virtual public void DeprecatedLogicTest()
        {
            String fileName = "xmp_metadata_deprecated.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);
            XmpSchema    dc      = new DublinCoreSchema();
            XmpArray     subject = new XmpArray(XmpArray.UNORDERED);

            subject.Add("Hello World");
            subject.Add("XMP & Metadata");
            subject.Add("Metadata");
            dc.SetProperty(DublinCoreSchema.SUBJECT, subject);
            xmp.AddRdfDescription(dc.Xmlns, dc.ToString());
            PdfSchema pdf = new PdfSchema();

            pdf.AddKeywords("Hello World, XMP & Metadata, Metadata");
            pdf.AddVersion("1.4");
            xmp.AddRdfDescription(pdf);
            xmp.Close();
            writer.XmpMetadata = os.ToArray();
            // step 3
            document.Open();
            // step 4
            document.Add(new Paragraph("Hello World"));
            // step 5
            document.Close();
            CompareResults("xmp_metadata.pdf", fileName);
        }
Beispiel #2
0
        virtual public void DeprecatedLogicTest()
        {
            String fileName = "xmp_metadata_deprecated.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);
            MemoryStream os      = new MemoryStream();
            XmpWriter    xmp     = new PdfAXmpWriter(os, PdfAConformanceLevel.PDF_A_2B, writer);
            XmpSchema    dc      = new DublinCoreSchema();
            XmpArray     subject = new XmpArray(XmpArray.UNORDERED);

            subject.Add("Hello World");
            subject.Add("XMP & Metadata");
            subject.Add("Metadata");
            dc.SetProperty(DublinCoreSchema.SUBJECT, subject);
            xmp.AddRdfDescription(dc.Xmlns, dc.ToString());
            PdfSchema pdf = new PdfSchema();

            pdf.AddKeywords("Hello World, XMP & Metadata, Metadata");
            pdf.AddVersion("1.4");
            xmp.AddRdfDescription(pdf);
            xmp.Close();
            writer.XmpMetadata = os.ToArray();
            // 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("xmp_metadata_deprecated.pdf", fileName);
        }
// ---------------------------------------------------------------------------
/**
 * Creates a PDF document.
 */
    public byte[] CreatePdf() {
      using (MemoryStream ms = new MemoryStream()) {
        // step 1
        using (Document document = new Document()) {
        // step 2
          PdfWriter writer = PdfWriter.GetInstance(document, ms);
          using (MemoryStream msXmp = new MemoryStream()) {
            XmpWriter xmp = new XmpWriter(msXmp);
            XmpSchema dc = new DublinCoreSchema();
            XmpArray subject = new XmpArray(XmpArray.UNORDERED);
            subject.Add("Hello World");
            subject.Add("XMP & Metadata");
            subject.Add("Metadata");
            dc.SetProperty(DublinCoreSchema.SUBJECT, subject);
            xmp.AddRdfDescription(dc);
            PdfSchema pdf = new PdfSchema();
/*
 *  iTextSharp uses Item property instead of Java setProperty() method
 * 
 *      pdf.SetProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata");
 *      pdf.SetProperty(PdfSchema.VERSION, "1.4");
 */
            pdf[PdfSchema.KEYWORDS] = "Hello World, XMP, Metadata";
            pdf[PdfSchema.VERSION] = "1.4";
            xmp.AddRdfDescription(pdf);
            xmp.Close();
            writer.XmpMetadata = ms.ToArray();
          }
          // step 3
          document.Open();
          // step 4
          document.Add(new Paragraph("Hello World"));
        }
        return ms.ToArray();
      }
    }
Beispiel #4
0
 /**
  * @param os
  * @param info
  * @throws IOException
  */
 public XmpWriter(Stream os, IDictionary <string, string> info) : this(os) {
     if (info != null)
     {
         DublinCoreSchema dc    = new DublinCoreSchema();
         PdfSchema        p     = new PdfSchema();
         XmpBasicSchema   basic = new XmpBasicSchema();
         String           value;
         foreach (KeyValuePair <string, string> entry in info)
         {
             String key = entry.Key;
             value = entry.Value;
             if (value == null)
             {
                 continue;
             }
             if ("Title".Equals(key))
             {
                 dc.AddTitle(value);
             }
             if ("Author".Equals(key))
             {
                 dc.AddAuthor(value);
             }
             if ("Subject".Equals(key))
             {
                 dc.AddSubject(value);
                 dc.AddDescription(value);
             }
             if ("Keywords".Equals(key))
             {
                 p.AddKeywords(value);
             }
             if ("Creator".Equals(key))
             {
                 basic.AddCreatorTool(value);
             }
             if ("Producer".Equals(key))
             {
                 p.AddProducer(value);
             }
             if ("CreationDate".Equals(key))
             {
                 basic.AddCreateDate(PdfDate.GetW3CDate(value));
             }
             if ("ModDate".Equals(key))
             {
                 basic.AddModDate(PdfDate.GetW3CDate(value));
             }
         }
         if (dc.Count > 0)
         {
             AddRdfDescription(dc);
         }
         if (p.Count > 0)
         {
             AddRdfDescription(p);
         }
         if (basic.Count > 0)
         {
             AddRdfDescription(basic);
         }
     }
 }
