Exemple #1
0
        // Background worker
        public void PDFBackgroundWorker_DoWork_TextPDF(object sender, DoWorkEventArgs e)
        {
            int i = 0;
            int ii = 1;
            exportFilePath = string.Empty;

                if (JobType == PDFJobType.TextPDF)
                {
                    exportFilePath = directoryName + "\\" + FileNoExt + ".pdf";

                    while (System.IO.File.Exists(exportFilePath))
                    {
                        exportFilePath = directoryName + "\\" + FileNoExt + "_" + ii + ".pdf";
                        ii++;
                    }

                    using (FileStream fs = new FileStream(exportFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.B4);

                        // iTextSharp.text. Document doc = new Document(PageSize.A2);
                        // doc.SetMargins(100, 200, 0, 0);
                        //Document doc = new Document(PageSize.A5, 36, 72, 108, 180);
                        //Document doc = new Document(PageSize.A3.Rotate(),400,0,0,0);
                        //var doc = new Document(new iTextSharp.text.Rectangle(100f, 300f));
                        iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, fs);
                        iTextSharp.text.pdf.BaseFont bfTimes = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.TIMES_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, false);
                        // doc.SetPageSize(PageSize.A1);
                        // doc.SetMargins(76, 0, 0, 0);
                        doc.SetMarginMirroring(false);
                        iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 14, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.CYAN);

                        if (PDFBackgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                            PDFBackgroundWorker.ReportProgress(i);
                            return;
                        }

                        using (StreamReader read = new StreamReader(InputFilename))
                        {

                            string text = read.ReadToEnd();
                            // AddDocMetaData();
                            doc.AddTitle(GameTitle);
                            doc.AddSubject("");
                            doc.AddKeywords(GameTitle + ",  " + FileNoExt + " : by Hypermint,  ");
                            doc.AddCreator("HLM-Chk");
                            doc.AddAuthor(GameTitle);
                            doc.AddHeader(FileNoExt, GameTitle);
                            doc.Open();
                            iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
                            paragraph.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                            paragraph.Add(text);
                            doc.Add(paragraph);

                            //Paragraph paragraph = new Paragraph(text);
                            doc.Close();
                        }

                    }
                }
        }