示例#1
0
        public void Verify_PrintPreferencesExample_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            var document = new Document();

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            writer.PdfVersion = PdfWriter.VERSION_1_5;
            writer.AddViewerPreference(PdfName.Printscaling, PdfName.None);
            writer.AddViewerPreference(PdfName.Numcopies, new PdfNumber(3));
            writer.AddViewerPreference(PdfName.Picktraybypdfsize, PdfBoolean.Pdftrue);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            document.Add(new Paragraph("Hello World!"));

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#2
0
        public byte[] imprimirRecibo(Pago pago)
        {
            _documento.SetPageSize(PageSize.A5.Rotate());
            _documento.SetMargins(28f, 28f, 20f, 20f);
            _fontStyle = FontFactory.GetFont("Tahoma", 8f, 1);
            PdfWriter docWriter = PdfWriter.GetInstance(_documento, _ms);

            _documento.Open();

            _documento.AddTitle("Recibo");
            _documento.AddAuthor("La Piazzolla");
            _documento.AddKeywords("Hola Mundo");

            string path = Path.Combine(_env.WebRootPath, "Images", "logoPiazzolla.jpg");
            Image  img  = Image.GetInstance(path);

            img.ScaleAbsoluteWidth(164.88f);
            img.ScaleAbsoluteHeight(37.16f);
            img.Alignment = Element.ALIGN_LEFT;
            //_documento.Add(img);

            _pdfPTable.WidthPercentage = 100;
            _pdfCell         = new PdfPCell(img);
            _pdfCell.Colspan = 1;
            _pdfCell.Border  = 1;
            _pdfPTable.AddCell(_pdfCell);
            _pdfPTable.CompleteRow();

            _documento.Add(_pdfPTable);
            _documento.Add(new Paragraph(pago.Monto.ToString()));

            _documento.Close();
            docWriter.Close();
            return(_ms.ToArray());
        }
示例#3
0
        public void Verify_PdfXPdfA_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            writer.PdfxConformance = PdfWriter.PDFX1A2001;
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var arialTtf = TestUtils.GetTahomaFontPath();
            var font     = FontFactory.GetFont(
                arialTtf, BaseFont.CP1252, BaseFont.EMBEDDED, Font.UNDEFINED,
                Font.UNDEFINED, new CmykColor(255, 255, 0, 0)
                );

            document.Add(new Paragraph("Hello World", font));

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#4
0
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            FileStream fs       = new FileStream(@"G:\PDFs\First PDF document.pdf", FileMode.Create);
            Document   document = new Document(PageSize.A7, 25, 25, 30, 30);

            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            document.AddAuthor("Micke Blomquist");
            document.AddCreator("Sample application using iTextSharp");
            document.AddKeywords("PDF tutorial education");
            document.AddSubject("Document subject - Describing the steps creating a PDF document");
            document.AddTitle("The document title - PDF creation using iTextSharp");

            // Open the document to enable you to write to the document
            document.Open();
            // Add a simple and wellknown phrase to the document in a flow layout manner
            document.Add(new Paragraph(".    Thushini Mini Super     ."));

            PdfContentByte cb   = writer.DirectContent;
            BaseFont       f_cb = BaseFont.CreateFont("c:\\windows\\fonts\\calibrib.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            /*
             * cb.SetTextMatrix(100, 100); // Left, Top
             *
             *
             *
             *
             *
             * int row = 1;
             * for (int y = 0; y != 70; y++)
             * {
             *  cb.SetTextMatrix(10, row);
             *  cb.ShowText("Y: " + row.ToString());
             *  row += 12; // The spacing between the rows is set to 12 "points"
             * }
             * int col = 35;
             * for (int x = 0; x != 22; x++)
             * {
             *  cb.SetTextMatrix(col, 829);
             *  cb.ShowText("X: " + col.ToString());
             *  col += 25; // The spacing between the columns is set to 25 "points"
             * }
             *
             *
             */
            cb.BeginText();
            cb.SetFontAndSize(f_cb, 9);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "This text is left aligned", 200, 800, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "This text is right aligned", 200, 788, 0);

            cb.ShowText("Hello World");
            cb.EndText();
            // Close the document
            document.Close();
            // Close the writer instance
            writer.Close();
            // Always close open filehandles explicity
            fs.Close();
        }
