1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| using PDFCreator;
private PDFCreator.clsPDFCreator _PDFCreator; (var globale du form)
private PDFCreator.clsPDFCreatorError pErr; (var globale du form)
private void Etat_pdf_Click(object sender, EventArgs e)
{
PDFCreator.clsPDFCreatorOptions opt;
FileInfo fi;
string fname = "", DefaultPrinter;
// On récupère des informations sur le fichier à créer en PDF
fi = new FileInfo(chemin);
if (fi.Name.Length > 0)
{
if (fi.Name.IndexOf(".") > 1)
{
fname = fi.Name.Substring(0, fi.Name.IndexOf("."));
}
else
{
fname = fi.Name;
}
}
if (!_PDFCreator.cIsPrintable(fi.FullName))
{
MessageBox.Show("Le fichier '" + fi.FullName + "' n'est pas imprimable!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
try
{
opt = _PDFCreator.cOptions;
opt.UseAutosave = 1;
opt.UseAutosaveDirectory = 1;
opt.AutosaveDirectory = fi.DirectoryName;
opt.AutosaveFormat = 0;
opt.AutosaveFilename = fname;
_PDFCreator.cOptions = opt;
_PDFCreator.cClearCache();
DefaultPrinter = _PDFCreator.cDefaultPrinter;
_PDFCreator.cDefaultPrinter = "PDFCreator";
_PDFCreator.cPrintFile(fi.FullName);
//ReadyState = false;
_PDFCreator.cPrinterStop = false;
MessageBox.Show("Votre fichier PDF est créé");
_PDFCreator.cPrinterStop = true;
_PDFCreator.cDefaultPrinter = DefaultPrinter;
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString(), "Erreur ", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
appelprocessusexternepdf();
}
public void appelprocessusexternepdf()
{
String chemin;
chemin = Application.StartupPath + "\\Etat.pdf";
Process notepad = new Process();
chemin = chemin.Replace(" ", "%20"); // on remplace l'espace par son code ascii
Process.Start("acroRd32.exe", chemin);
} |
Partager