Exemplo n.º 1
0
        private void ManipulatePdf(String dest)
        {
            font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);
            bold = PdfFontFactory.CreateFont(BOLD, PdfEncodings.IDENTITY_H);

            FileStream fileStream =
                new FileStream("../../../resources/data/sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read);

            PdfADocument pdfDoc = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1A,
                                                   new PdfOutputIntent("Custom", "",
                                                                       null, "sRGB IEC61966-2.1", fileStream));

            Document document = new Document(pdfDoc, PageSize.A4.Rotate());

            pdfDoc
            .SetTagged()
            .GetCatalog()
            .SetLang(new PdfString("en-us"));

            template = new PdfFormXObject(new Rectangle(795, 575, 30, 30));
            PdfCanvas canvas = new PdfCanvas(template, pdfDoc);

            total = new Image(template);
            total.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);

            // Creates a header for every page in the document
            pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, new HeaderHandler(this));

            PdfDictionary parameters = new PdfDictionary();

            parameters.Put(PdfName.ModDate, new PdfDate().GetPdfObject());

            Table table = new Table(UnitValue.CreatePercentArray(
                                        new float[] { 4, 1, 3, 4, 3, 3, 3, 3, 1 })).UseAllAvailableWidth();

            StreamReader br = new StreamReader(DATA);

            // Reads content of csv file
            String line = br.ReadLine();

            Process(table, line, bold, 10, true);

            while ((line = br.ReadLine()) != null)
            {
                Process(table, line, font, 10, false);
            }

            br.Close();

            document.Add(table);

            canvas.BeginText();
            canvas.SetFontAndSize(bold, 12);
            canvas.MoveText(795, 575);
            canvas.ShowText(pdfDoc.GetNumberOfPages().ToString());
            canvas.EndText();
            canvas.Stroke();

            document.Close();
        }