示例#5
0
        public void Verify_ImageSkew_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document(PageSize.Postcard.Rotate());

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            writer.CompressionLevel = 0;
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var img = Image.GetInstance(TestUtils.GetImagePath("loa.jpg"));

            // Add the image to the upper layer
            writer.DirectContent.AddImage(
                img,
                img.Width, 0, 0.35f * img.Height,
                0.65f * img.Height, 30, 30
                );

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
        public void Verify_TableAlignment_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            PdfPTable table = createFirstTable();

            table.WidthPercentage     = 50;
            table.HorizontalAlignment = Element.ALIGN_LEFT;
            document.Add(table);
            table.HorizontalAlignment = Element.ALIGN_CENTER;
            document.Add(table);
            table.HorizontalAlignment = Element.ALIGN_RIGHT;
            document.Add(table);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#7
0
        public void Verify_Hero1_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            Rectangle rect     = new Rectangle(-1192, -1685, 1192, 1685);
            var       document = new Document(rect);

            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            PdfContentByte content  = writer.DirectContent;
            PdfTemplate    template = createTemplate(content, rect, 4);

            content.AddTemplate(template, -1192, -1685);
            content.MoveTo(-595, 0);
            content.LineTo(595, 0);
            content.MoveTo(0, -842);
            content.LineTo(0, 842);
            content.Stroke();

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#8
0
        static void CallPDF()
        {
            FileStream fs       = new FileStream(@"D:\ab\fund.pdf", FileMode.Create);
            Document   document = new Document(PageSize.A4, 25, 25, 30, 30);
            PdfWriter  writer   = PdfWriter.GetInstance(document, fs);

            document.AddAuthor("Praseed Pai");
            document.AddCreator("iTextSharp PDF Library");
            document.AddTitle("PDF Demo");
            document.Open();
            PdfPTable table = new PdfPTable(2);
            PdfPCell  cell  = new PdfPCell(new Phrase("A Header which spans 3"));

            cell.Colspan             = 3;
            cell.HorizontalAlignment = 1;
            table.AddCell(cell);
            table.AddCell("Col 1 Row 1");
            table.AddCell("Col 2 Row 1");
            table.AddCell("Col 3 Row 1");
            table.AddCell("Col 1 Row 2");
            table.AddCell("Col 2 Row 2");
            table.AddCell("Col 3 Row 2");
            document.Add(table);
            document.Close();
            writer.Close();
            fs.Close();
        }
