Beispiel #1
0
        public void PechkinMultiConvert(string FilesDir)
        {
            //取得目標資料夾中所有符合條件的所有檔案
            string[] FilePath = Directory.GetFiles(FilesDir, "*");

            //開始逐檔將HTML轉PDF
            foreach (var i in FilePath)
            {
                Console.WriteLine("開始從" + i + "\n\r 產生:" + Path.GetFileNameWithoutExtension(i) + ".pdf");

                var          config  = new GlobalConfig();
                var          pechkin = new SimplePechkin(config);
                ObjectConfig oc      = new ObjectConfig();
                oc.SetPrintBackground(true).SetLoadImages(true);
                string HTML = ""; //讀入html
                try
                {                 // Open the text file using a stream reader.
                    using (StreamReader sr = new StreamReader(i))
                    {
                        // Read the stream to a string, and write the string to the console.
                        HTML = sr.ReadToEnd();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("The file could not be read:");
                    Console.WriteLine(e.Message);
                }

                byte[] pdf = pechkin.Convert(oc, HTML);
                File.WriteAllBytes(FilesDir + @"\" + Path.GetFileNameWithoutExtension(i) + ".pdf", pdf);
                Console.WriteLine(Path.GetFileNameWithoutExtension(i) + ".pdf 轉換完成");
            }
        }
        /// <summary>
        /// Метод конвертирует html код в pdf файл
        /// Используется библиотека Pechkin
        /// </summary>
        /// <param name="pdfName">имя pdf файла</param>
        /// <param name="folderPath">путь к директории сохранения</param>
        private void HtmlToPdf(string pdfName, string folderPath = null)
        {
            GlobalConfig globalConfig = new GlobalConfig();

            globalConfig
            .SetMargins(EngineerMenu.PC.PrinterTopMarg, EngineerMenu.PC.PrinterRightMarg, EngineerMenu.PC.PrinterBottomMarg, EngineerMenu.PC.PrinterLeftMarg)
            .SetDocumentTitle("PdfDoc")
            .SetPaperSize(PaperKind.A4);

            IPechkin pechkin = new SimplePechkin(globalConfig);

            byte[] pdfBufferBytes = pechkin.Convert(_strBuilder.ToString());

            if (folderPath != null)
            {
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                File.WriteAllBytes(folderPath + @"\" + pdfName, pdfBufferBytes);
            }
            else
            {
                File.WriteAllBytes(pdfName, pdfBufferBytes);
            }
        }
 public void GenerateMemberList(List <Member> members, DateTime snapshot)
 {
     try
     {
         string input = File.ReadAllText(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html\\Template_Memberlist.htm");
         string str1  = "Ledenlijst: " + snapshot.ToShortDateString();
         this.FilePath = Path.GetTempPath() + ("tmp" + Util.Util.RandomString(10)) + ".pdf";
         StringBuilder stringBuilder = new StringBuilder();
         int           num           = 1;
         foreach (Member member in members)
         {
             stringBuilder.Append(num % 2 > 0 ? "<tr>" : "<tr class=\"alt\">");
             stringBuilder.Append("<td>" + (object)num + "</td>");
             stringBuilder.Append("<td>" + member.LastName + "</td>");
             stringBuilder.Append("<td>" + member.FirstName + "</td>");
             stringBuilder.Append("<td>" + member.ZipCode + "</td>");
             stringBuilder.Append("<td>" + member.City + "</td>");
             stringBuilder.Append("<td>" + member.Address + "</td>");
             stringBuilder.Append("<td>" + member.Country + "</td>");
             DateTime dateTime = member.BirthDate ?? new DateTime();
             stringBuilder.Append("<td>" + dateTime.ToShortDateString() + "</td>");
             stringBuilder.Append("<td>" + member.Email + "</td>");
             stringBuilder.Append("<td>" + member.TelephoneNr + "</td>");
             stringBuilder.Append("</tr>");
             ++num;
         }
         string str2 = new Regex("\\[(\\w+)\\]", RegexOptions.Compiled).Replace(input, (MatchEvaluator)(match => new Dictionary <string, string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase)
         {
             {
                 "Title",
                 str1
             },
             {
                 "ImagePath",
                 Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html"
             },
             {
                 "MemberOverviewTableElements",
                 stringBuilder.ToString()
             }
         }[match.Groups[1].Value]));
         GlobalConfig config = new GlobalConfig();
         config.SetMargins(new Margins(70, 45, 70, 45)).SetPaperSize(PaperKind.A4Rotated);
         SimplePechkin simplePechkin = new SimplePechkin(config);
         ObjectConfig  objectConfig  = new ObjectConfig();
         objectConfig.SetLoadImages(true);
         objectConfig.SetPrintBackground(true);
         objectConfig.SetZoomFactor(1.1);
         objectConfig.SetAllowLocalContent(true);
         ObjectConfig doc  = objectConfig;
         string       html = str2;
         File.WriteAllBytes(this.FilePath, simplePechkin.Convert(doc, html));
         PdfReportService.logger.Info("Memberlist PDF created: " + this.FilePath);
     }
     catch (Exception ex)
     {
         PdfReportService.logger.Error("Could not create temporary PDF file:" + ex.Message);
     }
 }
Beispiel #4
0
//html to Pdf
        public static void HtmlToPdf(string filePath, string html, bool isOrientation = false)
        {
            if (string.IsNullOrEmpty(html))
            {
                html = "Null";
            }
            // 创建全局信息
            GlobalConfig gc = new GlobalConfig();

            gc.SetMargins(new Margins(50, 50, 60, 60))
            .SetDocumentTitle("MarkWord")
            .SetPaperSize(PaperKind.A4)
            .SetPaperOrientation(isOrientation)
            .SetOutlineGeneration(true);


            //页面信息
            ObjectConfig oc = new ObjectConfig();

            oc.SetCreateExternalLinks(false)
            .SetFallbackEncoding(Encoding.UTF8)
            .SetLoadImages(true)
            .SetScreenMediaType(true)
            .SetPrintBackground(true);
            //.SetZoomFactor(1.5);

            var pechkin = new SimplePechkin(gc);

            pechkin.Finished        += Pechkin_Finished;
            pechkin.Error           += Pechkin_Error;
            pechkin.ProgressChanged += Pechkin_ProgressChanged;
            var buf = pechkin.Convert(oc, html);

            if (buf == null)
            {
                Common.ShowMessage("导出异常");
                return;
            }

            try
            {
                string     fn = filePath; //Path.GetTempFileName() + ".pdf";
                FileStream fs = new FileStream(fn, FileMode.Create);
                fs.Write(buf, 0, buf.Length);
                fs.Close();

                //Process myProcess = new Process();
                //myProcess.StartInfo.FileName = fn;
                //myProcess.Start();
            }
            catch { }
        }
Beispiel #5
0
        private void SaveHtmlAsPdf(string fName, string html)
        {
            GlobalConfig  cfg = new GlobalConfig();
            SimplePechkin sp  = new SimplePechkin(cfg);
            ObjectConfig  oc  = new ObjectConfig();

            oc.SetCreateExternalLinks(true)
            .SetFallbackEncoding(Encoding.ASCII)
            .SetLoadImages(true)
            .SetAllowLocalContent(true)
            .SetPrintBackground(true);

            byte[]     pdfBuf = sp.Convert(oc, "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title></title></head><body>" + html + "</body></html>");
            FileStream fs     = new FileStream(fName, FileMode.Create, FileAccess.ReadWrite);

            foreach (var byteSymbol in pdfBuf)
            {
                fs.WriteByte(byteSymbol);
            }
            fs.Close();
        }
Beispiel #6
0
        private static void WritePdfFromHtml(string html, string outputFile, string documentTitle, string cssFile, string headerHtmlFile, string footerHtmlFile)
        {
            GlobalConfig gc = new GlobalConfig();

            gc.SetPaperSize(System.Drawing.Printing.PaperKind.A4);
            gc.SetPaperOrientation(false);
            gc.SetDocumentTitle(documentTitle);

            SimplePechkin pechkin = new SimplePechkin(gc);
            ObjectConfig  oc      = new ObjectConfig();

            oc.SetAllowLocalContent(true);
            oc.SetPrintBackground(true);

            if (!string.IsNullOrEmpty(cssFile))
            {
                /// for some reason oc.SetUserStylesheetUri(new Uri(cssFile).AbsoluteUri) is not working, so although
                /// this looks hacky, it gets the job done
                html = @"<link href=""" + new Uri(cssFile).AbsoluteUri + @""" rel=""stylesheet"" type=""text/css"" />" + System.Environment.NewLine + html;
            }

            if (!string.IsNullOrEmpty(headerHtmlFile))
            {
                oc.Header.SetHtmlContent(new Uri(headerHtmlFile).AbsoluteUri);
            }

            if (!string.IsNullOrEmpty(footerHtmlFile))
            {
                oc.Footer.SetHtmlContent(new Uri(footerHtmlFile).AbsoluteUri);
            }

            try
            {
                System.IO.File.WriteAllBytes(outputFile, pechkin.Convert(oc, html));
            }
            catch (System.IO.IOException)
            {
                Console.WriteLine("The PDF file you are writing to is likely already open/in use");
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
            maxTreadNumber = int.Parse(ConfigurationManager.AppSettings["MaxThreadNumber"].ToString());
            string[] paras = args[0].Split(',');
            environment = paras[0];
            switch (environment)
            {
            case "1":
                environment = "DEV";
                break;

            case "2":
                environment = "QA";
                break;

            case "3":
                environment = "UAT";
                break;

            case "4":
                environment = "PROD";
                break;

            default:
                break;
            }

            // get data from databases
            string connetionStr = ConfigurationManager.ConnectionStrings["SQL" + environment].ConnectionString;

            string cmd = "SELECT [ID],[Control_ID],[Claim_Number],[Claimant_Number],[Form_ID],[sequence],[FormName] ,[URL],[URLDate],[URLFlag],[AttachmentName],[PDFName],[PDFDate] ,[Processed] FROM test where id> (1591748 +" + (1000 * int.Parse(paras[1])).ToString() + ") and id<=(1591748 +"
                         + (1000 * int.Parse(paras[1]) + 1000).ToString() + ")";// [TRANSFORMDB].[dbo].[CMT_ASPX_to_PDF_URL]";

            using (SqlConnection sc = new SqlConnection(connetionStr))
            {
                SqlCommand scmd = new SqlCommand(cmd, sc);
                try
                {
                    sc.Open();
                    SqlDataAdapter sda = new SqlDataAdapter(scmd);
                    DataSet        sd  = new DataSet();
                    sda.Fill(sd);
                    dataRowQueue = new ConcurrentQueue <DataRow>(sd.Tables[0].AsEnumerable().ToList <DataRow>());
                    sda.Dispose();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            //get the html contents
            while (threadNumber < maxTreadNumber)
            {
                //control thread amount
                threadNumber++;
                var thread = getWebBrowerThread();
                //thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }

            Console.WriteLine("started");

            while (dataRowQueue != null && dataRowQueue.Count > 0 && htmlQueue.Count == 0)
            {
                Thread.Sleep(1000);
            }

            while (pdfThreadNumber < maxTreadNumber)
            {
                pdfThreadNumber++;
                Thread pdfThread = new Thread(() =>
                {
                    GlobalConfig gc = new GlobalConfig();
                    gc.SetMargins(new Margins(100, 100, 100, 100));
                    gc.SetPaperSize(PaperKind.Letter);
                    IPechkin pechkin           = new SimplePechkin(gc);
                    ObjectConfig configuration = new ObjectConfig();
                    configuration.SetCreateExternalLinks(true).SetFallbackEncoding(Encoding.UTF8).SetLoadImages(true).SetCreateForms(false);
                    /*test error*/
                    int m = 0;
                    /*end*/

                    while (htmlQueue.Count != 0)
                    {
                        //while(threadNumber>=maxTreadNumber)
                        //    {
                        //        Thread.Sleep(1000);
                        //    }

                        /*test error*/
                        m++;
                        if (m == 50)
                        {
                            throw (new Exception("forced"));
                        }

                        /*end*/

                        while (dataRowQueue != null && dataRowQueue.Count > 0 && htmlQueue.Count == 0)
                        {
                            Thread.Sleep(1000);
                        }

                        /*isProcessDone = false;
                         * var subThread = new Thread(() =>
                         * {*/
                        //threadNumber++;

                        DataRow dr;
                        if (htmlQueue.TryDequeue(out dr))
                        {
                            rounds++;
                            try
                            {
                                byte[] pdfBuf = pechkin.Convert(configuration, dr["URL"].ToString());
                                var testFile  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                                             "testpdf\\" + dr["Claim_Number"].ToString() + "_" + dr["Claimant_Number"].ToString() + "_" + dr["Form_ID"].ToString() + "_" + dr["sequence"].ToString() + ".pdf");
                                System.IO.File.WriteAllBytes(testFile, pdfBuf);
                                pdfBuf = null;
                                dr.Delete();
                                dr       = null;
                                testFile = null;
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message);
                            }
                            if (rounds % 1000 == 0)
                            {
                                GC.Collect();
                                GC.WaitForPendingFinalizers();
                            }
                        }

                        Application.ApplicationExit += Application_PDFApplicationExit;
                        Application.ExitThread();
                        Application.Exit();
                    }
                });
                pdfThread.Start();
            }
        }
        public void GenerateMemberCardList(List <Member> members)
        {
            string input = File.ReadAllText(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html\\Template_Membercardlist.htm");
            string str1  = "Lidkaarten: " + DateTime.Now.ToShortDateString();

            this.FilePath = Path.GetTempPath() + ("tmp" + Util.Util.RandomString(10)) + ".pdf";
            StringBuilder stringBuilder = new StringBuilder();

            foreach (Member member in members)
            {
                stringBuilder.AppendLine("<table class=\"table3\">");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td colspan=\"6\" class=\"memberTitle\">" + member.LastName + " " + member.FirstName + "</td>");
                stringBuilder.AppendLine("</tr>");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\">Postcode</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\">Gemeente</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\" colspan=\"2\">Adres</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\">Land</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\">Geslacht</td>");
                stringBuilder.AppendLine("</tr>");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\">" + member.ZipCode + "</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\">" + member.City + "</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\" colspan=\"2\">" + member.Address + "</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\">" + member.Country + "</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\">" + (member.Gender == Member.Genders.Female ? "Vrouw" : "Man") + "</td>");
                stringBuilder.AppendLine("</tr>");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\" colspan=\"2\">Geboortedatum</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\" colspan=\"2\">E-mail adres</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyTitles\" colspan=\"2\">Telefoonnummer</td>");
                stringBuilder.AppendLine("</tr>");
                DateTime dateTime = member.BirthDate ?? new DateTime();
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\" colspan=\"2\">" + dateTime.ToShortDateString() + "</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\" colspan=\"2\">" + member.Email + "</td>");
                stringBuilder.AppendLine("<td class=\"memberPropertyValues\" colspan=\"2\">" + member.TelephoneNr + "</td>");
                stringBuilder.AppendLine("</tr>");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td colspan=\"6\">&nbsp;</td>");
                stringBuilder.AppendLine("</tr>");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine(" <td colspan=\"6\" class=\"memberCardTitle\">Lidkaarten</td>");
                stringBuilder.AppendLine("</tr>");
                stringBuilder.AppendLine("<tr>");
                stringBuilder.AppendLine("<td class=\"memberCardPropertyTitles\">Aanmaakdatum</td>");
                stringBuilder.AppendLine("<td class=\"memberCardPropertyTitles\">Vervaldatum</td>");
                stringBuilder.AppendLine("<td class=\"memberCardPropertyTitles\">Actief lid</td>");
                stringBuilder.AppendLine("<td class=\"memberCardPropertyTitles\">Afgedrukt</td>");
                stringBuilder.AppendLine("<td class=\"memberCardPropertyTitles\">Kaart ID</td>");
                stringBuilder.AppendLine("<td class=\"memberCardPropertyTitles\">Aangemaakt door</td>");
                stringBuilder.AppendLine("</tr>");
                foreach (MemberCard memberCard in (Collection <MemberCard>)member.MemberCards)
                {
                    stringBuilder.AppendLine("<tr>");
                    stringBuilder.AppendLine("<td class =\"memberCardPropertyValues\">" + memberCard.CreationTime.ToShortDateString() + "</td>");
                    stringBuilder.AppendLine("<td class =\"memberCardPropertyValues\">" + memberCard.ExpireDate.ToShortDateString() + "</td>");
                    stringBuilder.AppendLine("<td class =\"memberCardPropertyValues\">" + (memberCard.ActiveMember ? "Ja" : "Nee") + "</td>");
                    stringBuilder.AppendLine("<td class =\"memberCardPropertyValues\">" + (memberCard.Printed ? "Ja" : "Nee") + "</td>");
                    stringBuilder.AppendLine("<td class =\"memberCardPropertyValues\">" + memberCard.SmartCardId + "</td>");
                    stringBuilder.AppendLine("<td class =\"memberCardPropertyValues\">" + (memberCard.CreatedBy != null ? memberCard.CreatedBy.Fullname : string.Empty) + "</td>");
                    stringBuilder.AppendLine("</tr>");
                }
                stringBuilder.AppendLine("</table>");
                stringBuilder.AppendLine("<br />");
            }
            string str2 = new Regex("\\[(\\w+)\\]", RegexOptions.Compiled).Replace(input, (MatchEvaluator)(match => new Dictionary <string, string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase)
            {
                {
                    "Title",
                    str1
                },
                {
                    "ImagePath",
                    Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html"
                },
                {
                    "MemberCardOverviewTable",
                    stringBuilder.ToString()
                }
            }[match.Groups[1].Value]));
            GlobalConfig config = new GlobalConfig();

            config.SetMargins(new Margins(70, 45, 70, 45)).SetPaperSize(PaperKind.A4);
            SimplePechkin simplePechkin = new SimplePechkin(config);
            ObjectConfig  objectConfig  = new ObjectConfig();

            objectConfig.SetLoadImages(true);
            objectConfig.SetPrintBackground(true);
            objectConfig.SetZoomFactor(1.1);
            objectConfig.SetAllowLocalContent(true);
            ObjectConfig doc  = objectConfig;
            string       html = str2;

            File.WriteAllBytes(this.FilePath, simplePechkin.Convert(doc, html));
            PdfReportService.logger.Info("Membercardlist PDF created: " + this.FilePath);
        }
 public void GenerateCheckoutSheet(CheckoutSheet sheet)
 {
     try
     {
         string   input    = File.ReadAllText(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html\\Template_Checkoutsheet.htm");
         DateTime dateTime = sheet.OpenTime ?? DateTime.Now;
         string   str1     = "Kasblad JH Tjok Hove: " + dateTime.ToShortDateString();
         this.FilePath = Path.GetTempPath() + ("Kasblad JH Tjok Hove " + dateTime.ToString("dd_MM_yyyy HH_mm")) + ".pdf";
         List <IGrouping <Product, TicketLine> > list = sheet.Tickets.SelectMany <Ticket, TicketLine>((Func <Ticket, IEnumerable <TicketLine> >)(t => (IEnumerable <TicketLine>)t.TicketLines)).GroupBy <TicketLine, Product>((Func <TicketLine, Product>)(tl => tl.Product)).ToList <IGrouping <Product, TicketLine> >().OrderBy <IGrouping <Product, TicketLine>, string>((Func <IGrouping <Product, TicketLine>, string>)(pl => pl.Key.Name)).ToList <IGrouping <Product, TicketLine> >();
         StringBuilder stringBuilder = new StringBuilder();
         int           num1          = 1;
         foreach (IGrouping <Product, TicketLine> source in list)
         {
             stringBuilder.AppendLine(num1 % 2 > 0 ? "<tr>" : "<tr class=\"alt\">");
             stringBuilder.AppendLine("<td>" + source.Key.Name + "</td>");
             stringBuilder.AppendLine("<td>" + (object)source.Sum <TicketLine>((Func <TicketLine, int>)(l => (int)l.Amount)) + "</td>");
             stringBuilder.AppendLine("</tr>");
             ++num1;
         }
         Dictionary <string, string> formFields = new Dictionary <string, string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);
         formFields.Add("Title", str1);
         Dictionary <string, string> dictionary1 = formFields;
         DateTime?nullable = sheet.OpenTime;
         string   str2     = nullable.ToString();
         dictionary1.Add("OpeningTime", str2);
         Dictionary <string, string> dictionary2 = formFields;
         nullable = sheet.CloseTime;
         string str3 = nullable.ToString();
         dictionary2.Add("ClosureTime", str3);
         formFields.Add("ClosedBy", sheet.ClosedBy.Fullname);
         formFields.Add("OpenedBy", sheet.OpenedBy.Fullname);
         Dictionary <string, string> dictionary3 = formFields;
         int    num2 = sheet.CloseEur500;
         string str4 = num2.ToString();
         dictionary3.Add("AmountEur500", str4);
         Dictionary <string, string> dictionary4 = formFields;
         num2 = sheet.CloseEur200;
         string str5 = num2.ToString();
         dictionary4.Add("AmountEur200", str5);
         Dictionary <string, string> dictionary5 = formFields;
         num2 = sheet.CloseEur100;
         string str6 = num2.ToString();
         dictionary5.Add("AmountEur100", str6);
         Dictionary <string, string> dictionary6 = formFields;
         num2 = sheet.CloseEur50;
         string str7 = num2.ToString();
         dictionary6.Add("AmountEur50", str7);
         formFields.Add("AmountEur20", sheet.CloseEur20.ToString());
         formFields.Add("AmountEur10", sheet.CloseEur10.ToString());
         Dictionary <string, string> dictionary7 = formFields;
         int    num3 = sheet.CloseEur5;
         string str8 = num3.ToString();
         dictionary7.Add("AmountEur5", str8);
         Dictionary <string, string> dictionary8 = formFields;
         num3 = sheet.CloseEur2;
         string str9 = num3.ToString();
         dictionary8.Add("AmountEur2", str9);
         formFields.Add("AmountEur1", sheet.CloseEur1.ToString());
         Dictionary <string, string> dictionary9 = formFields;
         int    num4  = sheet.CloseEur50c;
         string str10 = num4.ToString();
         dictionary9.Add("AmountEur50c", str10);
         Dictionary <string, string> dictionary10 = formFields;
         num4 = sheet.CloseEur20c;
         string str11 = num4.ToString();
         dictionary10.Add("AmountEur20c", str11);
         Dictionary <string, string> dictionary11 = formFields;
         num4 = sheet.CloseEur10c;
         string str12 = num4.ToString();
         dictionary11.Add("AmountEur10c", str12);
         Dictionary <string, string> dictionary12 = formFields;
         num4 = sheet.CloseEur5c;
         string str13 = num4.ToString();
         dictionary12.Add("AmountEur5c", str13);
         Dictionary <string, string> dictionary13 = formFields;
         num4 = sheet.CloseEur2c;
         string str14 = num4.ToString();
         dictionary13.Add("AmountEur2c", str14);
         Dictionary <string, string> dictionary14 = formFields;
         num4 = sheet.CloseEur1c;
         string str15 = num4.ToString();
         dictionary14.Add("AmountEur1c", str15);
         Dictionary <string, string> dictionary15 = formFields;
         num4 = sheet.CloseEur500 * 500;
         string str16 = num4.ToString("C");
         dictionary15.Add("SubtotalEur500", str16);
         Dictionary <string, string> dictionary16 = formFields;
         num4 = sheet.CloseEur200 * 200;
         string str17 = num4.ToString("C");
         dictionary16.Add("SubtotalEur200", str17);
         Dictionary <string, string> dictionary17 = formFields;
         num4 = sheet.CloseEur100 * 100;
         string str18 = num4.ToString("C");
         dictionary17.Add("SubtotalEur100", str18);
         Dictionary <string, string> dictionary18 = formFields;
         num4 = sheet.CloseEur50 * 50;
         string str19 = num4.ToString("C");
         dictionary18.Add("SubtotalEur50", str19);
         Dictionary <string, string> dictionary19 = formFields;
         num4 = sheet.CloseEur20 * 20;
         string str20 = num4.ToString("C");
         dictionary19.Add("SubtotalEur20", str20);
         Dictionary <string, string> dictionary20 = formFields;
         num4 = sheet.CloseEur10 * 10;
         string str21 = num4.ToString("C");
         dictionary20.Add("SubtotalEur10", str21);
         Dictionary <string, string> dictionary21 = formFields;
         num4 = sheet.CloseEur5 * 5;
         string str22 = num4.ToString("C");
         dictionary21.Add("SubtotalEur5", str22);
         Dictionary <string, string> dictionary22 = formFields;
         num4 = sheet.CloseEur2 * 2;
         string str23 = num4.ToString("C");
         dictionary22.Add("SubtotalEur2", str23);
         Dictionary <string, string> dictionary23 = formFields;
         num4 = sheet.CloseEur1 * 1;
         string str24 = num4.ToString("C");
         dictionary23.Add("SubtotalEur1", str24);
         Dictionary <string, string> dictionary24 = formFields;
         double num5  = (double)sheet.CloseEur50c * 0.5;
         string str25 = num5.ToString("C");
         dictionary24.Add("SubtotalEur50c", str25);
         Dictionary <string, string> dictionary25 = formFields;
         num5 = (double)sheet.CloseEur20c * 0.2;
         string str26 = num5.ToString("C");
         dictionary25.Add("SubtotalEur20c", str26);
         Dictionary <string, string> dictionary26 = formFields;
         num5 = (double)sheet.CloseEur10c * 0.1;
         string str27 = num5.ToString("C");
         dictionary26.Add("SubtotalEur10c", str27);
         Dictionary <string, string> dictionary27 = formFields;
         num5 = (double)sheet.CloseEur5c * 0.05;
         string str28 = num5.ToString("C");
         dictionary27.Add("SubtotalEur5c", str28);
         Dictionary <string, string> dictionary28 = formFields;
         num5 = (double)sheet.CloseEur2c * 0.02;
         string str29 = num5.ToString("C");
         dictionary28.Add("SubtotalEur2c", str29);
         Dictionary <string, string> dictionary29 = formFields;
         num5 = (double)sheet.CloseEur1c * 0.01;
         string str30 = num5.ToString("C");
         dictionary29.Add("SubtotalEur1c", str30);
         Dictionary <string, string> dictionary30 = formFields;
         num5 = sheet.CloseAmount;
         string str31 = num5.ToString("C");
         dictionary30.Add("EndTotal", str31);
         Dictionary <string, string> dictionary31 = formFields;
         num5 = sheet.OpenAmount;
         string str32 = num5.ToString("C");
         dictionary31.Add("BeginTotal", str32);
         Dictionary <string, string> dictionary32 = formFields;
         num5 = sheet.CloseAmount - sheet.OpenAmount;
         string str33 = num5.ToString("C");
         dictionary32.Add("Revenue", str33);
         formFields.Add("Remarks", sheet.Comments);
         formFields.Add("ImagePath", Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html");
         formFields.Add("TableSoldProducts", stringBuilder.ToString());
         string       str34  = new Regex("\\[(\\w+)\\]", RegexOptions.Compiled).Replace(input, (MatchEvaluator)(match => formFields[match.Groups[1].Value]));
         GlobalConfig config = new GlobalConfig();
         config.SetMargins(new Margins(70, 45, 70, 45)).SetPaperSize(PaperKind.A4);
         SimplePechkin simplePechkin = new SimplePechkin(config);
         ObjectConfig  objectConfig  = new ObjectConfig();
         objectConfig.SetLoadImages(true);
         objectConfig.SetPrintBackground(true);
         objectConfig.SetZoomFactor(1.1);
         objectConfig.SetAllowLocalContent(true);
         ObjectConfig doc  = objectConfig;
         string       html = str34;
         File.WriteAllBytes(this.FilePath, simplePechkin.Convert(doc, html));
         PdfReportService.logger.Info("Checkoutsheet PDF created: " + this.FilePath);
     }
     catch (Exception ex)
     {
         PdfReportService.logger.Error("Could not create temporary PDF file:" + ex.Message);
     }
 }
 public void GenerateCheckoutTicketOverview(CheckoutSheet sheet)
 {
     try
     {
         string   input    = File.ReadAllText(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html\\Template_Checkoutsheet_TicketOverview.htm");
         DateTime dateTime = sheet.OpenTime ?? DateTime.Now;
         string   str1     = "Ticketoverzicht: " + dateTime.ToShortDateString();
         this.FilePath = Path.GetTempPath() + ("Ticketoverzicht " + dateTime.ToString("dd_MM_yyyy HH_mm")) + ".pdf";
         StringBuilder stringBuilder1 = new StringBuilder();
         foreach (Ticket ticket in (Collection <Ticket>)sheet.Tickets)
         {
             stringBuilder1.AppendLine("<table class=\"table3\">");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td colspan=\"6\" class=\"ticketTitle\">Ticket &#35;" + (object)ticket.Id + "</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyTitles\" colspan=\"2\">Datum</td>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyTitles\">Waarde EUR</td>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyTitles\">Waarde Bonnen</td>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyTitles\" colspan=\"2\">Aangemaakt door</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td class =\"ticketPropertyValues\" colspan=\"2\">" + (object)ticket.CreationTime + "</td>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyValues\">" + ticket.TotalPrice.ToString("C") + "</td>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyValues\">" + (object)ticket.TotalCoins + "</td>");
             stringBuilder1.AppendLine("<td class=\"ticketPropertyValues\" colspan=\"2\">" + ticket.CreatedBy.Fullname + "</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td colspan=\"6\">&nbsp;</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine(" <td colspan=\"6\" class=\"productsTitle\">Producten</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td class=\"productsPropertyTitles\">Naam</td>");
             stringBuilder1.AppendLine("<td class =\"productsPropertyTitles\">Hoeveelheid</td>");
             stringBuilder1.AppendLine("<td class=\"productsPropertyTitles\">Stukprijs EUR</td>");
             stringBuilder1.AppendLine("<td class=\"productsPropertyTitles\">Stukprijs Bonnen</td>");
             stringBuilder1.AppendLine("<td class=\"productsPropertyTitles\">Subtotaal EUR</td>");
             stringBuilder1.AppendLine("<td class=\"productsPropertyTitles\">Subtotaal Bonnen</td>");
             stringBuilder1.AppendLine("</tr>");
             foreach (TicketLine ticketLine in (Collection <TicketLine>)ticket.TicketLines)
             {
                 stringBuilder1.AppendLine("<tr>");
                 stringBuilder1.AppendLine("<td class =\"productsPropertyValues\">" + ticketLine.Product.Name + "</td>");
                 stringBuilder1.AppendLine("<td class =\"productsPropertyValues\">" + (object)ticketLine.Amount + "</td>");
                 StringBuilder stringBuilder2 = stringBuilder1;
                 double        num            = ticketLine.UnitPrice;
                 string        str2           = "<td class =\"productsPropertyValues\">" + num.ToString("C") + "</td>";
                 stringBuilder2.AppendLine(str2);
                 stringBuilder1.AppendLine("<td class =\"productsPropertyValues\">" + (object)ticketLine.UnitPriceCoins + "</td>");
                 StringBuilder stringBuilder3 = stringBuilder1;
                 num = ticketLine.LinePriceIncl;
                 string str3 = "<td class =\"productsPropertyValues\">" + num.ToString("C") + "</td>";
                 stringBuilder3.AppendLine(str3);
                 stringBuilder1.AppendLine("<td class =\"productsPropertyValues\">" + (object)ticketLine.LinePriceCoins + "</td>");
                 stringBuilder1.AppendLine("</tr>");
             }
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td colspan=\"6\">&nbsp;</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td colspan=\"6\" class=\"transactionsTitle\">Transacties</td>");
             stringBuilder1.AppendLine("</tr>");
             stringBuilder1.AppendLine("<tr>");
             stringBuilder1.AppendLine("<td class=\"transactionsPropertyTitles\">Datum</td>");
             stringBuilder1.AppendLine("<td class=\"transactionsPropertyTitles\">Bedrag</td>");
             stringBuilder1.AppendLine("<td class=\"transactionsPropertyTitles\">Betaalmethode</td>");
             stringBuilder1.AppendLine("<td class=\"transactionsPropertyTitles\">Afgehandeld door</td>");
             stringBuilder1.AppendLine("<td class=\"transactionsPropertyTitles\">Ontvangen</td>");
             stringBuilder1.AppendLine("<td class=\"transactionsPropertyTitles\">Wisselgeld</td>");
             stringBuilder1.AppendLine("</tr>");
             foreach (Transaction transaction in (Collection <Transaction>)ticket.Transactions)
             {
                 stringBuilder1.AppendLine("<tr>");
                 stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + (object)transaction.PayTime + "</td>");
                 stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + transaction.Amount.ToString("C") + "</td>");
                 stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + (object)transaction.PaymentMethodUsed + "</td>");
                 stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + transaction.PaymentHandledBy.Fullname + "</td>");
                 if (transaction.PaymentMethodUsed == Transaction.PaymentMethod.Cash)
                 {
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + ((CashTransaction)transaction).MoneyReceived.ToString("C") + "</td>");
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + ((CashTransaction)transaction).MoneyReturned.ToString("C") + "</td>");
                 }
                 else if (transaction.PaymentMethodUsed == Transaction.PaymentMethod.Coin)
                 {
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\">" + (object)((CoinTransaction)transaction).CoinsReceived + "</td>");
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\"></td>");
                 }
                 else if (transaction.PaymentMethodUsed == Transaction.PaymentMethod.Free)
                 {
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\" colspan=\"2\">" + ((FreeTransaction)transaction).Reason + "</td>");
                 }
                 else if (transaction.PaymentMethodUsed == Transaction.PaymentMethod.NFC)
                 {
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\"></td>");
                     stringBuilder1.AppendLine("<td class =\"transactionsPropertyValues\"></td>");
                 }
                 stringBuilder1.AppendLine("</tr>");
             }
             stringBuilder1.AppendLine("</table>");
             stringBuilder1.AppendLine("<br />");
         }
         string str4 = new Regex("\\[(\\w+)\\]", RegexOptions.Compiled).Replace(input, (MatchEvaluator)(match => new Dictionary <string, string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase)
         {
             {
                 "Title",
                 str1
             },
             {
                 "ImagePath",
                 Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\Templates\\Html"
             },
             {
                 "TicketOverviewTable",
                 stringBuilder1.ToString()
             }
         }[match.Groups[1].Value]));
         GlobalConfig config = new GlobalConfig();
         config.SetMargins(new Margins(70, 45, 70, 45)).SetPaperSize(PaperKind.A4);
         SimplePechkin simplePechkin = new SimplePechkin(config);
         ObjectConfig  objectConfig  = new ObjectConfig();
         objectConfig.SetLoadImages(true);
         objectConfig.SetPrintBackground(true);
         objectConfig.SetZoomFactor(1.1);
         objectConfig.SetAllowLocalContent(true);
         ObjectConfig doc  = objectConfig;
         string       html = str4;
         File.WriteAllBytes(this.FilePath, simplePechkin.Convert(doc, html));
         PdfReportService.logger.Info("Ticketoverview PDF created: " + this.FilePath);
     }
     catch (Exception ex)
     {
         PdfReportService.logger.Error("Could not create temporary PDF file:" + ex.Message);
     }
 }