static void Main(string[] args) { string inFile = args[0]; string outFile = args[1]; string[] pages = new string[args.Length - 2]; for (int i = 2; i < args.Length; i++) { pages[i - 2] = args[i]; } Console.WriteLine(); GhostscriptProcessor gp = new GhostscriptProcessor(GhostscriptVersionInfo.GetLastInstalledVersion(), true); foreach (string p in pages) { gp.Processing += GPProcess; gp.StartProcessing(GSExtractSwitches(inFile, "temp" + p + ".pdf", p), null); while (gp.IsRunning) { } } gp.Processing += GPProcess; gp.StartProcessing(GSCombineSwitches(pages, outFile), null); while (gp.IsRunning) { } foreach (string p in pages) { DeleteTempFiles(p); } }
public void Start(List <string> str) { // YOU NEED TO HAVE ADMINISTRATOR RIGHTS TO RUN THIS CODE foreach (var file in str) { string inputFile = file; try { using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=mswinpr2"); switches.Add("-sOutputFile=%printer%" + AppSettings.PrinterName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } } catch (Exception e) { } } }
public void PrintPdf(string inputfile) { GhostscriptVersionInfo _lastInstalledVersion = GetGhostscriptVersion(); string printerName = System.Drawing.Printing.PrinterSettings.InstalledPrinters.Cast <string>().ToList().Find(f => f.Contains("XPS")); using (GhostscriptProcessor processor = new GhostscriptProcessor(_lastInstalledVersion)) { List <string> switches = new List <string> { "-empty", "-dPrinted", "-dBATCH", "-dNOPAUSE", "-dNOSAFER", "-dNumCopies=1", "-sDEVICE=mswinpr2", "-sOutputFile=%printer%" + printerName, "-f", inputfile }; processor.StartProcessing(switches.ToArray(), null); } }
private void Add_Watermark_To_PDF_Document() { string inputFile = @"E:\gss_test\test.pdf"; string outputFile = @"E:\gss_test\output\test-watermarked.pdf"; List <string> switches = new List <string>(); switches.Add(string.Empty); // set required switches switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPAUSE"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-sOutputFile=" + outputFile); switches.Add("-c"); switches.Add(POSTSCRIPT_APPEND_WATERMARK); switches.Add("-f"); switches.Add(inputFile); // create a new instance of the GhostscriptProcessor using (GhostscriptProcessor processor = new GhostscriptProcessor()) { // start processing pdf file processor.StartProcessing(switches.ToArray(), null); } // show new pdf Process.Start(outputFile); }
private void CompressDocument() { List <string> gsArgs = new List <string>(); gsArgs.Add("-empty"); gsArgs.Add("-dSAFER"); gsArgs.Add("-dBATCH"); gsArgs.Add("-dNOPAUSE"); gsArgs.Add("-dNOPROMPT"); gsArgs.Add("-sDEVICE=pdfwrite"); gsArgs.Add("-dCompatibilityLevel=1.4"); // dPDFSETTINGS is basically our commpression option // - /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting. // - /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting. // - /printer selects output similar to the Acrobat Distiller "Print Optimized" setting. // - /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting. // - /default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file. // gsArgs.Add("-dPDFSETTINGS=/screen"); gsArgs.Add("-dPDFSETTINGS=/ebook"); gsArgs.Add("-sOutputFile=" + _outputFile + ""); gsArgs.Add("-f"); gsArgs.Add(_inputFile); using (GhostscriptProcessor processor = new GhostscriptProcessor(_gs_verssion_info, true)) processor.StartProcessing(gsArgs.ToArray(), null); }
public bool ConvertPsToPdf(string inputFile, string outputFile) { GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion(); try { using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true)) { processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-dCompatibilityLevel=1.4"); switches.Add("-sOutputFile=" + outputFile); switches.Add("-c"); switches.Add("-f"); switches.Add(inputFile.ToString()); processor.StartProcessing(switches.ToArray(), null); } } catch (Exception) { return(false); } return(true); }
private static void OptimizarDump() { var dump = Directory.GetCurrentDirectory() + @"\dump"; var dumped = Directory.GetCurrentDirectory() + @"\dumped"; GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(Directory.GetFiles(Directory.GetCurrentDirectory(), "gsdll32.dll").FirstOrDefault()); using (GhostscriptProcessor processor = new GhostscriptProcessor(gvi, true)) { //processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); List <string> switches = new List <string>(); switches.Add("-empty"); //switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); //switches.Add(@"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts)); //switches.Add("-dFirstPage=" + pageFrom.ToString()); //switches.Add("-dLastPage=" + pageTo.ToString()); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-CompressPages=true"); switches.Add("-dCompatibilityLevel=1.5"); switches.Add("-dPDFSETTINGS=/ebook"); switches.Add("-dEmbedAllFonts=false"); switches.Add("-dSubsetFonts=false"); switches.Add(@"-sOutputFile=" + dumped); switches.Add(@"-f"); switches.Add(dump); // if you dont want to handle stdio, you can pass 'null' value as the last parameter //LogStdio stdio = new LogStdio(); processor.StartProcessing(switches.ToArray(), null); } }
//https://www.ghostscript.com/download/gsdnld.html public ProcessResult Process(string key, string psFilename) { log.DebugFormat("PDFWriter process: key={0}, psFilename={1}", key, psFilename); GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); // pipe handle format: %handle%hexvalue string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2"); FileInfo fileInfo = new FileInfo(psFilename); var outputFilename = Path.Combine(fileInfo.Directory.FullName, string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(fileInfo.Name))); try { using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-o" + outputPipeHandle); switches.Add("-q"); switches.Add("-f"); switches.Add(psFilename); try { processor.StartProcessing(switches.ToArray(), null); byte[] rawDocumentData = gsPipedOutput.Data; File.WriteAllBytes(outputFilename, rawDocumentData); log.DebugFormat("PDFWriter success: {0}", outputFilename); } catch (Exception ex) { log.Error("PDFWriter failed", ex); } finally { gsPipedOutput.Dispose(); gsPipedOutput = null; } } } catch (Exception ex) { log.Error("PDFWriter failed", ex); } return(new ProcessResult()); }
public void Process(GhostscriptVersionInfo ghostscriptVersion, bool fromMemory, GhostscriptStdIO stdIO_callback) { if (ghostscriptVersion == null) { throw new ArgumentNullException("ghostscriptVersion"); } using (GhostscriptProcessor processor = new GhostscriptProcessor(ghostscriptVersion, fromMemory)) { processor.StartProcessing(this.GetSwitches(), stdIO_callback); } }
public void Start() { string inputFile = @"..\..\..\test\gre.pdf"; GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); // pipe handle format: %handle%hexvalue string h = gsPipedOutput.ClientHandle; string outputPipeHandle = "%handle%" + int.Parse(h).ToString("X2"); using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); //switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-sDEVICE=pdfwrite"); switches.Add($"-o{ outputPipeHandle }"); switches.Add("-q"); switches.Add("-f"); switches.Add(inputFile); try { processor.StartProcessing(switches.ToArray(), null); byte[] rawDocumentData = gsPipedOutput.Data; //if (writeToDatabase) //{ // Database.ExecSP("add_document", rawDocumentData); //} //else if (writeToDisk) //{ // File.WriteAllBytes(@"..\..\..\test\output\test_piped_output.pdf", rawDocumentData); //} } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { gsPipedOutput.Dispose(); gsPipedOutput = null; } } }
private static string PsToPDF(string psfilename) { string inputFile = psfilename; GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); string pdfFilePath = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf"; // pipe handle format: %handle%hexvalue string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2"); using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-o" + outputPipeHandle); switches.Add("-q"); switches.Add("-f"); switches.Add(inputFile); try { processor.StartProcessing(switches.ToArray(), null); byte[] rawDocumentData = gsPipedOutput.Data; File.WriteAllBytes(pdfFilePath, rawDocumentData); return(pdfFilePath); } catch (Exception ex) { throw new Exception(ex.Message + "hallo"); } finally { gsPipedOutput.Dispose(); gsPipedOutput = null; } } }
public static void Print(string printDocPath, string printerName, bool showWindow = false) { using (var processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=mswinpr2"); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(printDocPath); processor.StartProcessing(switches.ToArray(), null); } }
private static void StarOptimizer(string path) { //GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion(); GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(Directory.GetFiles(Directory.GetCurrentDirectory(), "gsdll32.dll").FirstOrDefault()); using (GhostscriptProcessor processor = new GhostscriptProcessor(gvi, true)) { //processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); var fi = new System.IO.FileInfo(path); List <string> switches = new List <string>(); switches.Add("-empty"); //switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); //switches.Add(@"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts)); //switches.Add("-dFirstPage=" + pageFrom.ToString()); //switches.Add("-dLastPage=" + pageTo.ToString()); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-CompressPages=true"); switches.Add("-dCompatibilityLevel=1.5"); switches.Add("-dPDFSETTINGS=/screen"); switches.Add("-dEmbedAllFonts=false"); switches.Add("-dSubsetFonts=false"); //switches.Add("-dColorImageDownsampleType=/Bicubic"); //switches.Add("-dColorImageResolution=144"); //switches.Add("-dGrayImageDownsampleType=/Bicubic"); //switches.Add("-dGrayImageResolution=144"); //switches.Add("-dMonoImageDownsampleType=/Bicubic"); //switches.Add("-dMonoImageResolution=144"); switches.Add(@"-sOutputFile=D:\Projecto Compacter\Ghost" + fi.Name); switches.Add(@"-f"); switches.Add(path); // if you dont want to handle stdio, you can pass 'null' value as the last parameter //LogStdio stdio = new LogStdio(); processor.StartProcessing(switches.ToArray(), null); } }
public void StartPrint(string printerName, string filePath) { Console.WriteLine(printerName); using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=mswinpr2"); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(filePath); processor.StartProcessing(switches.ToArray(), null); } }
protected override void Print(string printerName, string filePath) { byte[] buffer = File.ReadAllBytes(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\gsdll32.dll"); using (GhostscriptProcessor processor = new GhostscriptProcessor(buffer)) { var switches = GsCommandSwitches.Select(s => s.Replace("{printerName}", printerName).Replace("{fileName}", filePath)).ToArray(); Logger.LogInfo(string.Join(" ", switches)); var callback = new CallbackStdIO(); processor.StartProcessing(switches, callback); Logger.LogInfo("GS StdOut:\n" + callback.OutLog); if (!string.IsNullOrEmpty(callback.ErrorLog)) { Logger.LogError("GS StdError:\n" + callback.ErrorLog); } } }
public void Start() { string inputFile = @"E:\gss_test\test.pdf"; string outputFile = @"E:\gss_test\output\page-%03d.png"; //string inputFile = @"E:\gss_test\multipage.ps"; //string outputFile = @"E:\gss_test\output\multipage.pdf"; int pageFrom = 1; int pageTo = 50; GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion(); using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true)) { processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add(@"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts)); switches.Add("-dFirstPage=" + pageFrom.ToString()); switches.Add("-dLastPage=" + pageTo.ToString()); switches.Add("-sDEVICE=png16m"); switches.Add("-r96"); switches.Add("-dTextAlphaBits=4"); switches.Add("-dGraphicsAlphaBits=4"); //switches.Add("-sDEVICE=pdfwrite"); switches.Add(@"-sOutputFile=" + outputFile); switches.Add(@"-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } }
private void ConvertToJPEG(string inputFileName) { Ghostscript.NET.GhostscriptVersionInfo gv = Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion(Ghostscript.NET.GhostscriptLicense.GPL | Ghostscript.NET.GhostscriptLicense.AFPL, Ghostscript.NET.GhostscriptLicense.GPL); string outputPath = System.IO.Path.GetDirectoryName(inputFileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(inputFileName) + ".jpg"; System.IO.StreamReader r = new System.IO.StreamReader(inputFileName); string pdfText = r.ReadToEnd(); System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]"); System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText); //GhostscriptSharp.GhostscriptWrapper.GenerateOutput(singleFilePath, outputPath, gss); using (GhostscriptProcessor gsp = new GhostscriptProcessor(gv, true)) { gsp.Processing += new GhostscriptProcessorProcessingEventHandler(ghostscriptProcessing); List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add(@"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts)); switches.Add("-dFirstPage=1"); switches.Add("-dLastPage=" + matches.Count.ToString()); switches.Add("-sDEVICE=jpeg"); switches.Add("-r96"); switches.Add("-dTextAlphaBits=4"); switches.Add("-dGraphicsAlphaBits=4"); switches.Add(@"-sOutputFile=" + outputPath); switches.Add(@"-f"); switches.Add(inputFileName); gsp.StartProcessing(switches.ToArray(), null); } }
public void Start() { string inputFile = Path.GetFullPath(@"../../../test/test.pdf").Replace("\\", "/"); string outputFile = Path.GetFullPath(@"../../../test/output/page-%03d.png").Replace("\\", "/"); Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); int pageFrom = 1; int pageTo = 50; GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion(); using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true)) { processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); List <string> switches = new List <string>(); //switches.Add("-empty"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add($"-sFONTPATH={ System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts) }"); switches.Add("-dFirstPage=" + pageFrom.ToString()); switches.Add("-dLastPage=" + pageTo.ToString()); switches.Add("-sDEVICE=png16m"); switches.Add("-r96"); switches.Add("-dTextAlphaBits=4"); switches.Add("-dGraphicsAlphaBits=4"); switches.Add($"-sOutputFile={outputFile}"); switches.Add("-f"); switches.Add(inputFile); // if you don't want to handle stdio, you can pass 'null' value as the last parameter LogStdio stdio = new LogStdio(); processor.StartProcessing(switches.ToArray(), stdio); } }
private void CompressDocument(string path, string outpath) { // Sourced from https://gist.github.com/firstdoit/6390547 List <string> gsArgs = new List <string>(); gsArgs.Add("-empty"); gsArgs.Add("-dSAFER"); gsArgs.Add("-dBATCH"); gsArgs.Add("-dNOPAUSE"); gsArgs.Add("-dNOPROMPT"); gsArgs.Add("-sDEVICE=pdfwrite"); gsArgs.Add("-dCompatibilityLevel=1.4"); // dPDFSETTINGS is basically our commpression option // - /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting. // - /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting. // - /printer selects output similar to the Acrobat Distiller "Print Optimized" setting. // - /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting. // - /default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file. gsArgs.Add("-dPDFSETTINGS=/screen"); gsArgs.Add("-sOutputFile=" + outpath + ""); gsArgs.Add("-f"); gsArgs.Add(path); using (GhostscriptProcessor processor = new GhostscriptProcessor(_gs_verssion_info, true)) { processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); processor.Completed += processor_Completed; processor.StartProcessing(gsArgs.ToArray(), null); } }
private void ConvertPsToPdf(string inputFile, string outputFile) { GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion(); using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true)) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-dCompatibilityLevel=1.4"); switches.Add("-sOutputFile=" + outputFile); switches.Add("-c"); switches.Add("-f"); switches.Add(inputFile.ToString()); processor.StartProcessing(switches.ToArray(), null); } }
private static void PrintMyPdf(string pathofmypdf) { string printerName = Global.Selectedprinter; string inputFile = pathofmypdf; //try catch ghostscript try { using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=mswinpr2"); int largeurghostscript = Convert.ToInt32(Global.Largeuret / 100 * 72 / 2.54); //millimetre en inch, 72 point par inch //MessageBox.Show(largeurghostscript.ToString()); switches.Add("-dDEVICEWIDTHPOINTS=" + largeurghostscript); //-dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h int hauteurghostscript = Convert.ToInt32(Global.Hauteuet / 100 * 72 / 2.54); //MessageBox.Show(hauteurghostscript.ToString()); switches.Add("-dDEVICEHEIGHTPOINTS=" + hauteurghostscript); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); //switches.Add("-r600"); //300 point par inch switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } } catch (Exception e) { MessageBox.Show($"Erreur ghostscript: {e}", "Erreur ghostscript", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Start() { // YOU NEED TO HAVE ADMINISTRATOR RIGHTS TO RUN THIS CODE string printerName = "YourPrinterName"; string inputFile = @"..\..\..\test\t3.pdf"; using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); //switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=mswinpr2"); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } }
public void miseEnForm(string typeDoc) { int incCopie = 0; int nbCopie = int.Parse(donneEntete["Nombre_copies"]); string cheminDocFinaux = ConfigurationManager.AppSettings["CheminDocFinaux"].ToString(); string cheminRessources = ConfigurationManager.AppSettings["CheminRessources"].ToString(); while (incCopie < nbCopie) { bool drapReliquat = false; string chemin = cheminDocFinaux + "\\DocFinaux\\BP\\BP_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; Document nouveauDocument = new Document(PageSize.A4, 20, 20, 12, 20); PdfWriter.GetInstance(nouveauDocument, new FileStream(chemin, FileMode.Create)); //Stockage du document //---------------------------------------- //Constitution document PDF //---------------------------------------- nouveauDocument.Open(); PdfPTable tableau = new PdfPTable(2); tableau.TotalWidth = 550; tableau.LockedWidth = true; //-----------------Ajout Pattern/Image-------------------------------------------------------- Image image2 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternHautDroiteBp"]); image2.Alignment = Image.UNDERLYING; image2.SetAbsolutePosition(325, 755); nouveauDocument.Add(image2); Image image5 = Image.GetInstance(ConfigurationManager.AppSettings["CheminFilligraneBp"]); image5.Alignment = Image.UNDERLYING; image5.SetAbsolutePosition(180, 270); nouveauDocument.Add(image5); //------------------------------------------------------------------------------------------------------ Paragraph pLogo = new Paragraph(); Image image = Image.GetInstance(ConfigurationManager.AppSettings["CheminLogoABCR"]); pLogo.Add(image); //Encadré photo PdfPCell celulleHauteGauche = new PdfPCell(image); celulleHauteGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleHauteGauche); //Celulle de droite contenant l'adresse de livraison Paragraph pAdl = new Paragraph(); pAdl.Add(new Phrase("Adresse de livraison\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); if (donneEntete["Bon_typvte"] == "EMPORTEE") { pAdl.Add(new Phrase("EMPORTEE\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); /*pAdl.Add(new Phrase(donneEntete["Tiers_adl3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); * pAdl.Add(new Phrase(donneEntete["Tiers_adl4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); * pAdl.Add(new Phrase(donneEntete["Tiers_adl5"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); * pAdl.Add(new Phrase(donneEntete["Tiers_adlcp"] + " " + donneEntete["Tiers_adl6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD)));*/ } else { if (donneEntete["Tiers_adl1"] == "") { pAdl.Add(new Phrase(donneEntete["Tiers_adf1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adf2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adf3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adf4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); //pAdl.Add(new Phrase(donneEntete["Tiers_adf6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adl6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); } else { pAdl.Add(new Phrase(donneEntete["Tiers_adl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adl2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adl3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adl4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); //pAdl.Add(new Phrase(donneEntete["Tiers_adl5"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(donneEntete["Tiers_adlcp"] + " " + donneEntete["Tiers_adl6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); } } PdfPCell celulleFinDroite = new PdfPCell(pAdl); celulleFinDroite.Rowspan = 2; celulleFinDroite.Border = PdfPCell.NO_BORDER; celulleFinDroite.PaddingLeft = 35; tableau.AddCell(celulleFinDroite); //Adresse ABCR string tel = donneEntete["Adresse_interne_7"]; string fax = donneEntete["Adresse_interne_8"]; tel = tel.Substring(3, 15); fax = fax.Substring(3, 15); Paragraph p = new Paragraph(); p.Add(new Phrase(donneEntete["Adresse_interne_2"] + " Tél " + tel + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_3"] + " Fax " + fax + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleMilieuGauche = new PdfPCell(p); celulleMilieuGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleMilieuGauche); //Tableau dans celulle bas gauche du tableau d'entete PdfPTable tabCell = new PdfPTable(3); tabCell.TotalWidth = 230; tabCell.LockedWidth = true; tabCell.AddCell(new Phrase("Client", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("Date", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("N° CDE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase(donneEntete["Client_code"], FontFactory.GetFont(FontFactory.HELVETICA, 9))); tabCell.AddCell(new Phrase(donneEntete["Document_date"], FontFactory.GetFont(FontFactory.HELVETICA, 9))); tabCell.AddCell(new Phrase(donneEntete["Document_numero"], FontFactory.GetFont(FontFactory.HELVETICA, 9))); tabCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; PdfPCell celulleBasGauche = new PdfPCell(tabCell); celulleBasGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleBasGauche); //Adresse de facturation Paragraph pAdf = new Paragraph(); pAdf.Add(new Phrase("Adresse de facturation\n" + donneEntete["Tiers_adf1"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleHauteDroite = new PdfPCell(pAdf); celulleHauteDroite.Border = PdfPCell.NO_BORDER; celulleHauteDroite.HorizontalAlignment = Element.ALIGN_LEFT; celulleHauteDroite.PaddingLeft = 35; tableau.AddCell(celulleHauteDroite); nouveauDocument.Add(tableau); //Récap ref client et numéro de téléphone Paragraph refCli = new Paragraph(); refCli.Add(new Phrase("Référence client " + donneeBody["Bon_rcl1"] + " du " + donneeBody["Bon_datrcl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); nouveauDocument.Add(refCli); //Recap dessus tableau //Condition de fonctionnement si dictionnaire contient clé commentaire ou non Chunk c; if (donneEntete.ContainsKey("Commentaire_texteentete")) { c = new Chunk("Vous avez été servi par : " + donneEntete["Bon_vendeur_lib"] + " Livrée le " + donneeBody["Bon_datliv1"] + " " + donneEntete["Commentaire_texteentete"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.ITALIC)); nouveauDocument.Add(c); Phrase pPage1; if (donneEntete.ContainsKey("Commentaire_texteentete0")) { pPage1 = new Phrase(donneEntete["Commentaire_texteentete0"] + " Page n° 1\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } else { pPage1 = new Phrase(" " + donneEntete["Document_type"] + " " + donneEntete["Duplicata"] + " Page n° 1 \n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } nouveauDocument.Add(pPage1); } else { c = new Chunk("Vous avez été servi par : " + donneEntete["Bon_vendeur_lib"] + " Livrée le " + donneeBody["Bon_datliv1"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.ITALIC)); nouveauDocument.Add(c); Phrase pPage1; pPage1 = new Phrase(" " + donneEntete["Document_type"] + " " + donneEntete["Duplicata"] + " Page n° 1 \n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); nouveauDocument.Add(pPage1); } //-------------------------------------------------------------------------------------------------------- // TABLEAU //--------------------------------------------------------------------------------------------------------- CurseurTemplate ct = new CurseurTemplate(); valeurTemplate = ct.chercher("BP"); float[] largeurs = { int.Parse(valeurTemplate["Dimension1"]), int.Parse(valeurTemplate["Dimension2"]), int.Parse(valeurTemplate["Dimension3"]), int.Parse(valeurTemplate["Dimension4"]), int.Parse(valeurTemplate["Dimension5"]) }; PdfPTable table = new PdfPTable(largeurs); table.TotalWidth = 555; //Chaque colonne crée ci dessus doit être rempli table.LockedWidth = true; PdfPCell cellET1 = new PdfPCell(new Phrase("Article", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET1.Border = PdfPCell.NO_BORDER; //cellET1.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET1); PdfPCell cellET2 = new PdfPCell(new Phrase("Désignation", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET2.Border = PdfPCell.NO_BORDER; //cellET2.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET2); PdfPCell cellET3 = new PdfPCell(new Phrase("UV", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET3.Border = PdfPCell.NO_BORDER; //cellET3.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET3); PdfPCell cellET4 = new PdfPCell(new Phrase("Quantité", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET4.Border = PdfPCell.NO_BORDER; //cellET4.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET4); PdfPCell cellET5 = new PdfPCell(new Phrase("Localisation", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET5.Border = PdfPCell.NO_BORDER; //cellET5.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET5); PdfPCell cellvideDebut = new PdfPCell(new Phrase(" ", FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.BOLD))); cellvideDebut.Colspan = 5; cellvideDebut.Border = PdfPCell.NO_BORDER; table.AddCell(cellvideDebut); Image image3 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternTableau"]); image3.Alignment = Image.UNDERLYING; image3.SetAbsolutePosition(20, 597); nouveauDocument.Add(image3); List <string> locPrecedent = new List <string>(); //Liste qui récupère les anciennes clés de localisation afin de ne pas les réintégrer au doc int i; int nbLigne = 0; float resultat = 0; float dimTab = 0; int décrement = 0; int numPage = 0; //Constitution du tableau d'article bool okDési = false; bool okStart = false; for (i = 1; i <= iBody; i++) { //Condition ARTICLE---------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "ART") { nbLigne++; string sPattern = "libelle" + i + "bis"; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Art_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell1); Paragraph pCell2 = new Paragraph(); PdfPCell cell2 = new PdfPCell(pCell2); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; foreach (KeyValuePair <string, string> entry in donneeBody) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Key, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Value, "Localisations secondaires", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { } //Empeche de faire apparaitre la localisation secondaire dans la désignation else { if (okStart == false) { pCell2.Add(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); string clé = entry.Key; if (donneeBody.ContainsKey("Art_lot" + i)) { pCell2.Add(new Phrase("Numéro de lot : " + donneeBody["Art_lot" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); } pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7.5F, Font.BOLDITALIC))); okStart = true; } else { string clé = entry.Key; pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7.5F, Font.BOLDITALIC))); } okDési = true; } } } if (okDési == false) { PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell3); } else { table.AddCell(cell2); } PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Art_unite" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Art_qte" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell5); bool drapLoc = false; string reliquat = ""; foreach (KeyValuePair <string, string> entry in donneeBody) { //string patternReliquat = "Art_reliquat"; if (donneeBody.ContainsKey("Art_reliquat" + i)) { reliquat = "Reliquat"; drapReliquat = true; } //Condition si l'article à une loca secondaire if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && System.Text.RegularExpressions.Regex.IsMatch(entry.Value, "Localisations secondaires", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { string rackSub = donneeBody[entry.Key]; rackSub = rackSub.Substring(27, 2); string etagereSub = donneeBody[entry.Key]; etagereSub = etagereSub.Substring(29, 2); PdfPCell cell6 = new PdfPCell(new Phrase("Zone : " + donneeBody["Art_localisation" + i] + " Rack : " + rackSub + " Etagère : " + etagereSub + " /n" + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } //Si il n'en a pas, afficher uniquement la zone if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && donneeBody["Art_type_cde" + i] != "S" && donneeBody["Art_type_cde" + i] != "D") { PdfPCell cell6 = new PdfPCell(new Phrase("Zone : " + donneeBody["Art_localisation" + i] + " " + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } //Condition si article est spécial, pas de localisation if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && donneeBody["Art_type_cde" + i] == "S") { PdfPCell cell6 = new PdfPCell(new Phrase("Spécial" + " " + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } //Condition si article est direct, pas de localisation if (drapLoc == false && locPrecedent.Contains(entry.Key) == false && donneeBody["Art_type_cde" + i] == "D") { PdfPCell cell6 = new PdfPCell(new Phrase("Direct" + " " + reliquat, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell6); okStart = true; drapLoc = true; reliquat = ""; locPrecedent.Add(entry.Key); } } if (drapLoc == false) { PdfPCell cell7 = new PdfPCell(new Phrase(" ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell7.Border = PdfPCell.NO_BORDER; cell7.Border += PdfPCell.LEFT_BORDER; cell7.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell7); } okDési = false; okStart = false; drapLoc = false; } //Condition COMMENTAIRE-------------------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "COM") { nbLigne++; PdfPCell cellVide = new PdfPCell(new Phrase("" + "\n")); PdfPCell cell = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); PdfPCell cellFin = new PdfPCell(); cellVide.Border = PdfPCell.NO_BORDER; cellVide.Border += PdfPCell.RIGHT_BORDER; cellVide.Border += PdfPCell.LEFT_BORDER; cell.Border = PdfPCell.NO_BORDER; cell.Border += PdfPCell.RIGHT_BORDER; cell.Border += PdfPCell.LEFT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.LEFT_BORDER; cellFin.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cellVide); table.AddCell(cell); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellFin); } // PdfPCell cellEcartDroite = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); PdfPCell cellEcart = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); cellEcart.Border = PdfPCell.NO_BORDER; cellEcart.Border += PdfPCell.LEFT_BORDER; cellEcart.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border = PdfPCell.NO_BORDER; cellEcartDroite.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border += PdfPCell.LEFT_BORDER; table.AddCell(cellEcartDroite); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); //--------------------------------------------GESTION DU SAUT DE PAGE------------------------------------------------------------------------------------------- float temp = table.TotalHeight; dimTab = temp; if (dimTab >= 410 && i < iBody) { //Saut de page numPage++; PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 5; cellBlanche.FixedHeight = (450 - dimTab); cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = (450 - dimTab); cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); nouveauDocument.Add(table);//----------------------------------------------------------------------------Repère ligne en dessous-------------------------------------------------- Phrase pReport = new Phrase(" A REPORTER\n\n\n\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); Phrase pPage; if (donneEntete.ContainsKey("Commentaire_texteentete0")) { pPage = new Phrase(donneEntete["Commentaire_texteentete0"] + " Page n° " + (numPage + 1) + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } else { pPage = new Phrase(" Page n° " + (numPage + 1) + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); } nouveauDocument.Add(pReport); table.DeleteBodyRows(); nouveauDocument.Add(Chunk.NEXTPAGE); nouveauDocument.Add(tableau); //nouveauDocument.Add(p); nouveauDocument.Add(refCli); nouveauDocument.Add(c); nouveauDocument.Add(pPage); nouveauDocument.Add(image2); nouveauDocument.Add(image3); nouveauDocument.Add(image5); table.AddCell(cellET1); table.AddCell(cellET2); table.AddCell(cellET3); table.AddCell(cellET4); table.AddCell(cellET5); table.AddCell(cellvideDebut); dimTab = 0; décrement = (i - 1); } } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------- if (i > iBody) { PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 5; resultat = 450 - dimTab; //<<----------450 correspond au nombre de point de la longueur du tableau, c'est la valeur à modifier pour modifier la taille du tableau cellBlanche.FixedHeight = resultat; cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = resultat; cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); } nouveauDocument.Add(table); //----------------------------------------Gestion des commentaires de bon------------------------------------- if (donneEntete.ContainsKey("Commentaire_texte")) { Paragraph pComBon = new Paragraph(new Phrase(" " + donneEntete["Commentaire_texte"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); nouveauDocument.Add(pComBon); } nouveauDocument.Close(); incCopie++; //Copie Doc dans GED try { String connectionString = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn = new OdbcConnection(connectionString); conn.Open(); string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + donneEntete["Client_code"] + "'"; OdbcCommand act = new OdbcCommand(requete, conn); OdbcDataReader act0 = act.ExecuteReader(); string nomADH = ""; while (act0.Read()) { nomADH = (act0.GetString(1)); } conn.Close(); if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\" + "\\BP_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\BP\\" + "\\BP_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "ENVOI GED BP"); } //--------------------------------------------------------FIN COPIE------------------------------------------------------ #region ImpressionOld /*myPrinters.SetDefaultPrinter("Imp204"); * Process proc = new Process(); * proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; * proc.StartInfo.Verb = "print"; * * //Define location of adobe reader/command line * //switches to launch adobe in "print" mode * proc.StartInfo.FileName = * @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"; * proc.StartInfo.Arguments = String.Format(@"/p /h {0}", chemin); * proc.StartInfo.UseShellExecute = false; * proc.StartInfo.CreateNoWindow = true; * * proc.Start(); * proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; * if (proc.HasExited == false) * { * proc.WaitForExit(10000); * } * * proc.EnableRaisingEvents = true; * * proc.Close(); * foreach (Process clsProcess in Process.GetProcesses().Where( * clsProcess => clsProcess.ProcessName.StartsWith("AcroRd32"))) * { * clsProcess.Kill(); * }*/ #endregion //Solution d'impression fonctionnel, API payante---------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------- //----------------Expérimentation, ATTENTION FRAMEWORK EN 4.5--------------------------- int nbImp = 0; int nbImpOK = 0; string[] printer = new string[20]; // tableau qui contient les imprimantes du profil d'impression ProfilImprimante profil = new ProfilImprimante(); profil.chargementXML("BP"); // chargement selon le type de doc string vendeur = ""; try { vendeur = unProfil.Substring(2, 3); } catch { vendeur = unProfil.Substring(2, 2); } vendeur = vendeur.TrimEnd(); var listeProfil = profil.getDonneeProfil(); try { if (drapReliquat) { printer[nbImp] = ConfigurationManager.AppSettings["ImpDefBL"]; nbImp++; } else { foreach (string v in listeProfil[vendeur]) //lecture des imprimantes liée à un profil { printer[nbImp] = v.ToString(); nbImp++; //on incrémente le nombre d'impression à executer } } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "Erreur attribution imprimante par profil " + unProfil.ToString()); printer[nbImp] = "Imp211"; //Imprimante par defaut (essai) nbImp++; } nbImp = nbImp - 1; while (nbImpOK <= nbImp) // boucle tant que le nombre d'impression fait n'à pas atteint le nombre d'impression demander { string printerName = printer[nbImpOK]; string inputFile = String.Format(@"{0}", chemin); try { //Envoi de l'ordre d'impression vers l'imprimante, les "switches" sont des arguments de la ligne de script "processor" de type GhostscriptProcessor using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=ljet4"); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } nbImpOK++; } catch (Exception e) { LogHelper.WriteToFile(e.Message, "ParseurBP" + donneEntete["Document_numero"].Trim()); } // incrément à chaque impression terminée } } }
private void CompressDocument(string path, string outpath) { // Sourced from https://gist.github.com/firstdoit/6390547 List <string> gsArgs = new List <string>(); gsArgs.Add("-empty"); gsArgs.Add("-dSAFER"); gsArgs.Add("-dBATCH"); gsArgs.Add("-dNOPAUSE"); gsArgs.Add("-dNOPROMPT"); gsArgs.Add("-sDEVICE=pdfwrite"); gsArgs.Add("-dCompatibilityLevel=1.4"); // dPDFSETTINGS is basically our commpression option // - /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting. // - /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting. // - /printer selects output similar to the Acrobat Distiller "Print Optimized" setting. // - /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting. // - /default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file. //string selected = comboBoxQuality.Text.ToLower(); gsArgs.Add("-dPDFSETTINGS=/" + this._quality); gsArgs.Add("-sOutputFile=" + outpath + ""); gsArgs.Add("-f"); gsArgs.Add(path); using (GhostscriptProcessor processor = new GhostscriptProcessor(_gs_verssion_info, true)) { processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing); processor.Completed += processor_Completed; processor.StartProcessing(gsArgs.ToArray(), null); if (maintaintimestamps.Checked) { var fileInfo = new FileInfo(path); int fyear = fileInfo.LastWriteTime.Year; int fday = fileInfo.LastWriteTime.Day; int fmonth = fileInfo.LastWriteTime.Month; int fhour = fileInfo.LastWriteTime.Hour; int fminute = fileInfo.LastWriteTime.Minute; int fsecond = fileInfo.LastWriteTime.Second; File.SetLastWriteTime(outpath, new DateTime(fyear, fmonth, fday, fhour, fminute, fsecond)); } if (overwriteoriginals.Checked) { outpath = Path.GetDirectoryName(outpath); path = Path.GetDirectoryName(path); foreach (string newPath in Directory.GetFiles(outpath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(outpath, path), true); } } } }
/// <summary> /// Returns Ink coverage for specified page range. /// The result is ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally). /// This function is supported only in Ghostscript v9.05 or newer. /// </summary> /// <param name="path">PDF file path.</param> /// <param name="firstPage">Designated start page of the document. Pages of all documents in PDF collections are numbered sequentionally.</param> /// <param name="lastPage">Designated end page of the document. Pages of all documents in PDF collections are numbered sequentionally.</param> /// <param name="versionInfo">GhostscriptVersionInfo instance that tells which Ghostscript library to use.</param> /// <returns>A dictionary of a page numbers with the ink coverage.</returns> public static Dictionary <int, GhostscriptPageInkCoverage> GetInkCoverage(string path, int firstPage, int lastPage, GhostscriptVersionInfo versionInfo) { GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2"); List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-q"); if (firstPage != 0 && lastPage != 0) { switches.Add("-dFirstPage=" + firstPage.ToString()); switches.Add("-dLastPage=" + lastPage.ToString()); } switches.Add("-o" + outputPipeHandle); switches.Add("-sDEVICE=inkcov"); switches.Add(path); GhostscriptProcessor proc = new GhostscriptProcessor(versionInfo, false); proc.StartProcessing(switches.ToArray(), null); byte[] data = gsPipedOutput.Data; gsPipedOutput.Dispose(); gsPipedOutput = null; string output = Encoding.ASCII.GetString(data); if (output.Length > 0) { Dictionary <int, GhostscriptPageInkCoverage> result = new Dictionary <int, GhostscriptPageInkCoverage>(); string[] outputLines = output.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); int pageNumber = firstPage == 0 ? 1 : firstPage; foreach (string line in outputLines) { GhostscriptPageInkCoverage pic = new GhostscriptPageInkCoverage(); pic.Page = pageNumber; pic.IsValid = false; string[] lineParts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lineParts.Length == 6) { pic.C = Math.Round(float.Parse(lineParts[0], CultureInfo.InvariantCulture) * 100, 4); pic.M = Math.Round(float.Parse(lineParts[1], CultureInfo.InvariantCulture) * 100, 4); pic.Y = Math.Round(float.Parse(lineParts[2], CultureInfo.InvariantCulture) * 100, 4); pic.K = Math.Round(float.Parse(lineParts[3], CultureInfo.InvariantCulture) * 100, 4); if (lineParts[5] == "OK") { pic.IsValid = true; } } result.Add(pageNumber, pic); pageNumber++; } return(result); } else { return(null); } }
public void miseEnForm(string typeDoc) { int incCopie = 0; int nbCopie = 1; string cheminDocFinaux = ConfigurationManager.AppSettings["CheminDocFinaux"].ToString(); string cheminRessources = ConfigurationManager.AppSettings["CheminRessources"].ToString(); while (incCopie < nbCopie) { /*ND 23 10 2015*/ string chemin = ""; /* if (!System.IO.Directory.Exists(cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3,6))) { System.IO.Directory.CreateDirectory(cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3, 6)); chemin = cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; }*/ if (!System.IO.Directory.Exists(cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6))) { System.IO.Directory.CreateDirectory(cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6)); chemin = cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\RELEVE" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; } else { /*ND 23 10 2015*/ //chemin = cheminDocFinaux + "\\DocFinaux\\Releve\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; chemin = cheminDocFinaux + "\\DocFinaux\\Facturation\\" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "\\RELEVE" + nomDoc + "_" + donneEntete["Tiers_nocpt"].Substring(3, 6) + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; } Document nouveauDocument = new Document(PageSize.A4, 20, 20, 12, 2); PdfWriter writer = PdfWriter.GetInstance(nouveauDocument, new FileStream(chemin, FileMode.Create)); //Stockage du document //--------------------------------------------------------------------------------------------------------------------------- //Constitution document PDF //--------------------------------------------------------------------------------------------------------------------------- nouveauDocument.Open(); PdfPTable tableau = new PdfPTable(2); tableau.TotalWidth = 550; tableau.LockedWidth = true; //------------------------------------------------------------------------------------------------- //Encadré ABCR Paragraph p = new Paragraph(); p.Add(new Phrase(donneEntete["Adresse_interne_1"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_2"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_3"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_4"] + "\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleHauteGauche = new PdfPCell(p); celulleHauteGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleHauteGauche); //Celulle de droite contenant l'adresse de livraison Paragraph pAdl = new Paragraph(); pAdl.Add(new Phrase("\n\n \n")); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase("\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdl.Add(new Phrase(" ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleFinDroite = new PdfPCell(pAdl); celulleFinDroite.Bottom = PdfPCell.ALIGN_BOTTOM; celulleFinDroite.Border = PdfPCell.NO_BORDER; celulleFinDroite.PaddingLeft = 35; tableau.AddCell(celulleFinDroite); //Tableau dans celulle bas gauche du tableau d'entete PdfPCell celulleBasGauche = new PdfPCell(); Paragraph ptest = new Paragraph(); ptest.Add(new Phrase("\n Relevé de facture(s)\n\n",FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD))); celulleBasGauche.AddElement(ptest); PdfPTable tabCell = new PdfPTable(3); tabCell.TotalWidth = 230; tabCell.LockedWidth = true; tabCell.AddCell(new Phrase("COMPTE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("DATE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase("NO RELEVE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCell.AddCell(new Phrase(donneEntete["Tiers_nocpt"], FontFactory.GetFont(FontFactory.HELVETICA, 10))); tabCell.AddCell(new Phrase(donneEntete["Rel_datrel"], FontFactory.GetFont(FontFactory.HELVETICA, 10))); tabCell.AddCell(new Phrase(donneEntete["Document_numero"], FontFactory.GetFont(FontFactory.HELVETICA, 10))); tabCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT; celulleBasGauche.AddElement(tabCell); celulleBasGauche.Border = PdfPCell.NO_BORDER; celulleBasGauche.Bottom = PdfPCell.ALIGN_BOTTOM; tableau.AddCell(celulleBasGauche); //Adresse facturation Paragraph pAdf = new Paragraph(); // REGLER INDENTATION DU PARAGRAPHE pAdf.Add(new Phrase("\n\n\n\n" + donneEntete["Tiers_adf1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adf2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adf3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adf4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); pAdf.Add(new Phrase(donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adf6"] + "\n\n\n\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celulleHauteDroite = new PdfPCell(pAdf); celulleHauteGauche.HorizontalAlignment = Element.ALIGN_RIGHT; celulleHauteDroite.Border = PdfPCell.NO_BORDER; celulleHauteDroite.PaddingLeft = 80; tableau.AddCell(celulleHauteDroite); nouveauDocument.Add(tableau); //-------------------------------------------------------------------------------------------------------- // TABLEAU //------------------------------------------------------------------------------------------------------- CurseurTemplate ct = new CurseurTemplate(); valeurTemplate = ct.chercher("RELEVE"); float[] largeurs = { int.Parse(valeurTemplate["Dimension1"]), int.Parse(valeurTemplate["Dimension2"]), int.Parse(valeurTemplate["Dimension3"]), int.Parse(valeurTemplate["Dimension4"]), int.Parse(valeurTemplate["Dimension5"]), int.Parse(valeurTemplate["Dimension6"]), }; PdfPTable table = new PdfPTable(largeurs); table.TotalWidth = 565; //Chaque colonne crée ci dessus doit être rempli table.LockedWidth = true; PdfPCell cellET1 = new PdfPCell(new Phrase("Date", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET1.SetLeading(2f, 1.2f); cellET1.PaddingBottom = 7f; table.AddCell(cellET1); PdfPCell cellET2 = new PdfPCell(new Phrase("Type Pièce", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET2.SetLeading(2f, 1.2f); cellET2.PaddingBottom = 7f; table.AddCell(cellET2); PdfPCell cellET3 = new PdfPCell(new Phrase("Référence", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET3.SetLeading(2f, 1.2f); cellET3.PaddingBottom = 7f; table.AddCell(cellET3); PdfPCell cellET4 = new PdfPCell(new Phrase("T.V.A", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET4.HorizontalAlignment = Element.ALIGN_RIGHT; cellET4.PaddingBottom = 7f; cellET4.SetLeading(2f, 1.2f); table.AddCell(cellET4); PdfPCell cellET5 = new PdfPCell(new Phrase("Avoir", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET5.HorizontalAlignment = Element.ALIGN_RIGHT; cellET5.PaddingBottom = 7f; cellET5.SetLeading(2f, 1.2f); table.AddCell(cellET5); PdfPCell cellET6 = new PdfPCell(new Phrase("Facture", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); cellET6.HorizontalAlignment = Element.ALIGN_RIGHT; cellET6.PaddingBottom = 7f; cellET6.SetLeading(2f, 1.2f); table.AddCell(cellET6); int i; int nbLigne = 0; float resultat = 0; float dimTab = 0; int décrement = 0; int numPage = 0; //Constitution du tableau /*ND DEBUT 19 10 2015*/ // bool okDési = false; /*ND FIN 19 10 2015*/ /* ND debut 19 10 2015*/ //bool okStart = false; /*ND FIN 19 10 2015*/ double tempoTOT = 0; for (i = 0; i < iBody; i++) { nbLigne++; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Rel_datfac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; cell1.SetLeading(5f, 1.2f); table.AddCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(donneeBody["Rel_libavofac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; cell2.SetLeading(5f, 1.2f); table.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Rel_nofac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; cell3.SetLeading(5f, 1.2f); table.AddCell(cell3); PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Rel_mtva" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; cell4.HorizontalAlignment = Element.ALIGN_RIGHT; cell4.SetLeading(5f, 1.2f); table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Rel_mttavo"+i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; cell5.HorizontalAlignment = Element.ALIGN_RIGHT; cell5.SetLeading(5f, 1.2f); table.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase(donneeBody["Rel_mtfac" + i], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; cell6.HorizontalAlignment = Element.ALIGN_RIGHT; cell6.SetLeading(5f, 1.2f); table.AddCell(cell6); //--------------------------------------------GESTION DU SAUT DE PAGE------------------------------------------------------------------------------------------- float temp = table.TotalHeight; dimTab = temp; if (dimTab >= 380 && i < iBody) //if (dimTab >= 380 && i <= iBody) { //Saut de page numPage++; PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheDA = new PdfPCell(new Phrase("\n\nA Reporter", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.ITALIC))); PdfPCell cellBlancheD = new PdfPCell(new Phrase("\n\n" + tempoTOT.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.ITALIC))); cellFin.Colspan = 8; cellBlancheDA.Bottom = PdfPCell.ALIGN_BOTTOM; cellBlancheD.Bottom = PdfPCell.ALIGN_BOTTOM; cellBlanche.FixedHeight = (440 - dimTab); cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheDA.FixedHeight = (440 - dimTab); cellBlancheDA.Border = PdfPCell.NO_BORDER; cellBlancheDA.Border += PdfPCell.LEFT_BORDER; cellBlancheDA.Border += PdfPCell.RIGHT_BORDER; cellBlancheD.FixedHeight = (440 - dimTab); cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheDA); table.AddCell(cellBlancheD); table.AddCell(cellFin); nouveauDocument.Add(table);//----------------------------------------------------------------------------Repère ligne en dessous-------------------------------------------------- Phrase pReport = new Phrase(" A REPORTER\n\n\n\n\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); /*10 12 15 ND correction bug saut de page donnée entete innexistante*/ // Phrase pPage = new Phrase("\n " + donneEntete["Document_type"] + " " + donneEntete["Duplicata"] + " Page n° " + (numPage + 1) + " ", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD)); Phrase pPage = new Phrase("\n " + donneEntete["Document_type"] + " Page n° " + (numPage + 1) + " ", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD)); pPage.Leading = 15; nouveauDocument.Add(pReport); table.DeleteBodyRows(); nouveauDocument.Add(Chunk.NEXTPAGE); nouveauDocument.Add(tableau); nouveauDocument.Add(pPage); table.AddCell(cellET1); table.AddCell(cellET2); table.AddCell(cellET3); table.AddCell(cellET4); table.AddCell(cellET5); table.AddCell(cellET6); dimTab = 0; décrement = (i - 1); } //FinGestionSautPage } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- int b; //---------------------------------------------------------------- for (b = 0; b <= i; b++) // { // Compteur dimension du tableau float temp = table.TotalHeight; // resultat = temp; // } //------------------------------------------------------------------- if (i >= iBody) { PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 8; resultat = 300 - resultat; //<<----------450 correspond au nombre de point de la longueur du tableau, c'est la valeur à modifier pour modifier la taille du tableau cellBlanche.FixedHeight = resultat; cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = resultat; cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); } table.SpacingAfter = -15F; nouveauDocument.Add(table); //----------------------------------------------------Tableau récap----------------------------------------- PdfPTable tabTot = new PdfPTable(3); tabTot.TotalWidth = 565; tabTot.LockedWidth = true; PdfPCell cellHT = new PdfPCell(new Phrase("HT " + donneeFoot["Tot_ht"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); cellHT.Border = PdfPCell.NO_BORDER; PdfPCell cellTVA = new PdfPCell(new Phrase("TVA " + donneeFoot["Tot_tva"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); cellTVA.Border = PdfPCell.NO_BORDER; PdfPCell cellTot = new PdfPCell(new Phrase(donneeFoot["Tot_rel"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); cellTot.Border = PdfPCell.NO_BORDER; cellHT.HorizontalAlignment = Element.ALIGN_RIGHT; cellTVA.HorizontalAlignment = Element.ALIGN_RIGHT; cellTot.HorizontalAlignment = Element.ALIGN_RIGHT; tabTot.AddCell(cellHT); tabTot.AddCell(cellTVA); tabTot.AddCell(cellTot); PdfPCell cellType = new PdfPCell(new Phrase("\nDate d'échéance : " + donneeFoot["Tot_datech"]+"\n\n"+donneeFoot["Tot_libtraite"], FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.NORMAL))); cellType.Border = PdfPCell.NO_BORDER; cellType.Colspan = 2; PdfPTable tabReleve = new PdfPTable(1); tabReleve.TotalWidth = 138; tabReleve.LockedWidth = true; tabReleve.AddCell(new PdfPCell(new Phrase("TOTAL RELEVE", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)))); PdfPCell tabCellTot = new PdfPCell(new Phrase("\n"+donneeFoot["Tot_rel"]+" EUR", FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))); tabCellTot.HorizontalAlignment = Element.ALIGN_RIGHT; tabReleve.AddCell(tabCellTot); PdfPCell cellTabReleve = new PdfPCell(); cellTabReleve.Border = PdfPCell.NO_BORDER; cellTabReleve.PaddingLeft= 50; cellTabReleve.VerticalAlignment = Element.ALIGN_BOTTOM; cellTabReleve.AddElement(tabReleve); tabTot.AddCell(cellType); tabTot.AddCell(cellTabReleve); nouveauDocument.Add(tabTot); Phrase pTiré = new Phrase("\n------------------------------------------------------------------------------------------------------------------------------------------"); pTiré.SetLeading(0f, 0.5f); nouveauDocument.Add(pTiré); //--------------------------------------FIN TABLEAU RECAP------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (donneeFoot["Tot_libreg"] == "") // Condition si réglement par traites { PdfPTable tableauTraiteHaut = new PdfPTable(3); tableauTraiteHaut.TotalWidth = 565; tableauTraiteHaut.LockedWidth = true; PdfPCell cellBlancheTraite = new PdfPCell(); cellBlancheTraite.Border = PdfPCell.NO_BORDER; tableauTraiteHaut.AddCell(cellBlancheTraite); PdfPCell cellTraiteHaut = new PdfPCell(); cellTraiteHaut.SetLeading(1f, 0.5f); PdfPCell cellTraiteHautD = new PdfPCell(); cellTraiteHautD.SetLeading(1f, 0.5f); cellTraiteHaut.Border = PdfPCell.NO_BORDER; cellTraiteHautD.Border = PdfPCell.NO_BORDER; cellTraiteHaut.AddElement(new Phrase("Contre cette LETTRE de CHANGE stipulée SANS FRAIS veuillez payer la somme indiquée ci-dessous à l'ordre de :", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); tableauTraiteHaut.AddCell(cellTraiteHaut); cellTraiteHautD.AddElement(new Phrase(" " + donneeFoot["Tra_libacc"] + " " + donneeFoot["Tra_lcr"], FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); tableauTraiteHaut.AddCell(cellTraiteHautD); tableauTraiteHaut.SpacingAfter = -10f; nouveauDocument.Add(tableauTraiteHaut); //--------------------------Tableau Traite principal------------------------------------------------------------------------------------------------------- PdfPTable tableauTraite = new PdfPTable(3); //tableauTraite.SpacingBefore = -10f; tableauTraite.TotalWidth = 565; tableauTraite.LockedWidth = true; PdfPCell cellTraiteMiG = new PdfPCell(); cellTraiteMiG.Border = PdfPCell.NO_BORDER; Paragraph pcellTraiteHG = new Paragraph(); pcellTraiteHG.Add(new Phrase("\nA " + donneeFoot["Tra_lieucr"]+"\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); pcellTraiteHG.Add(new Phrase("Montant pour controle Date de création\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); pcellTraiteHG.Add(new Phrase("|"+donneeFoot["Tra_montae"] + "| |" + donneeFoot["Tra_datrel"]+"|", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); pcellTraiteHG.Add(new Phrase("\n| ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))); pcellTraiteHG.Add(new Phrase("|\n RIB du tiré .", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))); cellTraiteMiG.AddElement(pcellTraiteHG); cellTraiteMiG.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; PdfPCell cellTraiteMiM = new PdfPCell(); cellTraiteMiM.Border = PdfPCell.NO_BORDER; Paragraph pcellTraiteHM = new Paragraph(); pcellTraiteHM.Add(new Phrase("\n\nEchéance\n ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); pcellTraiteHM.Add(new Phrase("| " + donneeFoot["Tra_datech"] + " |", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); pcellTraiteHM.Add(new Phrase(" |" + donneeFoot["Tra_cocpt"] + "|\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); pcellTraiteHM.Add(new Phrase(" Ref.tiré ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteMiM.AddElement(pcellTraiteHM); cellTraiteMiM.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; PdfPCell cellTraiteMiD = new PdfPCell(); cellTraiteMiD.Border = PdfPCell.NO_BORDER; cellTraiteMiD.AddElement(new Phrase("\n CODE MONNAIE ISO\n",FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteMiD.AddElement(new Phrase(" EUR\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteMiD.AddElement(new Phrase("Montant\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteMiD.AddElement(new Phrase(" *****" + donneeFoot["Tra_montae"] + "***", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteMiD.PaddingLeft = 70; tableauTraite.AddCell(cellTraiteMiG); tableauTraite.AddCell(cellTraiteMiM); tableauTraite.AddCell(cellTraiteMiD); //------------FIN LIGNE MILEU TABLEAU--------------- PdfPCell cellTraiteBasG = new PdfPCell(); cellTraiteBasG.Border = PdfPCell.NO_BORDER; cellTraiteBasG.AddElement(new Phrase("|" + donneeFoot["Tra_banque"] + " | " + donneeFoot["Tra_guichet"] + " | " + donneeFoot["Tra_cptco"] + " | " + donneeFoot["Tra_rib"]+"|\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("Code établ. Code guichet N°de Compte Clé RIB\n", FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("Valeur en:", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("ACCEPTATION OU AVAL", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase(" NOM\n et ADRESSE", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasG.AddElement(new Phrase("\nN° SIREN du TIRE "+donneeFoot["Tra_siren"],FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); PdfPCell cellTraiteBasM = new PdfPCell(); cellTraiteBasM.Border = PdfPCell.NO_BORDER; cellTraiteBasM.AddElement(new Phrase(" "+donneeFoot["Tra_tiers_adf1"]+"\n",FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasM.AddElement(new Phrase(" " + donneeFoot["Tra_tiers_adf2"] + "\n\n\n\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasM.AddElement(new Phrase(" " + donneeFoot["Tra_tiers_adfcp"] + " " + donneeFoot["Tra_tiers_adf6"], FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); PdfPCell cellTraiteBasD = new PdfPCell(); cellTraiteBasD.Border = PdfPCell.NO_BORDER; cellTraiteBasD.AddElement(new Phrase(" DOMICILIATION .\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.UNDERLINE))); cellTraiteBasD.AddElement(new Phrase("| " + donneeFoot["Tra_domic1"] + " |\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasD.AddElement(new Phrase("| " + donneeFoot["Tra_domic2"] + " |\n", FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); cellTraiteBasD.AddElement(new Phrase(" Signature ", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL))); cellTraiteBasD.AddElement(new Phrase("\n\nCLIENT N° " + donneeFoot["Tra_nocli"] + " RELEVE N° " + donneeFoot["Tra_numrel"], FontFactory.GetFont(FontFactory.COURIER, 8, Font.NORMAL))); tableauTraite.AddCell(cellTraiteBasG);tableauTraite.AddCell(cellTraiteBasM);tableauTraite.AddCell(cellTraiteBasD); nouveauDocument.Add(tableauTraite); } nouveauDocument.Close(); incCopie++; //--------------------------------------------------COPIE GED-------------------------------------------------------- string nomADH = ""; string numcli = ""; try { String connectionString = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn = new OdbcConnection(connectionString); conn.Open(); //string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + donneeFoot["Tra_nocli"] + "'"; numcli = donneEntete["Tiers_nocpt"].Substring(3, 6); string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + numcli + "'"; OdbcCommand act = new OdbcCommand(requete, conn); OdbcDataReader act0 = act.ExecuteReader(); //string nomADH = ""; //act0.Read(); while (act0.Read()) { nomADH = (act0.GetString(1)); nomADH = nomADH.Trim(); /*test recup nom*/ // LogHelper.WriteToFile("requete : ", requete + "-" + numcli); } conn.Close(); /*if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + "\\" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneeFoot["Tra_nocli"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); }*/ if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + "\\" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + numcli + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Facturation\\RELEVE" + nomDoc + "_" + donneeFoot["Tra_nocli"] + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "nomAdh : " + nomADH + "-"+ numcli + "ENVOI GED Releve"); } //----------------------------------------------FIN COPIE---------------------------------------------------------- //Requette qui retourne le champ "OUI/NON" envoi mail facture String connectionString2 = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn2 = new OdbcConnection(connectionString2); conn2.Open(); //Requete de séléction sur le champ "envoi facture par mail" string requete2 = "select T1.NOCLI c1 , T1.CLID5 c2 , T1.RENDI c3 , T1.PROFE c4 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.CLID5 = 'OUI'"; OdbcCommand act2 = new OdbcCommand(requete2, conn2); OdbcDataReader act20 = null; bool effectuerImpression = true; string numCli =""; try { act20 = act2.ExecuteReader(); while (act20.Read()) { numCli = donneEntete["Tiers_nocpt"].Substring(3, 6); /*ND 27 10 15 correction erreur généré recherche facture oui ou non donnée entete inexistante car code compte*/ // if(act20.GetString(0) == donneEntete["Client_code"])// Si le code client est égale au résultat de la requete sur la ligne lu "NOCLI" if (act20.GetString(0) == numCli)// Si le code client est égale au résultat de la requete sur la ligne lu "NOCLI" { if(act20.GetString(1) == "OUI") //Si la ligne de l'enrigistrement dans la base est à OUI pour cet ID, alors ne pas imprimer { effectuerImpression = false; } } } } catch (Exception e) { LogHelper.WriteToFile(e.Message, "Erreur de connexion à la base, rupture d'impression"); } if (effectuerImpression == true) { int nbImp = 0; int nbImpOK = 0; string[] printer = new string[20]; // tableau qui contient les imprimantes du profil d'impression ProfilImprimante profil = new ProfilImprimante(); profil.chargementXML("Facture"); // chargement selon le type de doc string vendeur = unProfil.Substring(2, 3); vendeur = vendeur.TrimEnd(); var listeProfil = profil.getDonneeProfil(); try { foreach (string v in listeProfil[vendeur]) //lecture des imprimantes liée à un profil { printer[nbImp] = v.ToString(); nbImp++; //on incrémente le nombre d'impression à executer } } catch { printer[nbImp] = ConfigurationManager.AppSettings["ImpDef"]; //Imprimante par defaut (essai) nbImp++; } nbImp = nbImp - 1; while (nbImpOK <= nbImp) // boucle tant que le nombre d'impression fait n'à pas atteint le nombre d'impression demander { string printerName = printer[nbImpOK]; string inputFile = String.Format(@"{0}", chemin); try { //Envoi de l'ordre d'impression vers l'imprimante, les "switches" sont des arguments de la ligne de script "processor" de type GhostscriptProcessor using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=" + ConfigurationManager.AppSettings["NbCopieGC"]); switches.Add("-sDEVICE=" + ConfigurationManager.AppSettings["PiloteImpressionFacture"]); //switches.Add("-r360x360");//Pilote d'impression switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } nbImpOK++; } catch (Exception e) { //LogHelper.WriteToFile(e.Message, "ParseurBP" + donneEntete["Document_numero"].Trim()); LogHelper.WriteToFile(e.Message, "relevé" +donneEntete["Tiers_nocpt"].Trim()); } // incrément à chaque impression terminée } } } }
public void miseEnForm(string typeDoc) { string cheminDocFinaux = ConfigurationManager.AppSettings["CheminDocFinaux"].ToString(); string cheminRessources = ConfigurationManager.AppSettings["CheminRessources"].ToString(); string chemin = cheminDocFinaux + "\\DocFinaux\\DEVIS\\DEVIS_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"; Document nouveauDocument = new Document(PageSize.A4, 20, 20, 12, 20); PdfWriter.GetInstance(nouveauDocument, new FileStream(chemin, FileMode.Create)); //Stockage du document nouveauDocument.Open(); Image image4 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternTot"]); image4.Alignment = Image.UNDERLYING; image4.SetAbsolutePosition(385, 70); //----------------------------------------------------------------------------------------------------Filligrane----------------------------------------------- Image image5 = Image.GetInstance(ConfigurationManager.AppSettings["CheminFilligraneDevis"]); image5.Alignment = Image.UNDERLYING; image5.SetAbsolutePosition(200, 250); nouveauDocument.Add(image5); //---------------------------------------- //Constitution document PDF //---------------------------------------- PdfPTable tableau = new PdfPTable(2); tableau.TotalWidth = 550; tableau.LockedWidth = true; Image image6 = Image.GetInstance(ConfigurationManager.AppSettings["CheminLogoABCRDevis"]); image6.ScaleAbsolute(PageSize.A4); image6.ScaleToFit(175, 180); image6.SetAbsolutePosition(13, 715); nouveauDocument.Add(image6); Paragraph pLogo = new Paragraph(); //Image image = Image.GetInstance(ConfigurationManager.AppSettings["CheminLogoABCRDevis"]); // pLogo.Add(image); //Encadré photo pLogo.Add(new Phrase("")); PdfPCell celulleHauteGauche = new PdfPCell(pLogo); celulleHauteGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celulleHauteGauche); //Encadré info devis Paragraph pDoc = new Paragraph(); Image image2 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternHautDroiteDevis"]); image2.Alignment = Image.UNDERLYING; image2.SetAbsolutePosition(335, 740); nouveauDocument.Add(image2); pDoc.Alignment = Element.ALIGN_RIGHT; pDoc.Add(new Phrase("Devis n° " + donneeBody["Bon_numero1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pDoc.Add(new Phrase("Date : " + donneeBody["Bon_datrcl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase("Référence client : " + donneeBody["Bon_rcl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, BaseColor.RED))); pDoc.Add(new Phrase("Code client: " + donneEntete["Client_code"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase(donneEntete["Tiers_tel"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase(donneEntete["Tiers_fax"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8))); pDoc.Add(new Phrase(donneEntete["Tiers_adf5"], FontFactory.GetFont(FontFactory.HELVETICA, 8))); PdfPCell celulleHauteDroite = new PdfPCell(pDoc); celulleHauteDroite.Border = PdfPCell.NO_BORDER; celulleHauteDroite.HorizontalAlignment = Element.ALIGN_CENTER; tableau.AddCell(celulleHauteDroite); //Encadré "ABCR" Paragraph p = new Paragraph(); p.Add(new Phrase(donneEntete["Adresse_interne_2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_4"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_5"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_6"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_7"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); p.Add(new Phrase(donneEntete["Adresse_interne_8"] + "\n" + "\n" + "\n" + "\n" + "\n ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); PdfPCell celluleBasGauche = new PdfPCell(p); celluleBasGauche.Border = PdfPCell.NO_BORDER; tableau.AddCell(celluleBasGauche); //Encadré client Paragraph pClient = new Paragraph(); if (donneEntete["Tiers_adl1"] == "") { pClient.Add(new Phrase("\n" + "\n" + donneEntete["Tiers_adf1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adf2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adf3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adf4"] + "\n" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adf6"], FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); } else { pClient.Add(new Phrase("\n" /*+"\n"*/ + donneEntete["Tiers_adl1"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adl2"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adl3"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adl4"] + "\n" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); pClient.Add(new Phrase(donneEntete["Tiers_adlcp"] + " " + donneEntete["Tiers_adl6"], FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD))); } PdfPCell celluleBasDroite = new PdfPCell(pClient); celluleBasDroite.Border = PdfPCell.NO_BORDER; tableau.AddCell(celluleBasDroite); nouveauDocument.Add(tableau); //Dessus tableau Paragraph pRécap = new Paragraph(); Chunk contact = null; contact = new Chunk("Votre contact : " + donneEntete["Bon_vendeur_lib"] + "\n " + donneEntete["Duplicata"], FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.ITALIC));//FontFactory pour changer la police Chunk delai = new Chunk("Livraison : " + donneEntete["Tiers_adf1"] + " - " + donneEntete["Tiers_adf2"] + " - " + donneEntete["Tiers_adfcp"] + " " + donneEntete["Tiers_adf6"] + "\n" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.ITALIC)).SetUnderline(2, 2); Chunk ligneEspace = new Chunk("\n", FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.ITALIC)); pRécap.Add(contact); pRécap.Add(delai); pRécap.Add(ligneEspace); nouveauDocument.Add(pRécap); CurseurTemplate ct = new CurseurTemplate(); valeurTemplate = ct.chercher("Devis"); float[] largeurs = { int.Parse(valeurTemplate["Dimension1"]), int.Parse(valeurTemplate["Dimension2"]), int.Parse(valeurTemplate["Dimension3"]), int.Parse(valeurTemplate["Dimension4"]), int.Parse(valeurTemplate["Dimension5"]), int.Parse(valeurTemplate["Dimension6"]), int.Parse(valeurTemplate["Dimension7"]), int.Parse(valeurTemplate["Dimension8"]), int.Parse(valeurTemplate["Dimension9"]) }; // Dimension tableau body PdfPTable table = new PdfPTable(largeurs); table.TotalWidth = 555; //Chaque colonne crée ci dessus doit être rempli table.LockedWidth = true; PdfPCell cellET1 = new PdfPCell(new Phrase("Article", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET1.Border = PdfPCell.NO_BORDER; //cellET1.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET1); PdfPCell cellET2 = new PdfPCell(new Phrase("Désignation", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET2.Border = PdfPCell.NO_BORDER; //cellET2.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET2); PdfPCell cellET3 = new PdfPCell(new Phrase("UV", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET3.Border = PdfPCell.NO_BORDER; //cellET3.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET3); PdfPCell cellET4 = new PdfPCell(new Phrase("Quantité", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET4.Border = PdfPCell.NO_BORDER; //cellET4.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET4); PdfPCell cellET5 = new PdfPCell(new Phrase("Prix remisé", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET5.Border = PdfPCell.NO_BORDER; //cellET5.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET5); PdfPCell cellET6 = new PdfPCell(new Phrase("Remise", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET6.Border = PdfPCell.NO_BORDER; //cellET6.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET6); PdfPCell cellET7 = new PdfPCell(new Phrase("Prix net", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET7.Border = PdfPCell.NO_BORDER; //cellET7.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET7); PdfPCell cellET8 = new PdfPCell(new Phrase("Montant HT", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET8.Border = PdfPCell.NO_BORDER; //cellET8.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET8); PdfPCell cellET9 = new PdfPCell(new Phrase("TVA", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellET9.Border = PdfPCell.NO_BORDER; //cellET9.Border += PdfPCell.BOTTOM_BORDER; table.AddCell(cellET9); Image image3 = Image.GetInstance(ConfigurationManager.AppSettings["CheminPatternTableau"]); image3.Alignment = Image.UNDERLYING; image3.SetAbsolutePosition(20, 567); nouveauDocument.Add(image3); int i; int nbLigne = 0; float resultat = 0; float dimTab = 0; int décrement = 0; int numPage = 0; //Constitution du tableau d'article bool okDési = false; bool okStart = false; for (i = 1; i <= iBody; i++) { //Condition ARTICLE---------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "ART") { nbLigne++; string sPattern = "libelle" + i + "bis"; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Art_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell1); Paragraph pCell2 = new Paragraph(); PdfPCell cell2 = new PdfPCell(pCell2); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; foreach (KeyValuePair <string, string> entry in donneeBody) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Key, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { if (okStart == false) { pCell2.Add(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); string clé = entry.Key; pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); okStart = true; } else { string clé = entry.Key; pCell2.Add(new Phrase(donneeBody[clé] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); } okDési = true; } } if (okDési == false) { PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell3); } else { table.AddCell(cell2); } PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Art_unite" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Art_qte" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase(donneeBody["Art_remise2" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell6); PdfPCell cell7 = new PdfPCell(new Phrase(donneeBody["Art_remise1" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell7.Border = PdfPCell.NO_BORDER; cell7.Border += PdfPCell.RIGHT_BORDER; cell7.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell7); if (donneeBody["Art_prinet" + i] != "") { PdfPCell cell8 = new PdfPCell(new Phrase(double.Parse(donneeBody["Art_prinet" + i]).ToString("N2") + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell8.Border = PdfPCell.NO_BORDER; cell8.Border += PdfPCell.RIGHT_BORDER; cell8.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell8); } else { PdfPCell cell8 = new PdfPCell(new Phrase(donneeBody["Art_prinet" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell8.Border = PdfPCell.NO_BORDER; cell8.Border += PdfPCell.RIGHT_BORDER; cell8.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell8); } PdfPCell cell9 = new PdfPCell(new Phrase(donneeBody["Art_monht" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell9.Border = PdfPCell.NO_BORDER; cell9.Border += PdfPCell.RIGHT_BORDER; cell9.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell9); PdfPCell cell10 = new PdfPCell(new Phrase("0" + donneeBody["Art_tva_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell10.Border = PdfPCell.NO_BORDER; cell10.Border += PdfPCell.RIGHT_BORDER; cell10.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell10); okDési = false; okStart = false; } //Condition ARTICLE GRATUIT----------------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "GRA") { nbLigne++; string sPattern = "libelle" + i + "bis"; PdfPCell cell1 = new PdfPCell(new Phrase(donneeBody["Art_code" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell1.Border = PdfPCell.NO_BORDER; cell1.Border += PdfPCell.RIGHT_BORDER; cell1.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell1); foreach (KeyValuePair <string, string> entry in donneeBody) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Key, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { PdfPCell cell2 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n" + donneeBody["Libelle" + i + "bis"] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell2.Border = PdfPCell.NO_BORDER; cell2.Border += PdfPCell.RIGHT_BORDER; cell2.Border += PdfPCell.LEFT_BORDER; okDési = true; table.AddCell(cell2); } } if (okDési == false) { PdfPCell cell3 = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell3.Border = PdfPCell.NO_BORDER; cell3.Border += PdfPCell.RIGHT_BORDER; cell3.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell3); } PdfPCell cell4 = new PdfPCell(new Phrase(donneeBody["Art_unite" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell4.Border = PdfPCell.NO_BORDER; cell4.Border += PdfPCell.RIGHT_BORDER; cell4.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell4); PdfPCell cell5 = new PdfPCell(new Phrase(donneeBody["Art_qte" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell5.Border = PdfPCell.NO_BORDER; cell5.Border += PdfPCell.RIGHT_BORDER; cell5.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell5); PdfPCell cell6 = new PdfPCell(new Phrase("" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell6.Border = PdfPCell.NO_BORDER; cell6.Border += PdfPCell.RIGHT_BORDER; cell6.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell6); table.AddCell(cell6); table.AddCell(cell6); PdfPCell cell7 = new PdfPCell((new Phrase(donneeBody["Lib_rempl_mt" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD)))); cell7.Border = PdfPCell.NO_BORDER; cell7.Border += PdfPCell.RIGHT_BORDER; cell7.Border += PdfPCell.LEFT_BORDER; table.AddCell(cell7); PdfPCell cell8 = new PdfPCell(new Phrase("" + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cell8.Border = PdfPCell.NO_BORDER; cell8.Border += PdfPCell.LEFT_BORDER; cell8.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cell8); } //Condition COMMENTAIRE-------------------------------------------------------------------------------------------------------------------------------- if (donneeBody["Ligne_type" + i] == "COM") { nbLigne++; PdfPCell cellVide = new PdfPCell(new Phrase("" + "\n")); PdfPCell cell = new PdfPCell(new Phrase(donneeBody["Libelle" + i] + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); PdfPCell cellFin = new PdfPCell(); cellVide.Border = PdfPCell.NO_BORDER; cellVide.Border += PdfPCell.RIGHT_BORDER; cellVide.Border += PdfPCell.LEFT_BORDER; cell.Border = PdfPCell.NO_BORDER; cell.Border += PdfPCell.RIGHT_BORDER; cell.Border += PdfPCell.LEFT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.LEFT_BORDER; cellFin.Border += PdfPCell.RIGHT_BORDER; table.AddCell(cellVide); table.AddCell(cell); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellVide); table.AddCell(cellFin); } PdfPCell cellEcartDroite = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); PdfPCell cellEcart = new PdfPCell(new Phrase(" " + "\n", FontFactory.GetFont(FontFactory.HELVETICA, 2, Font.BOLD))); cellEcart.Border = PdfPCell.NO_BORDER; cellEcart.Border += PdfPCell.LEFT_BORDER; cellEcart.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border = PdfPCell.NO_BORDER; cellEcartDroite.Border += PdfPCell.RIGHT_BORDER; cellEcartDroite.Border += PdfPCell.LEFT_BORDER; table.AddCell(cellEcartDroite); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); table.AddCell(cellEcart); //--------------------------------------------GESTION DU SAUT DE PAGE------------------------------------------------------------------------------------------- //float temp = table.GetRowHeight(i-1-décrement); float temp = table.TotalHeight; dimTab = temp; if (dimTab >= 410 && i < iBody) { //Saut de page numPage++; PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 9; cellBlanche.FixedHeight = (450 - dimTab); cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = (450 - dimTab); cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); nouveauDocument.Add(table);//----------------------------------------------------------------------------Repère ligne en dessous-------------------------------------------------- Phrase pReport = new Phrase(" A REPORTER\n\n\n\n\n Page n° " + numPage, FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); nouveauDocument.Add(pReport); table.DeleteBodyRows(); nouveauDocument.Add(Chunk.NEXTPAGE); nouveauDocument.Add(tableau); nouveauDocument.Add(pRécap); nouveauDocument.Add(image2); nouveauDocument.Add(image3); nouveauDocument.Add(image5); table.AddCell(cellET1); table.AddCell(cellET2); table.AddCell(cellET3); table.AddCell(cellET4); table.AddCell(cellET5); table.AddCell(cellET6); table.AddCell(cellET7); table.AddCell(cellET8); table.AddCell(cellET9); dimTab = 0; décrement = (i - 1); } //---------------------------------------------------------------------------------------------------------------------------------------------------------------------- } int b; //---------------------------------------------------------------- for (b = 0; b <= i; b++) // { // Compteur dimension du tableau float temp = table.TotalHeight; // resultat = temp; // } //------------------------------------------------------------------- if (i > iBody) { PdfPCell cellFin = new PdfPCell(new Phrase(" ")); PdfPCell cellBlanche = new PdfPCell(new Phrase(" ")); PdfPCell cellBlancheD = new PdfPCell(new Phrase(" ")); cellFin.Colspan = 9; resultat = 450 - resultat; //<<----------450 correspond au nombre de point de la longueur du tableau, c'est la valeur à modifier pour modifier la taille du tableau cellBlanche.FixedHeight = resultat; cellBlanche.Border = PdfPCell.NO_BORDER; cellBlanche.Border += PdfPCell.RIGHT_BORDER; cellBlanche.Border += PdfPCell.LEFT_BORDER; cellBlancheD.FixedHeight = resultat; cellBlancheD.Border = PdfPCell.NO_BORDER; cellBlancheD.Border += PdfPCell.LEFT_BORDER; cellBlancheD.Border += PdfPCell.RIGHT_BORDER; cellFin.Border = PdfPCell.NO_BORDER; cellFin.Border += PdfPCell.TOP_BORDER; table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlanche); table.AddCell(cellBlancheD); table.AddCell(cellFin); } nouveauDocument.Add(table); // Constitution tableau pied de page PdfPTable tableauPied = new PdfPTable(3); tableauPied.TotalWidth = 555; tableauPied.LockedWidth = true; Paragraph pTVA = new Paragraph(); pTVA.Add(new Phrase("Offre de prix valable jusqu'au : " + donneEntete["Date_val"], FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.RED))); int iF = 0; foreach (KeyValuePair <string, string> entry in donneeFoot) { if (System.Text.RegularExpressions.Regex.IsMatch(entry.Value, "TVA", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { pTVA.Add(new Phrase("\nTVA " + donneeFoot.ElementAt(iF - 1).Value + " = " + entry.Value, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); } iF++; } PdfPCell cellulePied = new PdfPCell(pTVA); cellulePied.Colspan = 2; cellulePied.Border = PdfPCell.NO_BORDER; tableauPied.AddCell(cellulePied); nouveauDocument.Add(image4); PdfPTable tableauTot = new PdfPTable(1); PdfPCell cellTTot = new PdfPCell(new Phrase("Total HT : " + donneeFoot["Base_tva_mht"] + " €", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellTTot.Border = PdfPCell.NO_BORDER; cellTTot.Border = PdfPCell.BOTTOM_BORDER; tableauTot.AddCell(cellTTot); PdfPCell cellTVA = new PdfPCell(new Phrase("Total TVA : " + donneeFoot["Base_tva_mtva"] + " €", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellTVA.Border = PdfPCell.NO_BORDER; cellTVA.Border = PdfPCell.BOTTOM_BORDER; tableauTot.AddCell(cellTVA); PdfPCell cellTTC = new PdfPCell(new Phrase("Total TTC : " + donneeFoot["Base_tva_mttc"] + " €", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD))); cellTTC.Border = PdfPCell.NO_BORDER; tableauTot.AddCell(cellTTC); PdfPCell cellTot = new PdfPCell(tableauTot); cellTot.Border = PdfPCell.NO_BORDER; tableauPied.AddCell(cellTot); nouveauDocument.Add(tableauPied); Phrase maPhrase = new Phrase(); maPhrase.Add(new Chunk("\nBon pour accord ", FontFactory.GetFont(FontFactory.HELVETICA, 9, Font.BOLD))); maPhrase.Add(new Chunk("\n Fait à: le: Signature", FontFactory.GetFont(FontFactory.HELVETICA, 8))); nouveauDocument.Add(maPhrase); if (numPage > 0) { Phrase PageFinal = new Phrase(" Page n° " + (1 + numPage), FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD)); nouveauDocument.Add(PageFinal); } nouveauDocument.Close(); //Copie Doc dans GED try { String connectionString = ConfigurationManager.AppSettings["ChaineDeConnexionBase"]; OdbcConnection conn = new OdbcConnection(connectionString); conn.Open(); string requete = "select T1.NOCLI c1 , T1.NOMCL c2 from B00C0ACR.AMAGESTCOM.ACLIENL1 T1 where T1.NOCLI = '" + donneEntete["Client_code"] + "'"; OdbcCommand act = new OdbcCommand(requete, conn); OdbcDataReader act0 = act.ExecuteReader(); string nomADH = ""; while (act0.Read()) { nomADH = (act0.GetString(1)); } conn.Close(); if (!System.IO.Directory.Exists(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\")) { System.IO.Directory.CreateDirectory(ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\"); System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\" + "\\DEVIS_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } else { System.IO.File.Copy(chemin, ConfigurationManager.AppSettings["cheminGED"] + "\\" + donneEntete["Client_code"] + " - " + nomADH + "\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MM").ToUpperInvariant() + "-" + DateTime.Now.ToString("MMMM").First().ToString().ToUpper() + String.Join("", DateTime.Now.ToString("MMMM").Skip(1)) + "\\Devis\\" + "\\DEVIS_" + nomDoc + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".pdf"); } } catch { } //--------------------------------------------------------FIN COPIE---------------------------------------------------------------------------------------------------------- int nbImp = 0; int nbImpOK = 0; string[] printer = new string[20]; // tableau qui contient les imprimantes du profil d'impression ProfilImprimante profil = new ProfilImprimante(); profil.chargementXML("Dev"); // chargement selon le type de doc string vendeur = unProfil.Substring(2, 3); vendeur = vendeur.TrimEnd(); var listeProfil = profil.getDonneeProfil(); try { foreach (string v in listeProfil[vendeur]) //lecture des imprimantes liée à un profil { printer[nbImp] = v.ToString(); nbImp++; //on incrémente le nombre d'impression à executer } } catch { printer[nbImp] = ConfigurationManager.AppSettings["ImpDef"]; //Imprimante par defaut (essai) nbImp++; } nbImp = nbImp - 1; while (nbImpOK <= nbImp) // boucle tant que le nombre d'impression fait n'à pas atteint le nombre d'impression demander { string printerName = printer[nbImpOK]; string inputFile = String.Format(@"{0}", chemin); try { using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=" + ConfigurationManager.AppSettings["NbCopieGC"]); switches.Add("-sDEVICE=" + ConfigurationManager.AppSettings["PiloteImpressionGC"]); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } nbImpOK++; } catch (Exception e) { LogHelper.WriteToFile(e.Message, "ParseurBP" + donneEntete["Document_numero"].Trim()); } } /*Mail m = new Mail(); * m.remplirDictionnaire(); * m.comparerDocument(donneEntete["Client_code"]);*/ }
public void execPrint() { try { this.Cursor = Cursors.WaitCursor; using (GhostscriptProcessor processor = new GhostscriptProcessor()) { if (diagFlg) { if (rdPage1.Checked) { stSize = CommonTeisu.SIZE_B5; } else if (rdPage2.Checked) { stSize = CommonTeisu.SIZE_A4; } if (rdPage3.Checked) { stSize = CommonTeisu.SIZE_B4; } lstSize = CommonTeisu.paramSize[stSize]; } List <string> switches = new List <string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); //switches.Add("-dNumCopies=" + _intPrintCnt.ToString()); //部数 switches.Add("-dNumCopies=1"); //部数 switches.Add("-sDEVICE=mswinpr2"); switches.Add("-sOutputFile=%printer%" + _printer); if (stSize == CommonTeisu.SIZE_NAGA3 || stSize == CommonTeisu.SIZE_NAGA4) { switches.Add("-dManualFeed"); switches.Add("-dCasset=1"); if (tateFlg) { switches.Add("-dDEVICEWIDTHPOINTS=" + lstSize[1]); switches.Add("-dDEVICEHEIGHTPOINTS=" + lstSize[0]); //switches.Add("-sPAPERSIZE=" + stSize); //switches.Add("-g" + lstSize[1] + "x" + lstSize[0]); } else { //横指定A4 switches.Add("-dDEVICEWIDTHPOINTS=" + lstSize[0]); switches.Add("-dDEVICEHEIGHTPOINTS=" + lstSize[1]); //switches.Add("-g" + lstSize[0] + "x" + lstSize[1]); } //switches.Add("-dFitPage"); } else { if (tateFlg) { switches.Add("-dDEVICEWIDTHPOINTS=" + lstSize[1]); switches.Add("-dDEVICEHEIGHTPOINTS=" + lstSize[0]); //switches.Add("-sPAPERSIZE=" + stSize); //switches.Add("-g" + lstSize[1] + "x" + lstSize[0]); } else { //横指定A4 switches.Add("-dDEVICEWIDTHPOINTS=" + lstSize[0]); switches.Add("-dDEVICEHEIGHTPOINTS=" + lstSize[1]); //switches.Add("-g" + lstSize[0] + "x" + lstSize[1]); } //両面印刷 //switches.Add("-dDuplex");//TrueON,false=off //switches.Add("-dTumble=true");//True=短辺綴じ false=長辺綴じ switches.Add("-dFitPage"); } switches.Add("-f"); switches.Add(stPath); processor.StartProcessing(switches.ToArray(), null); } } catch (Exception ex) { throw ex; } finally { this.Cursor = Cursors.Default; } }