示例#9
0
文件: PdfExporter.cs 项目: lulzzz/cbs
        public bool WriteReports(IEnumerable <CaseReportForListing> reports, string[] fields, Stream stream)
        {
            var nowString = DateTimeOffset.Now.ToString("yyyy-MMMM-dd");
            var doc       = new Document(PageSize.A4, 0f, 0f, 30f, 10f);

            using (var writer = PdfWriter.GetInstance(doc, stream))
            {
                writer.CloseStream = false;

                doc.AddAuthor("Cbs - Volunteer Reporting");
                doc.AddCreator("Cbs - Volunteer Reporting");
                doc.AddSubject("Case Reports " + nowString);
                doc.AddTitle("Case Reports " + nowString);

                doc.Open();
                doc.NewPage();
                if (reports.Any())
                {
                    AddCaseReportsToPdf(reports, doc, new string[] { });
                }
                else
                {
                    doc.Add(new Paragraph("No case reports were retrieved from the database"));
                }

                doc.Close();

                writer.Flush();
            }

            return(true);
        }
        public void Verify_HelloWorldColumn_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            // we set the compression to 0 so that we can read the PDF syntax
            writer.CompressionLevel = 0;
            // writes something to the direct content using a convenience method
            var hello  = new Phrase("HelloWorldColumn");
            var canvas = writer.DirectContentUnder;

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT,
                                       hello, 36, 788, 0
                                       );

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
        public void Verify_HelloWorldDirect_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var canvas = writer.DirectContentUnder;

            writer.CompressionLevel = 0;
            canvas.SaveState();                               // q
            canvas.BeginText();                               // BT
            canvas.MoveText(36, 788);                         // 36 788 Td
            canvas.SetFontAndSize(BaseFont.CreateFont(), 12); // /F1 12 Tf
            canvas.ShowText("HelloWorldDirect");              // (Hello World)Tj
            canvas.EndText();                                 // ET
            canvas.RestoreState();                            // Q

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
        public void Verify_HelloWorldNarrow_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            // Using a custom page size
            var pagesize = new Rectangle(216f, 720f);
            var document = new Document(pagesize, 36f, 72f, 108f, 180f);

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            document.Add(new Paragraph(
                             "Hello World! Hello People! " +
                             "Hello Sky! Hello Sun! Hello Moon! Hello Stars!")
                         );

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
        public void Verify_HelloWorldMaximum_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            // Specifying the page size
            var document = new Document(new Rectangle(14400, 14400));

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            // changes the user unit
            writer.Userunit = 75000f;
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            document.Add(new Paragraph("HelloWorldMaximum"));

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#14
0
    /// <summary>
    /// 读取或创建Pdf文档并打开写入文件流
    /// </summary>
    /// <param name="fileName"></param>
    /// <param name="folderPath"></param>
    public Document GetOrCreatePDF(string fileName, string folderPath)
    {
        string     filePath = folderPath + fileName;
        FileStream fs       = null;

        if (!File.Exists(filePath))
        {
            fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
        }
        else
        {
            fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.None);
        }
        //获取A4纸尺寸
        Rectangle rec = new Rectangle(PageSize.A4);
        Document  doc = new Document(rec);
        //创建一个 iTextSharp.text.pdf.PdfWriter 对象: 它有助于把Document书写到特定的FileStream:
        PdfWriter writer = PdfWriter.GetInstance(doc, fs);

        doc.AddTitle(fileName.Remove(fileName.LastIndexOf('.')));
        doc.AddSubject(fileName.Remove(fileName.LastIndexOf('.')));
        doc.AddKeywords("Metadata, iTextSharp 5.4.4, Chapter 1, Tutorial");
        doc.AddCreator("MCS");
        doc.AddAuthor("Chingy");
        doc.AddHeader("Nothing", "No Header");
        //打开 Document:
        doc.Open();
        ////关闭 Document:
        //doc.Close();
        return(doc);
    }
示例#15
0
        /// <summary>
        /// 创建一个包含指定文本的pdf文件,并设置页面大小、作者、标题等相关信息设置
        /// </summary>
        /// <param name="pdfFilePath">pdf文件保存路径</param>
        /// <param name="content">pdf文本内容</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="title">标题</param>
        /// <param name="subject">主题</param>
        /// <param name="keywords">关键字</param>
        /// <param name="creator">创建者</param>
        /// <param name="author">作者</param>
        public static void CreatePdfSetInfo(string pdfFilePath, string content, Rectangle pageSize = null,
                                            string title = null, string subject = null, string keywords = null, string creator = null, string author = null)
        {
            //设置页面大小
            if (pageSize == null)
            {
                pageSize = new Rectangle(216f, 716f);
            }
            pageSize.BackgroundColor = new BaseColor(0xFF, 0xFF, 0xDE);

            //设置边界
            Document document = new Document(pageSize, 36f, 72f, 108f, 180f);

            PdfWriter.GetInstance(document, new FileStream(pdfFilePath, FileMode.Create));

            // 添加文档信息
            document.AddTitle(title);
            document.AddSubject(subject);
            document.AddKeywords(keywords);
            document.AddCreator(creator);
            document.AddAuthor(author);
            document.Open();

            // 添加文档内容
            document.Add(new Paragraph(content));
            document.Close();
        }