Beispiel #5
0
 /**
  * @param os
  * @param info
  * @throws IOException
  */
 public XmpWriter(Stream os, PdfDictionary info, int PdfXConformance) : this(os) {
     if (info != null)
     {
         DublinCoreSchema dc    = new DublinCoreSchema();
         PdfSchema        p     = new PdfSchema();
         XmpBasicSchema   basic = new XmpBasicSchema();
         PdfObject        obj;
         foreach (PdfName key in info.Keys)
         {
             obj = info.Get(key);
             if (obj == null)
             {
                 continue;
             }
             if (PdfName.TITLE.Equals(key))
             {
                 dc.AddTitle(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.AUTHOR.Equals(key))
             {
                 dc.AddAuthor(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.SUBJECT.Equals(key))
             {
                 dc.AddSubject(((PdfString)obj).ToUnicodeString());
                 dc.AddDescription(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.KEYWORDS.Equals(key))
             {
                 p.AddKeywords(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.CREATOR.Equals(key))
             {
                 basic.AddCreatorTool(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.PRODUCER.Equals(key))
             {
                 p.AddProducer(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.CREATIONDATE.Equals(key))
             {
                 basic.AddCreateDate(((PdfDate)obj).GetW3CDate());
             }
             if (PdfName.MODDATE.Equals(key))
             {
                 basic.AddModDate(((PdfDate)obj).GetW3CDate());
             }
         }
         if (dc.Count > 0)
         {
             AddRdfDescription(dc);
         }
         if (p.Count > 0)
         {
             AddRdfDescription(p);
         }
         if (basic.Count > 0)
         {
             AddRdfDescription(basic);
         }
         if (PdfXConformance == PdfWriter.PDFA1A || PdfXConformance == PdfWriter.PDFA1B)
         {
             PdfA1Schema a1 = new PdfA1Schema();
             if (PdfXConformance == PdfWriter.PDFA1A)
             {
                 a1.AddConformance("A");
             }
             else
             {
                 a1.AddConformance("B");
             }
             AddRdfDescription(a1);
         }
     }
 }
Beispiel #6
0
 virtual public void DeprecatedLogicTest() {
     String fileName = "xmp_metadata_deprecated.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);
     XmpSchema dc = new DublinCoreSchema();
     XmpArray subject = new XmpArray(XmpArray.UNORDERED);
     subject.Add("Hello World");
     subject.Add("XMP & Metadata");
     subject.Add("Metadata");
     dc.SetProperty(DublinCoreSchema.SUBJECT, subject);
     xmp.AddRdfDescription(dc.Xmlns, dc.ToString());
     PdfSchema pdf = new PdfSchema();
     pdf.AddKeywords("Hello World, XMP & Metadata, Metadata");
     pdf.AddVersion("1.4");
     xmp.AddRdfDescription(pdf);
     xmp.Close();
     writer.XmpMetadata = os.ToArray();
     // step 3
     document.Open();
     // step 4
     document.Add(new Paragraph("Hello World"));
     // step 5
     document.Close();
     CompareResults("xmp_metadata.pdf", fileName);
 }
Beispiel #7
0
 /**
 * @param os
 * @param info
 * @throws IOException
 */
 public XmpWriter(Stream os, IDictionary<string,string> info) : this(os) {
     if (info != null) {
         DublinCoreSchema dc = new DublinCoreSchema();
         PdfSchema p = new PdfSchema();
         XmpBasicSchema basic = new XmpBasicSchema();
         String value;
         foreach (KeyValuePair<string,string> entry in info) {
             String key = entry.Key;
             value = entry.Value;
             if (value == null)
                 continue;
             if ("Title".Equals(key)) {
                 dc.AddTitle(value);
             }
             if ("Author".Equals(key)) {
                 dc.AddAuthor(value);
             }
             if ("Subject".Equals(key)) {
                 dc.AddSubject(value);
                 dc.AddDescription(value);
             }
             if ("Keywords".Equals(key)) {
                 p.AddKeywords(value);
             }
             if ("Creator".Equals(key)) {
                 basic.AddCreatorTool(value);
             }
             if ("Producer".Equals(key)) {
                 p.AddProducer(value);
             }
             if ("CreationDate".Equals(key)) {
                 basic.AddCreateDate(PdfDate.GetW3CDate(value));
             }
             if ("ModDate".Equals(key)) {
                 basic.AddModDate(PdfDate.GetW3CDate(value));
             }
         }
         if (dc.Count > 0) AddRdfDescription(dc);
         if (p.Count > 0) AddRdfDescription(p);
         if (basic.Count > 0) AddRdfDescription(basic);
     }
 }
Beispiel #8
0
 /**
 * @param os
 * @param info
 * @throws IOException
 */
 public XmpWriter(Stream os, PdfDictionary info, int PdfXConformance) : this(os) {
     if (info != null) {
         DublinCoreSchema dc = new DublinCoreSchema();
         PdfSchema p = new PdfSchema();
         XmpBasicSchema basic = new XmpBasicSchema();
         PdfObject obj;
         String value;
         foreach (PdfName key in info.Keys) {
             obj = info.Get(key);
             if (obj == null)
                 continue;
             value = ((PdfString)obj).ToUnicodeString();
             if (PdfName.TITLE.Equals(key)) {
                 dc.AddTitle(value);
             }
             if (PdfName.AUTHOR.Equals(key)) {
                 dc.AddAuthor(value);
             }
             if (PdfName.SUBJECT.Equals(key)) {
                 dc.AddSubject(value);
                 dc.AddDescription(value);
             }
             if (PdfName.KEYWORDS.Equals(key)) {
                 p.AddKeywords(value);
             }
             if (PdfName.CREATOR.Equals(key)) {
                 basic.AddCreatorTool(value);
             }
             if (PdfName.PRODUCER.Equals(key)) {
                 p.AddProducer(value);
             }
             if (PdfName.CREATIONDATE.Equals(key)) {
                 basic.AddCreateDate(PdfDate.GetW3CDate(obj.ToString()));
             }
             if (PdfName.MODDATE.Equals(key)) {
                 basic.AddModDate(PdfDate.GetW3CDate(obj.ToString()));
             }
         }
         if (dc.Count > 0) AddRdfDescription(dc);
         if (p.Count > 0) AddRdfDescription(p);
         if (basic.Count > 0) AddRdfDescription(basic);
         if (PdfXConformance == PdfWriter.PDFA1A || PdfXConformance == PdfWriter.PDFA1B) {
             PdfA1Schema a1 = new PdfA1Schema();
             if (PdfXConformance == PdfWriter.PDFA1A)
                 a1.AddConformance("A");
             else
                 a1.AddConformance("B");
             AddRdfDescription(a1);
         }
     }
 }
 /**
  * @param os
  * @param info
  * @throws IOException
  */
 public XmpWriter(Stream os, PdfDictionary info)
     : this(os)
 {
     if (info != null)
     {
         DublinCoreSchema dc    = new DublinCoreSchema();
         PdfSchema        p     = new PdfSchema();
         XmpBasicSchema   basic = new XmpBasicSchema();
         PdfObject        obj;
         String           value;
         foreach (PdfName key in info.Keys)
         {
             obj = info.Get(key);
             if (obj == null)
             {
                 continue;
             }
             if (!obj.IsString())
             {
                 continue;
             }
             value = ((PdfString)obj).ToUnicodeString();
             if (PdfName.TITLE.Equals(key))
             {
                 dc.AddTitle(value);
             }
             if (PdfName.AUTHOR.Equals(key))
             {
                 dc.AddAuthor(value);
             }
             if (PdfName.SUBJECT.Equals(key))
             {
                 dc.AddSubject(value);
                 dc.AddDescription(value);
             }
             if (PdfName.KEYWORDS.Equals(key))
             {
                 p.AddKeywords(value);
             }
             if (PdfName.CREATOR.Equals(key))
             {
                 basic.AddCreatorTool(value);
             }
             if (PdfName.PRODUCER.Equals(key))
             {
                 p.AddProducer(value);
             }
             if (PdfName.CREATIONDATE.Equals(key))
             {
                 basic.AddCreateDate(PdfDate.GetW3CDate(obj.ToString()));
             }
             if (PdfName.MODDATE.Equals(key))
             {
                 basic.AddModDate(PdfDate.GetW3CDate(obj.ToString()));
             }
         }
         if (dc.Count > 0)
         {
             AddRdfDescription(dc);
         }
         if (p.Count > 0)
         {
             AddRdfDescription(p);
         }
         if (basic.Count > 0)
         {
             AddRdfDescription(basic);
         }
     }
 }
        virtual public void DeprecatedLogicTest() {
            String fileName = "xmp_metadata_deprecated.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);
            MemoryStream os = new MemoryStream();
            XmpWriter xmp = new PdfAXmpWriter(os, PdfAConformanceLevel.PDF_A_2B, writer);
            XmpSchema dc = new DublinCoreSchema();
            XmpArray subject = new XmpArray(XmpArray.UNORDERED);
            subject.Add("Hello World");
            subject.Add("XMP & Metadata");
            subject.Add("Metadata");
            dc.SetProperty(DublinCoreSchema.SUBJECT, subject);
            xmp.AddRdfDescription(dc.Xmlns, dc.ToString());
            PdfSchema pdf = new PdfSchema();
            pdf.AddKeywords("Hello World, XMP & Metadata, Metadata");
            pdf.AddVersion("1.4");
            xmp.AddRdfDescription(pdf);
            xmp.Close();
            writer.XmpMetadata = os.ToArray();
            // 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("xmp_metadata_deprecated.pdf", fileName);
        }
Beispiel #11
0
 /**
  * @param os
  * @param info
  * @throws IOException
  */
 public XmpWriter(Stream os, Hashtable info) : this(os) {
     if (info != null)
     {
         DublinCoreSchema dc    = new DublinCoreSchema();
         PdfSchema        p     = new PdfSchema();
         XmpBasicSchema   basic = new XmpBasicSchema();
         String           value;
         foreach (String key in info.Keys)
         {
             value = (String)info[key];
             if (value == null)
             {
                 continue;
             }
             if ("Title".Equals(key))
             {
                 dc.AddTitle(value);
             }
             if ("Author".Equals(key))
             {
                 dc.AddAuthor(value);
             }
             if ("Subject".Equals(key))
             {
                 dc.AddSubject(value);
             }
             if ("Keywords".Equals(key))
             {
                 p.AddKeywords(value);
             }
             if ("Creator".Equals(key))
             {
                 basic.AddCreatorTool(value);
             }
             if ("Producer".Equals(key))
             {
                 p.AddProducer(value);
             }
             if ("CreationDate".Equals(key))
             {
                 basic.AddCreateDate(PdfDate.GetW3CDate(value));
             }
             if ("ModDate".Equals(key))
             {
                 basic.AddModDate(PdfDate.GetW3CDate(value));
             }
         }
         if (dc.Count > 0)
         {
             AddRdfDescription(dc);
         }
         if (p.Count > 0)
         {
             AddRdfDescription(p);
         }
         if (basic.Count > 0)
         {
             AddRdfDescription(basic);
         }
     }
 }
        /// <summary>
        /// @throws IOException
        /// </summary>
        /// <param name="os"></param>
        /// <param name="info"></param>
        public XmpWriter(Stream os, Hashtable info) : this(os)
        {
            if (info != null)
            {
                var    dc    = new DublinCoreSchema();
                var    p     = new PdfSchema();
                var    basic = new XmpBasicSchema();
                string value;
                foreach (DictionaryEntry entry in info)
                {
                    var key = (string)entry.Key;
                    value = (string)entry.Value;
                    if (value == null)
                    {
                        continue;
                    }

                    if ("Title".Equals(key))
                    {
                        dc.AddTitle(value);
                    }
                    if ("Author".Equals(key))
                    {
                        dc.AddAuthor(value);
                    }
                    if ("Subject".Equals(key))
                    {
                        dc.AddSubject(value);
                        dc.AddDescription(value);
                    }
                    if ("Keywords".Equals(key))
                    {
                        p.AddKeywords(value);
                    }
                    if ("Creator".Equals(key))
                    {
                        basic.AddCreatorTool(value);
                    }
                    if ("Producer".Equals(key))
                    {
                        p.AddProducer(value);
                    }
                    if ("CreationDate".Equals(key))
                    {
                        basic.AddCreateDate(PdfDate.GetW3CDate(value));
                    }
                    if ("ModDate".Equals(key))
                    {
                        basic.AddModDate(PdfDate.GetW3CDate(value));
                    }
                }
                if (dc.Count > 0)
                {
                    AddRdfDescription(dc);
                }

                if (p.Count > 0)
                {
                    AddRdfDescription(p);
                }

                if (basic.Count > 0)
                {
                    AddRdfDescription(basic);
                }
            }
        }
        /// <summary>
        /// @throws IOException
        /// </summary>
        public XmpWriter(Stream os, PdfDictionary info, int pdfXConformance) : this(os)
        {
            if (info != null)
            {
                var       dc    = new DublinCoreSchema();
                var       p     = new PdfSchema();
                var       basic = new XmpBasicSchema();
                PdfObject obj;
                foreach (PdfName key in info.Keys)
                {
                    obj = info.Get(key);
                    if (obj == null)
                    {
                        continue;
                    }

                    if (PdfName.Title.Equals(key))
                    {
                        dc.AddTitle(((PdfString)obj).ToUnicodeString());
                    }
                    if (PdfName.Author.Equals(key))
                    {
                        dc.AddAuthor(((PdfString)obj).ToUnicodeString());
                    }
                    if (PdfName.Subject.Equals(key))
                    {
                        dc.AddSubject(((PdfString)obj).ToUnicodeString());
                        dc.AddDescription(((PdfString)obj).ToUnicodeString());
                    }
                    if (PdfName.Keywords.Equals(key))
                    {
                        p.AddKeywords(((PdfString)obj).ToUnicodeString());
                    }
                    if (PdfName.Creator.Equals(key))
                    {
                        basic.AddCreatorTool(((PdfString)obj).ToUnicodeString());
                    }
                    if (PdfName.Producer.Equals(key))
                    {
                        p.AddProducer(((PdfString)obj).ToUnicodeString());
                    }
                    if (PdfName.Creationdate.Equals(key))
                    {
                        basic.AddCreateDate(((PdfDate)obj).GetW3CDate());
                    }
                    if (PdfName.Moddate.Equals(key))
                    {
                        basic.AddModDate(((PdfDate)obj).GetW3CDate());
                    }
                }
                if (dc.Count > 0)
                {
                    AddRdfDescription(dc);
                }

                if (p.Count > 0)
                {
                    AddRdfDescription(p);
                }

                if (basic.Count > 0)
                {
                    AddRdfDescription(basic);
                }

                if (pdfXConformance == PdfWriter.PDFA1A || pdfXConformance == PdfWriter.PDFA1B)
                {
                    var a1 = new PdfA1Schema();
                    if (pdfXConformance == PdfWriter.PDFA1A)
                    {
                        a1.AddConformance("A");
                    }
                    else
                    {
                        a1.AddConformance("B");
                    }

                    AddRdfDescription(a1);
                }
            }
        }
Beispiel #14
0
 /**
 * @param os
 * @param info
 * @throws IOException
 */
 public XmpWriter(Stream os, PdfDictionary info)
     : this(os)
 {
     if (info != null) {
         DublinCoreSchema dc = new DublinCoreSchema();
         PdfSchema p = new PdfSchema();
         XmpBasicSchema basic = new XmpBasicSchema();
         PdfObject obj;
         foreach (PdfName key in info.Keys) {
             obj = info.Get(key);
             if (obj == null)
                 continue;
             if (PdfName.TITLE.Equals(key)) {
                 dc.AddTitle(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.AUTHOR.Equals(key)) {
                 dc.AddAuthor(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.SUBJECT.Equals(key)) {
                 dc.AddSubject(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.KEYWORDS.Equals(key)) {
                 p.AddKeywords(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.CREATOR.Equals(key)) {
                 basic.AddCreatorTool(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.PRODUCER.Equals(key)) {
                 p.AddProducer(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.CREATIONDATE.Equals(key)) {
                 basic.AddCreateDate(((PdfDate)obj).GetW3CDate());
             }
             if (PdfName.MODDATE.Equals(key)) {
                 basic.AddModDate(((PdfDate)obj).GetW3CDate());
             }
         }
         if (dc.Count > 0) AddRdfDescription(dc);
         if (p.Count > 0) AddRdfDescription(p);
         if (basic.Count > 0) AddRdfDescription(basic);
     }
 }