示例#1
0
        virtual public void CreatePdfTest()
        {
            String fileName = "xmp_metadata.pdf";
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter    writer = PdfWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create));
            MemoryStream os     = new MemoryStream();
            XmpWriter    xmp    = new XmpWriter(os, XmpWriter.UTF16, 2000);

            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata");

            PdfProperties.SetKeywords(xmp.XmpMeta, "Hello World, XMP & Metadata, Metadata");
            PdfProperties.SetVersion(xmp.XmpMeta, "1.4");

            xmp.Close();

            writer.XmpMetadata = os.ToArray();
            // step 3
            document.Open();
            // step 4
            document.Add(new Paragraph("Hello World"));
            // step 5
            document.Close();

            CompareResults(fileName, fileName);
        }
示例#2
0
        virtual public void ManipulatePdf2Test()
        {
            String     fileName = "xmp_metadata_added2.pdf";
            PdfReader  reader   = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf");
            PdfStamper stamper  = new PdfStamper(reader, new FileStream(OUT_FOLDER + fileName, FileMode.Create));

            stamper.CreateXmpMetadata();
            XmpWriter xmp = stamper.XmpWriter;

            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata");

            PdfProperties.SetVersion(xmp.XmpMeta, "1.4");
            stamper.Close();
            reader.Close();

            CompareResults(fileName, fileName);
        }
示例#3
0
        virtual public void ManipulatePdf2Test()
        {
            String     fileName = "xmp_metadata_added2.pdf";
            PdfReader  reader   = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf");
            PdfStamper stamper  = new PdfAStamper(reader, new FileStream(OUT_FOLDER + fileName, FileMode.Create),
                                                  PdfAConformanceLevel.PDF_A_1A);
            MemoryStream os  = new MemoryStream();
            XmpWriter    xmp = new PdfAXmpWriter(os, reader.Info, PdfAConformanceLevel.PDF_A_1A, stamper.Writer);

            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata");

            PdfProperties.SetVersion(xmp.XmpMeta, "1.4");
            xmp.Close();
            stamper.XmpMetadata = os.ToArray();
            stamper.Close();
            reader.Close();
            CompareResults(fileName, fileName);
        }
示例#4
0
        virtual public void CreatePdfTest()
        {
            String fileName = "xmp_metadata.pdf";
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create),
                                                      PdfAConformanceLevel.PDF_A_2B);

            writer.SetTagged();
            writer.CreateXmpMetadata();
            XmpWriter xmp = writer.XmpWriter;

            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata");

            PdfProperties.SetKeywords(xmp.XmpMeta, "Hello World, XMP & Metadata, Metadata");
            PdfProperties.SetVersion(xmp.XmpMeta, "1.4");

            // step 3
            document.Open();
            document.AddLanguage("en_US");

            // step 4
            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);
        }