示例#16
0
        /// <summary>
        /// Создает файл pdf с надписью 'HelloWorld'
        /// http://www.c-sharpcorner.com/UploadFile/f2e803/basic-pdf-creation-using-itextsharp-part-i/
        /// </summary>
        /// <param name="args"></param>
        public static void HelloWorld(string fileName)
        {
            System.IO.FileStream fs = new FileStream(fileName, FileMode.Create);

            // Create an instance of the document class which represents the PDF document itself.
            Document document = new Document(PageSize.A4, 25, 25, 30, 30);
            // Create an instance to the PDF file by creating an instance of the PDF
            // Writer class using the document and the filestrem in the constructor.
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            // Add meta information to the document
            document.AddAuthor("Document author");
            document.AddCreator("Sample application");
            document.AddKeywords("PDF keywords");
            document.AddSubject("Document subject - Describing the steps creating a PDF document");
            document.AddTitle("The document title");

            // Open the document to enable you to write to the document
            document.Open();
            // Add a simple and wellknown phrase to the document in a flow layout manner
            document.Add(new Paragraph("Hello World!"));
            // Close the document
            document.Close();
            // Close the writer instance
            writer.Close();
            // Always close open filehandles explicity
            fs.Close();
        }
示例#17
0
        private static byte[] createSamplePdfFile()
        {
            using (var stream = new MemoryStream())
            {
                // step 1
                var document = new Document(PageSize.A4);

                // step 2
                var writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.AddAuthor(TestUtils.Author);
                document.Open();
                // step 4
                document.Add(new Paragraph("This page will NOT be followed by a blank page!"));
                document.NewPage();
                // we don't add anything to this page: newPage() will be ignored
                document.NewPage();
                document.Add(new Paragraph("This page will be followed by a blank page!"));
                document.NewPage();
                writer.PageEmpty = false;
                document.NewPage();
                document.Add(new Paragraph("The previous page was a blank page!"));

                document.Close();

                return(stream.ToArray());
            }
        }
示例#18
0
        virtual public void CreatePdfAutomaticTest()
        {
            String fileName = "xmp_metadata_automatic.pdf";
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create),
                                                      PdfAConformanceLevel.PDF_A_1B);

            document.AddTitle("Hello World example");
            document.AddSubject("This example shows how to add metadata & XMP");
            document.AddKeywords("Metadata, iText, step 3");
            document.AddCreator("My program using 'iText'");
            document.AddAuthor("Bruno Lowagie & Paulo Soares");
            writer.CreateXmpMetadata();
            // step 3
            document.Open();
            Font font = FontFactory.GetFont("../../resources/text/pdfa/FreeMonoBold.ttf", BaseFont.WINANSI,
                                            BaseFont.EMBEDDED, 12);

            document.Add(new Paragraph("Hello World", font));

            FileStream iccStream = new FileStream("../../resources/text/pdfa/sRGB Color Space Profile.icm",
                                                  FileMode.Open);
            ICC_Profile icc = ICC_Profile.GetInstance(iccStream);

            iccStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
            // step 5
            document.Close();
            CompareResults(fileName, fileName);
        }
        public void Verify_ColumnWidths_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            PdfPTable table = createTable1();

            document.Add(table);
            table = createTable2();
            table.SpacingBefore = 5;
            table.SpacingAfter  = 5;
            document.Add(table);
            table = createTable3();
            document.Add(table);
            table = createTable4();
            table.SpacingBefore = 5;
            table.SpacingAfter  = 5;
            document.Add(table);
            table = createTable5();
            document.Add(table);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
        public virtual void MontaCorpoDados()
        {
            if (!Paisagem)
            {
                doc = new Document(PageSize.A4, 20, 10, 80, 40);
            }
            else
            {
                doc = new Document(PageSize.A4.Rotate(), 20, 10, 80, 80);
            }
            output = new MemoryStream();
            writer = PdfWriter.GetInstance(doc, output);

            doc.AddAuthor("TNE - Treta Never Ends");
            doc.AddTitle(PageTitle);
            doc.AddSubject(PageTitle);

            var footer = new MSPDFFooter();

            footer.PageTitle               = PageTitle;
            footer.PageSubTitle            = PageSubTitle;
            footer.BasePath                = BasePath;
            footer.ImprimirCabecalhoPadrao = ImprimirCabecalhoPadrao;
            footer.ImprimirRodapePadrao    = ImprimirRodapePadrao;

            writer.PageEvent = footer;

            doc.Open();
            return;
        }
