コード例 #1
0
ファイル: PdfA3.cs プロジェクト: anqin0725/i7ns-samples
        private void ManipulatePdf(String dest)
        {
            PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);
            PdfFont bold = PdfFontFactory.CreateFont(BOLD, PdfEncodings.IDENTITY_H);

            Stream fileStream =
                new FileStream("../../../resources/data/sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read);
            PdfADocument pdfDoc = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_3B,
                                                   new PdfOutputIntent("Custom", "",
                                                                       null, "sRGB IEC61966-2.1", fileStream));

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

            PdfDictionary parameters = new PdfDictionary();

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

            // Embeds file to the document
            PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDoc,
                                                                      File.ReadAllBytes(DATA),
                                                                      "united_states.csv", "united_states.csv",
                                                                      new PdfName("text/csv"), parameters, PdfName.Data);

            pdfDoc.AddAssociatedFile("united_states.csv", fileSpec);

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

            using (StreamReader streamReader = new StreamReader(DATA))
            {
                // Reads content of csv file
                String line = streamReader.ReadLine();

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

                streamReader.Close();
            }

            document.Add(table);
            document.Close();
        }