示例#21
0
        public void Verify_NewPage_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            document.Add(new Paragraph("This page will NOT be followed by a blank page!"));
            document.NewPage();
            // we don't add anything to this page: newPage() will be ignored
            document.NewPage();
            document.Add(new Paragraph("This page will be followed by a blank page!"));
            document.NewPage();
            writer.PageEmpty = false;
            document.NewPage();
            document.Add(new Paragraph("The previous page was a blank page!"));

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#22
0
        private void addMetadata()
        {
#if NET40
            var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
#else
            var version = typeof(MergePdfDocuments).GetTypeInfo().Assembly.GetName().Version.ToString();
#endif

            if (DocumentMetadata != null)
            {
                _document.AddTitle(DocumentMetadata.Title);
                _document.AddSubject(DocumentMetadata.Subject);
                _document.AddAuthor(DocumentMetadata.Author);
                _document.AddCreator(DocumentMetadata.Application + ", Using PdfRpt V" + version);
                _document.AddKeywords(DocumentMetadata.Keywords);
            }
            else
            {
                _document.AddCreator("PdfRpt V" + version);
            }

            _writer.CreateXmpMetadata();
            _writer.SetPdfVersion(PdfWriter.PdfVersion15);
            _writer.RgbTransparencyBlending = true;
        }
示例#23
0
        public void Verify_ImageInline_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document(PageSize.Postcard, 30, 30, 30, 30);

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            writer.CompressionLevel = 0;
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var img = Image.GetInstance(TestUtils.GetImagePath("loa.jpg"));

            img.SetAbsolutePosition(
                (PageSize.Postcard.Width - img.ScaledWidth) / 2,
                (PageSize.Postcard.Height - img.ScaledHeight) / 2
                );
            writer.DirectContent.AddImage(img, true);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#24
0
        public async Task <byte[]> Reports()
        {
            _document = new Document(PageSize.A5);
            _document.SetMargins(5f, 5f, 20f, 5f);
            _pdfPTable.HorizontalAlignment = Element.ALIGN_LEFT;
            _fontStyle = FontFactory.GetFont("Tahoma", 8f, 1);
            PdfWriter docWriter = PdfWriter.GetInstance(_document, _memoryStream);

            _document.Open();
            float [] sizes = new float[_maxColumn];
            for (int i = 0; i < _maxColumn; i++)
            {
                sizes[i] = 100;
            }
            _pdfPTable.SetWidths(sizes);
            ReportHeader();
            EmptyRow(2);
            ReportBody();
            _pdfPTable.HeaderRows = 2;
            _document.AddAuthor("Riad");
            _document.AddTitle("Hello World");
            _document.Add(_pdfPTable);
            _document.Close();
            return(_memoryStream.ToArray());
        }
示例#25
0
        public bool TryCreatePdf(string nameBank)
        {
            try
            {
                using (FileStream file = new FileStream(String.Format(path, nameBank), FileMode.Create))
                {
                    Document  document = new Document(PageSize.A7);
                    PdfWriter writer   = PdfWriter.GetInstance(document, file);

                    /// Create metadate pdf file
                    document.AddAuthor("");
                    document.AddLanguage("pl");
                    document.AddSubject("Payment transaction");
                    document.AddTitle("Transaction");
                    /// Create text in pdf file
                    document.Open();
                    document.Add(new Paragraph(_przelew + "\n"));
                    document.Add(new Paragraph(String.Format("Bank {0}: zaprasza\n", nameBank)));
                    document.Add(new Paragraph(DateTime.Now.ToString()));
                    document.Close();
                    writer.Close();
                    file.Close();
                    return(true);
                }
            }
            catch (SystemException ex)
            {
                return(false);
            }
        }
示例#26
0
        virtual public void CreatePdfAutomaticTest() {
            String fileName = "xmp_metadata_automatic.pdf";
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create),
                                                      PdfAConformanceLevel.PDF_A_1B);
            document.AddTitle("Hello World example");
            document.AddSubject("This example shows how to add metadata & XMP");
            document.AddKeywords("Metadata, iText, step 3");
            document.AddCreator("My program using 'iText'");
            document.AddAuthor("Bruno Lowagie & Paulo Soares");
            writer.CreateXmpMetadata();
            // step 3
            document.Open();
            Font font = FontFactory.GetFont("../../resources/text/pdfa/FreeMonoBold.ttf", BaseFont.WINANSI,
                                            BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccStream = new FileStream("../../resources/text/pdfa/sRGB Color Space Profile.icm",
                                                 FileMode.Open);
            ICC_Profile icc = ICC_Profile.GetInstance(iccStream);
            iccStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
            // step 5
            document.Close();
            CompareResults(fileName, fileName);
        }
示例#27
0
        public void Verify_TableHeight_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var table = createFirstTable();

            document.Add(new Paragraph(string.Format(
                                           "Table height before document.Add(): {0}",
                                           table.TotalHeight)
                                       ));
            document.Add(new Paragraph(
                             string.Format("Height of the first row: {0}",
                                           table.GetRowHeight(0))
                             ));
            document.Add(table);
            document.Add(new Paragraph(string.Format(
                                           "Table height after document.Add(): {0}",
                                           table.TotalHeight
                                           )));
            document.Add(new Paragraph(string.Format(
                                           "Height of the first row: {0}",
                                           table.GetRowHeight(0)
                                           )));
            table = createFirstTable();
            document.Add(new Paragraph(string.Format(
                                           "Table height before setTotalWidth(): {0}",
                                           table.TotalHeight
                                           )));
            document.Add(new Paragraph(string.Format(
                                           "Height of the first row: {0}",
                                           table.GetRowHeight(0)
                                           )));
            table.TotalWidth  = 50;
            table.LockedWidth = true;
            document.Add(new Paragraph(string.Format(
                                           "Table height after setTotalWidth(): {0}",
                                           table.TotalHeight
                                           )));
            document.Add(new Paragraph(string.Format(
                                           "Height of the first row: {0}",
                                           table.GetRowHeight(0)
                                           )));
            document.Add(table);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#28
0
        public void Verify_CellHeights_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var table = new PdfPTable(2);
            // a long phrase
            var p = new Phrase(
                "Dr. iText or: How I Learned to Stop Worrying and Love PDF."
                );
            var cell = new PdfPCell(p);

            // the prhase is wrapped
            table.AddCell("wrap");
            cell.NoWrap = false;
            table.AddCell(cell);
            // the phrase isn't wrapped
            table.AddCell("no wrap");
            cell.NoWrap = true;
            table.AddCell(cell);
            // a long phrase with newlines
            p = new Phrase(
                "Dr. iText or:\nHow I Learned to Stop Worrying\nand Love PDF.");
            cell = new PdfPCell(p);
            // the phrase fits the fixed height
            table.AddCell("fixed height (more than sufficient)");
            cell.FixedHeight = 72f;
            table.AddCell(cell);
            // the phrase doesn't fit the fixed height
            table.AddCell("fixed height (not sufficient)");
            cell.FixedHeight = 36f;
            table.AddCell(cell);
            // The minimum height is exceeded
            table.AddCell("minimum height");
            cell = new PdfPCell(new Phrase("Dr. iText"))
            {
                MinimumHeight = 36f
            };
            table.AddCell(cell);
            // The last row is extended
            table.ExtendLastRow = true;
            table.AddCell("extend last row");
            table.AddCell(cell);
            document.Add(table);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
示例#29
0
        private byte[] ReportPDF()
        {
            var memoryStream = new MemoryStream();

            // Marge in centimeter, then I convert with .ToDpi()
            float margeLeft   = 1.5f;
            float margeRight  = 1.5f;
            float margeTop    = 1.0f;
            float margeBottom = 1.0f;

            Document pdf = new Document(
                PageSize.A4,
                margeLeft.ToDpi(),
                margeRight.ToDpi(),
                margeTop.ToDpi(),
                margeBottom.ToDpi()
                );

            pdf.AddTitle("Blazor-PDF");
            pdf.AddAuthor("Ozzvy");
            pdf.AddCreationDate();
            pdf.AddKeywords("blazor");
            pdf.AddSubject("Create a pdf file with iText");

            PdfWriter writer = PdfWriter.GetInstance(pdf, memoryStream);

            //HEADER and FOOTER
            var          fontStyle   = FontFactory.GetFont("Arial", 16, BaseColor.White);
            var          labelHeader = new Chunk("User Info", fontStyle);
            HeaderFooter header      = new HeaderFooter(new Phrase(labelHeader), false)
            {
                BackgroundColor = new BaseColor(48, 79, 254),
                Alignment       = Element.ALIGN_CENTER,
                Border          = Rectangle.NO_BORDER
            };

            //header.Border = Rectangle.NO_BORDER;
            pdf.Header = header;

            var          labelFooter = new Chunk("Page", fontStyle);
            HeaderFooter footer      = new HeaderFooter(new Phrase(labelFooter), true)
            {
                Border    = Rectangle.NO_BORDER,
                Alignment = Element.ALIGN_RIGHT
            };

            pdf.Footer = footer;

            pdf.Open();

            if (_pagenumber == 1)
            {
                UserPrint.PageText(pdf, _user);
            }

            pdf.Close();

            return(memoryStream.ToArray());
        }
 private static void Author(Document pdfFile, Enum authorName, string title)
 {
     pdfFile.AddCreator(authorName.ToString()); //Oluşturan kişinin isminin eklenmesi
     pdfFile.AddCreationDate();                 //Oluşturulma tarihinin eklenmesi
     pdfFile.AddAuthor(authorName.ToString());  //Yazarın isiminin eklenmesi
     pdfFile.AddHeader("Başlık", "Sürücü Kursu Otomasyonu");
     pdfFile.AddTitle(title);                   //Başlık ve title eklenmesi
 }
示例#31
0
 void SetProperty()
 {
     doc.AddTitle(property.Title);
     doc.AddAuthor(property.Author);
     doc.AddCreator(property.Creator); // Application
     doc.AddSubject(property.Subject); // Subtitle
     doc.AddKeywords(property.Keywords);
 }
示例#32
0
 virtual public void CreatePdfAutomaticTest() {
     String fileName = "xmp_metadata_automatic.pdf";
     // step 1
     Document document = new Document();
     // step 2
     PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create));
     document.AddTitle("Hello World example");
     document.AddSubject("This example shows how to add metadata & XMP");
     document.AddKeywords("Metadata, iText, step 3");
     document.AddCreator("My program using 'iText'");
     document.AddAuthor("Bruno Lowagie & Paulo Soares");
     writer.CreateXmpMetadata();
     // step 3
     document.Open();
     // step 4
     document.Add(new Paragraph("Hello World"));
     // step 5
     document.Close();
     CompareResults(fileName, fileName);
 }