Inheritance: PdfObject, IComparable
Example #1
0
        virtual public void TestConstructionForType0WithoutToUnicodeMap()
        {
            int pageNum = 2;
            PdfName fontIdName = new PdfName("TT9");

            string testFile = TestResourceUtils.GetResourceAsTempFile(TEST_RESOURCES_PATH, "type0FontWithoutToUnicodeMap.pdf");
            RandomAccessFileOrArray f = new RandomAccessFileOrArray(testFile);
            PdfReader reader = new PdfReader(f, null);

            try
            {
                PdfDictionary fontsDic = reader.GetPageN(pageNum).GetAsDict(PdfName.RESOURCES).GetAsDict(PdfName.FONT);
                PdfDictionary fontDicDirect = fontsDic.GetAsDict(fontIdName);
                PRIndirectReference fontDicIndirect = (PRIndirectReference)fontsDic.Get(fontIdName);

                Assert.AreEqual(PdfName.TYPE0, fontDicDirect.GetAsName(PdfName.SUBTYPE));
                Assert.AreEqual("/Identity-H", fontDicDirect.GetAsName(PdfName.ENCODING).ToString());
                Assert.IsNull(fontDicDirect.Get(PdfName.TOUNICODE), "This font should not have a ToUnicode map");

                new DocumentFont(fontDicIndirect); // this used to throw an NPE
            }
            finally
            {
                reader.Close();
            }
        }
Example #2
0
 /**
 * Creates a new instance of PdfStructureElement.
 * @param parent the parent of this node
 * @param structureType the type of structure. It may be a standard type or a user type mapped by the role map
 */
 public PdfStructureElement(PdfStructureElement parent, PdfName structureType) {
     top = parent.top;
     Init(parent, structureType);
     this.parent = parent;
     Put(PdfName.P, parent.reference);
     Put(PdfName.TYPE, PdfName.STRUCTELEM);
 }
Example #3
0
 static PdfAppearance()
 {
     stdFieldFontNames["Courier-BoldOblique"] = new PdfName("CoBO");
     stdFieldFontNames["Courier-Bold"] = new PdfName("CoBo");
     stdFieldFontNames["Courier-Oblique"] = new PdfName("CoOb");
     stdFieldFontNames["Courier"] = new PdfName("Cour");
     stdFieldFontNames["Helvetica-BoldOblique"] = new PdfName("HeBO");
     stdFieldFontNames["Helvetica-Bold"] = new PdfName("HeBo");
     stdFieldFontNames["Helvetica-Oblique"] = new PdfName("HeOb");
     stdFieldFontNames["Helvetica"] = PdfName.HELV;
     stdFieldFontNames["Symbol"] = new PdfName("Symb");
     stdFieldFontNames["Times-BoldItalic"] = new PdfName("TiBI");
     stdFieldFontNames["Times-Bold"] = new PdfName("TiBo");
     stdFieldFontNames["Times-Italic"] = new PdfName("TiIt");
     stdFieldFontNames["Times-Roman"] = new PdfName("TiRo");
     stdFieldFontNames["ZapfDingbats"] = PdfName.ZADB;
     stdFieldFontNames["HYSMyeongJo-Medium"] = new PdfName("HySm");
     stdFieldFontNames["HYGoThic-Medium"] = new PdfName("HyGo");
     stdFieldFontNames["HeiseiKakuGo-W5"] = new PdfName("KaGo");
     stdFieldFontNames["HeiseiMin-W3"] = new PdfName("KaMi");
     stdFieldFontNames["MHei-Medium"] = new PdfName("MHei");
     stdFieldFontNames["MSung-Light"] = new PdfName("MSun");
     stdFieldFontNames["STSong-Light"] = new PdfName("STSo");
     stdFieldFontNames["MSungStd-Light"] = new PdfName("MSun");
     stdFieldFontNames["STSongStd-Light"] = new PdfName("STSo");
     stdFieldFontNames["HYSMyeongJoStd-Medium"] = new PdfName("HySm");
     stdFieldFontNames["KozMinPro-Regular"] = new PdfName("KaMi");
 }
 /**
 * Sets the value of the collection item.
 * @param value
 */
 public void AddItem(String key, PdfNumber n) {
     PdfName fieldname = new PdfName(key);
     PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
     if (field.fieldType == PdfCollectionField.NUMBER) {
         Put(fieldname, n);
     }
 }
 /**
 * Sets the value of the collection item.
 * @param value
 */
 public void AddItem(String key, PdfDate d) {
     PdfName fieldname = new PdfName(key);
     PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
     if (field.fieldType == PdfCollectionField.DATE) {
         Put(fieldname, d);
     }
 }
Example #6
0
 public PdfObject GetAccessibleAttribute(PdfName key) {
     if (accessibleAttributes != null) {
         PdfObject value;
         accessibleAttributes.TryGetValue(key, out value);
         return value;
     } else
         return null;
 }
Example #7
0
 /**
 * Maps the user tags to the standard tags. The mapping will allow a standard application to make some sense of the tagged
 * document whatever the user tags may be.
 * @param used the user tag
 * @param standard the standard tag
 */    
 public void MapRole(PdfName used, PdfName standard) {
     PdfDictionary rm = (PdfDictionary)Get(PdfName.ROLEMAP);
     if (rm == null) {
         rm = new PdfDictionary();
         Put(PdfName.ROLEMAP, rm);
     }
     rm.Put(used, standard);
 }
Example #8
0
     // methods
 
     internal void Add(PdfName key, PdfDictionary resource) {
         if (resource.Size == 0)
             return;
         PdfDictionary dic = GetAsDict(key);
         if (dic == null)
             Put(key, resource);
         else
             dic.Merge(resource);
     }
Example #9
0
 // methods
 internal void Add(PdfName key, PdfDictionary resource)
 {
     if (resource.Size == 0)
         return;
     PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObject(Get(key));
     if (dic == null)
         Put(key, resource);
     else
         dic.Merge(resource);
 }
Example #10
0
        // ---------------------------------------------------------------------------
        /**
         * Manipulates a PDF file src with the byte array as result
         */
        public byte[] ManipulatePdf(byte[] pdf)
        {
            PdfName key = new PdfName("ITXT_SpecialId");
              PdfName value = new PdfName("123456789");
              // Read the file
              PdfReader reader = new PdfReader(pdf);
              int n = reader.XrefSize;
              PdfObject pdfObject;
              PRStream prStream;
              // Look for image and manipulate image prStream
              for (int i = 0; i < n; i++) {
            pdfObject = reader.GetPdfObject(i);
            if (pdfObject == null || !pdfObject.IsStream()) continue;

            prStream = (PRStream) pdfObject;
            byte[] imageBytes;
            if (value.Equals(prStream.Get(key))) {
              PdfImageObject image = new PdfImageObject(prStream);
              using (System.Drawing.Image original = image.GetDrawingImage()) {
            if (original == null) continue;
            int width = (int)(original.Width * FACTOR);
            int height = (int)(original.Height * FACTOR);

            using (System.Drawing.Image thumb = new Bitmap(width, height) ) {
              using ( Graphics graphic = Graphics.FromImage(thumb) ) {
                graphic.DrawImage(original, 0, 0, width, height);
                using (MemoryStream ms = new MemoryStream()) {
                  thumb.Save(ms, ImageFormat.Jpeg);
                  imageBytes = ms.ToArray();
                }
              }
            }
            prStream.Clear();
            prStream.SetData(imageBytes, false, PRStream.NO_COMPRESSION);
            prStream.Put(PdfName.TYPE, PdfName.XOBJECT);
            prStream.Put(PdfName.SUBTYPE, PdfName.IMAGE);
            prStream.Put(key, value);
            prStream.Put(PdfName.FILTER, PdfName.DCTDECODE);
            prStream.Put(PdfName.WIDTH, new PdfNumber(width));
            prStream.Put(PdfName.HEIGHT, new PdfNumber(height));
            prStream.Put(PdfName.BITSPERCOMPONENT, new PdfNumber(8));
            prStream.Put(PdfName.COLORSPACE, PdfName.DEVICERGB);
              }
            }
              }
              // Save altered PDF
              using (MemoryStream ms = new MemoryStream()) {
            using (PdfStamper stamper = new PdfStamper(reader, ms)) {
            }
            return ms.ToArray();
              }
        }
Example #11
0
 internal PdfStructureElement(PdfDictionary parent, PdfName structureType) {
     if (parent is PdfStructureElement) {
         top = ((PdfStructureElement) parent).top;
         Init(parent, structureType);
         this.parent = (PdfStructureElement) parent;
         Put(PdfName.P, ((PdfStructureElement) parent).reference);
         Put(PdfName.TYPE, PdfName.STRUCTELEM);
     } else if (parent is PdfStructureTreeRoot) {
         top = (PdfStructureTreeRoot) parent;
         Init(parent, structureType);
         Put(PdfName.P, ((PdfStructureTreeRoot) parent).Reference);
         Put(PdfName.TYPE, PdfName.STRUCTELEM);
     } else {}
 }
Example #12
0
// ---------------------------------------------------------------------------     
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
      // the font file
      byte[] fontfile = null;
      using (FileStream fs = new FileStream(
        FONT, FileMode.Open, FileAccess.Read)) 
      {
        fontfile = new byte[fs.Length];
        fs.Read(fontfile, 0, (int) fs.Length);
      }
      // create a new stream for the font file
      PdfStream stream = new PdfStream(fontfile);
      stream.FlateCompress();
      stream.Put(PdfName.LENGTH1, new PdfNumber(fontfile.Length));
      // create a reader object
      PdfReader reader = new PdfReader(src);
      int n = reader.XrefSize;
      PdfDictionary font;
      using (MemoryStream ms = new MemoryStream()) {      
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          PdfName fontname = new PdfName(FONTNAME);
          for (int i = 0; i < n; i++) {
            PdfObject objectPdf = reader.GetPdfObject(i);
            if (objectPdf == null || !objectPdf.IsDictionary()) {
              continue;
            }
            font = (PdfDictionary)objectPdf;
            if (PdfName.FONTDESCRIPTOR.Equals(font.Get(PdfName.TYPE))
                && fontname.Equals(font.Get(PdfName.FONTNAME))) 
            {
              PdfIndirectObject objref = stamper.Writer.AddToBody(stream);
              font.Put(PdfName.FONTFILE2, objref.IndirectReference);
            }
          }
        }
        return ms.ToArray();
      }
    } 
Example #13
0
 /**
  * @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject)
  */
 virtual public void AddViewerPreference(PdfName key, PdfObject value)
 {
     fc.AddViewerPreference(key, value);
 }
 /**
  * Constructs a <CODE>PdfDictionary</CODE>-object of a certain type.
  *
  * @param        type    a <CODE>PdfName</CODE>
  */
 public PdfDictionary(PdfName type)
     : this()
 {
     dictionaryType = type;
     Put(PdfName.TYPE, dictionaryType);
 }
 /**
  * Removes a <CODE>PdfObject</CODE> and its key from the <CODE>PdfDictionary</CODE>.
  *
  * @param        key        key of the entry (a <CODE>PdfName</CODE>)
  */
 virtual public void Remove(PdfName key)
 {
     hashMap.Remove(key);
 }
 virtual public bool Contains(PdfName key)
 {
     return(hashMap.ContainsKey(key));
 }
 /**
  * This function behaves the same as 'get', but will never return an indirect reference,
  * it will always look such references up and return the actual object.
  * @param key
  * @return null, or a non-indirect object
  */
 public virtual PdfObject GetDirectObject(PdfName key)
 {
     return(PdfReader.GetPdfObject(Get(key)));
 }
        internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams)
        {
            if (this.writer != writer)
            {
                throw new ArgumentException(MessageLocalization.GetComposedMessage("type3.font.used.with.the.wrong.pdfwriter"));
            }
            // Get first & lastchar ...
            int firstChar = 0;

            while (firstChar < usedSlot.Length && !usedSlot[firstChar])
            {
                firstChar++;
            }

            if (firstChar == usedSlot.Length)
            {
                throw new DocumentException(MessageLocalization.GetComposedMessage("no.glyphs.defined.for.type3.font"));
            }
            int lastChar = usedSlot.Length - 1;

            while (lastChar >= firstChar && !usedSlot[lastChar])
            {
                lastChar--;
            }

            int[] widths = new int[lastChar - firstChar + 1];
            int[] invOrd = new int[lastChar - firstChar + 1];

            int invOrdIndx = 0, w = 0;

            for (int u = firstChar; u <= lastChar; u++, w++)
            {
                if (usedSlot[u])
                {
                    invOrd[invOrdIndx++] = u;
                    widths[w]            = widths3[u];
                }
            }
            PdfArray      diffs     = new PdfArray();
            PdfDictionary charprocs = new PdfDictionary();
            int           last      = -1;

            for (int k = 0; k < invOrdIndx; ++k)
            {
                int c = invOrd[k];
                if (c > last)
                {
                    last = c;
                    diffs.Add(new PdfNumber(last));
                }
                ++last;
                int    c2 = invOrd[k];
                String s  = GlyphList.UnicodeToName(c2);
                if (s == null)
                {
                    s = "a" + c2;
                }
                PdfName n = new PdfName(s);
                diffs.Add(n);
                Type3Glyph glyph  = (Type3Glyph)char2glyph[(char)c2];
                PdfStream  stream = new PdfStream(glyph.ToPdf(null));
                stream.FlateCompress(compressionLevel);
                PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference;
                charprocs.Put(n, refp);
            }
            PdfDictionary font = new PdfDictionary(PdfName.FONT);

            font.Put(PdfName.SUBTYPE, PdfName.TYPE3);
            if (colorized)
            {
                font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0));
            }
            else
            {
                font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury));
            }
            font.Put(PdfName.FONTMATRIX, new PdfArray(new float[] { 0.001f, 0, 0, 0.001f, 0, 0 }));
            font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference);
            PdfDictionary encoding = new PdfDictionary();

            encoding.Put(PdfName.DIFFERENCES, diffs);
            font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference);
            font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar));
            font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar));
            font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference);
            if (pageResources.HasResources())
            {
                font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference);
            }
            writer.AddToBody(font, piRef);
        }
 /// <summary>
 /// Creates a new instance of PdfStructureElement.
 /// </summary>
 /// <param name="parent">the parent of this node</param>
 /// <param name="structureType">the type of structure. It may be a standard type or a user type mapped by the role map</param>
 public PdfStructureElement(PdfStructureTreeRoot parent, PdfName structureType)
 {
     _top = parent;
     init(parent, structureType);
     Put(PdfName.P, parent.Reference);
 }
Example #20
0
 /**
  * Adds an additional entry for the page dictionary.
  * @since 5.1.0
  */
 public void AddPageDictEntry(PdfName key, PdfObject obj) {
     pageDictEntries.Put(key, obj);
 }
Example #21
0
 /**
 * Adds an image to the document but not to the page resources. It is used with
 * templates and <CODE>Document.Add(Image)</CODE>.
 * @param image the <CODE>Image</CODE> to add
 * @param fixedRef the reference to used. It may be <CODE>null</CODE>,
 * a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
 * @return the name of the image added
 * @throws PdfException on error
 * @throws DocumentException on error
 */
 public PdfName AddDirectImageSimple(Image image, PdfIndirectReference fixedRef) {
     PdfName name;
     // if the images is already added, just retrieve the name
     if (images.ContainsKey(image.MySerialId)) {
         name = images[image.MySerialId];
     }
     // if it's a new image, add it to the document
     else {
         if (image.IsImgTemplate()) {
             name = new PdfName("img" + images.Count);
             if (image is ImgWMF){
                 ImgWMF wmf = (ImgWMF)image;
                 wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0));
             }
         }
         else {
             PdfIndirectReference dref = image.DirectReference;
             if (dref != null) {
                 PdfName rname = new PdfName("img" + images.Count);
                 images[image.MySerialId] = rname;
                 imageDictionary.Put(rname, dref);
                 return rname;
             }
             Image maskImage = image.ImageMask;
             PdfIndirectReference maskRef = null;
             if (maskImage != null) {
                 PdfName mname = images[maskImage.MySerialId];
                 maskRef = GetImageReference(mname);
             }
             PdfImage i = new PdfImage(image, "img" + images.Count, maskRef);
             if (image is ImgJBIG2) {
                 byte[] globals = ((ImgJBIG2) image).GlobalBytes;
                 if (globals != null) {
                     PdfDictionary decodeparms = new PdfDictionary();
                     decodeparms.Put(PdfName.JBIG2GLOBALS, GetReferenceJBIG2Globals(globals));
                     i.Put(PdfName.DECODEPARMS, decodeparms);
                 }
             }
             if (image.HasICCProfile()) {
                 PdfICCBased icc = new PdfICCBased(image.TagICC, image.CompressionLevel);
                 PdfIndirectReference iccRef = Add(icc);
                 PdfArray iccArray = new PdfArray();
                 iccArray.Add(PdfName.ICCBASED);
                 iccArray.Add(iccRef);
                 PdfArray colorspace = i.GetAsArray(PdfName.COLORSPACE);
                 if (colorspace != null) {
                     if (colorspace.Size > 1 && PdfName.INDEXED.Equals(colorspace[0]))
                         colorspace[1] = iccArray;
                     else
                         i.Put(PdfName.COLORSPACE, iccArray);
                 }
                 else
                     i.Put(PdfName.COLORSPACE, iccArray);
             }
             Add(i, fixedRef);
             name = i.Name;
         }
         images[image.MySerialId] = name;
     }
     return name;
 }
Example #22
0
 /** Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @throws PdfException if the action type is invalid
 */    
 public virtual void SetPageAction(PdfName actionType, PdfAction action) {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.page.additional.action.type.1", actionType.ToString()));
     pdf.SetPageAction(actionType, action);
 }
Example #23
0
 /**
 * Sets the default colorspace that will be applied to all the document.
 * The colorspace is only applied if another colorspace with the same name
 * is not present in the content.
 * <p>
 * The colorspace is applied immediately when creating templates and at the page
 * end for the main document content.
 * @param key the name of the colorspace. It can be <CODE>PdfName.DEFAULTGRAY</CODE>, <CODE>PdfName.DEFAULTRGB</CODE>
 * or <CODE>PdfName.DEFAULTCMYK</CODE>
 * @param cs the colorspace. A <CODE>null</CODE> or <CODE>PdfNull</CODE> removes any colorspace with the same name
 */    
 public void SetDefaultColorspace(PdfName key, PdfObject cs) {
     if (cs == null || cs.IsNull())
         defaultColorspace.Remove(key);
     defaultColorspace.Put(key, cs);
 }
Example #24
0
 internal PdfName AddSimplePattern(PdfPatternPainter painter) {
     PdfName name;
     documentPatterns.TryGetValue(painter, out name);
     if (name == null) {
         name = new PdfName("P" + patternNumber);
         ++patternNumber;
         documentPatterns[painter] = name;
     }
     return name;
 }
Example #25
0
 private void AddASEvent(PdfName eventa, PdfName category) {
     PdfArray arr = new PdfArray();
     foreach (PdfLayer layer in documentOCG.Keys) {
         PdfDictionary usage = layer.GetAsDict(PdfName.USAGE);
         if (usage != null && usage.Get(category) != null)
             arr.Add(layer.Ref);
     }
     if (arr.Size == 0)
         return;
     PdfDictionary d = vOCProperties.GetAsDict(PdfName.D);
     PdfArray arras = d.GetAsArray(PdfName.AS);
     if (arras == null) {
         arras = new PdfArray();
         d.Put(PdfName.AS, arras);
     }
     PdfDictionary asa = new PdfDictionary();
     asa.Put(PdfName.EVENT, eventa);
     asa.Put(PdfName.CATEGORY, new PdfArray(category));
     asa.Put(PdfName.OCGS, arr);
     arras.Add(asa);
 }
Example #26
0
        virtual internal protected void Close(IDictionary<String, String> moreInfo) {
            if (closed) {
                return;
            }
            if (useVp) {
                SetViewerPreferences();
            }
            if (flat) {
                FlatFields();
            }
            if (flatFreeText) {
                FlatFreeTextFields();
            }
            if (flatannotations) {
                FlattenAnnotations();
            }
            AddFieldResources();
            PdfDictionary catalog = reader.Catalog;
            GetPdfVersion().AddToCatalog(catalog);
            PdfDictionary acroForm = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.ACROFORM), reader.Catalog);
            if (acroFields != null && acroFields.Xfa.Changed) {
                MarkUsed(acroForm);
                if (!flat) {
                    acroFields.Xfa.SetXfa(this);
                }
            }
            if (sigFlags != 0) {
                if (acroForm != null) {
                    acroForm.Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
                    MarkUsed(acroForm);
                    MarkUsed(catalog);
                }
            }
            closed = true;
            AddSharedObjectsToBody();
            SetOutlines();
            SetJavaScript();
            AddFileAttachments();
            // [C11] Output Intents
            if (extraCatalog != null) {
                catalog.MergeDifferent(extraCatalog);
            }
            if (openAction != null) {
                catalog.Put(PdfName.OPENACTION, openAction);
            }
            if (pdf.pageLabels != null) {
                catalog.Put(PdfName.PAGELABELS, pdf.pageLabels.GetDictionary(this));
            }
            // OCG
            if (documentOCG.Count > 0) {
                FillOCProperties(false);
                PdfDictionary ocdict = catalog.GetAsDict(PdfName.OCPROPERTIES);
                if (ocdict == null) {
                    reader.Catalog.Put(PdfName.OCPROPERTIES, OCProperties);
                }
                else {
                    ocdict.Put(PdfName.OCGS, OCProperties.Get(PdfName.OCGS));
                    PdfDictionary ddict = ocdict.GetAsDict(PdfName.D);
                    if (ddict == null) {
                        ddict = new PdfDictionary();
                        ocdict.Put(PdfName.D, ddict);
                    }
                    ddict.Put(PdfName.ORDER, OCProperties.GetAsDict(PdfName.D).Get(PdfName.ORDER));
                    ddict.Put(PdfName.RBGROUPS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.RBGROUPS));
                    ddict.Put(PdfName.OFF, OCProperties.GetAsDict(PdfName.D).Get(PdfName.OFF));
                    ddict.Put(PdfName.AS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.AS));
                }
                PdfWriter.CheckPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_LAYER, OCProperties);
            }
            // metadata
            int skipInfo = -1;
            PdfIndirectReference iInfo = reader.Trailer.GetAsIndirectObject(PdfName.INFO);
            if (iInfo != null) {
                skipInfo = iInfo.Number;
            }
            PdfDictionary oldInfo = reader.Trailer.GetAsDict(PdfName.INFO);
            String producer = null;
            if (oldInfo != null && oldInfo.Get(PdfName.PRODUCER) != null) {
                producer = oldInfo.GetAsString(PdfName.PRODUCER).ToUnicodeString();
            }
            Version version = Version.GetInstance();
            if (producer == null || version.GetVersion.IndexOf(version.Product) == -1) {
                producer = version.GetVersion;
            } else {
                int idx = producer.IndexOf("; modified using");
                StringBuilder buf;
                if (idx == -1)
                    buf = new StringBuilder(producer);
                else
                    buf = new StringBuilder(producer.Substring(0, idx));
                buf.Append("; modified using ");
                buf.Append(version.GetVersion);
                producer = buf.ToString();
            }
            PdfIndirectReference info = null;
            PdfDictionary newInfo = new PdfDictionary();
            if (oldInfo != null) {
                foreach (PdfName key in oldInfo.Keys) {
                    PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
                    newInfo.Put(key, value);
                }
            }
            if (moreInfo != null) {
                foreach (KeyValuePair<string,string> entry in moreInfo) {
                    PdfName keyName = new PdfName(entry.Key);
                    String value = entry.Value;
                    if (value == null)
                        newInfo.Remove(keyName);
                    else
                        newInfo.Put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE));
                }
            }
            PdfDate date = new PdfDate();
            newInfo.Put(PdfName.MODDATE, date);
            newInfo.Put(PdfName.PRODUCER, new PdfString(producer, PdfObject.TEXT_UNICODE));
            if (append) {
                if (iInfo == null) {
                    info = AddToBody(newInfo, false).IndirectReference;
                } else {
                    info = AddToBody(newInfo, iInfo.Number, false).IndirectReference;
                }
            } else {
                info = AddToBody(newInfo, false).IndirectReference;
            }
            // XMP
            byte[] altMetadata = null;
            PdfObject xmpo = PdfReader.GetPdfObject(catalog.Get(PdfName.METADATA));
            if (xmpo != null && xmpo.IsStream()) {
                altMetadata = PdfReader.GetStreamBytesRaw((PRStream)xmpo);
                PdfReader.KillIndirect(catalog.Get(PdfName.METADATA));
            }
            PdfStream xmp = null;
            if (xmpMetadata != null) {
                altMetadata = xmpMetadata;
            } else if (xmpWriter != null) {
                try {
                    MemoryStream baos = new MemoryStream();
                    PdfProperties.SetProducer(xmpWriter.XmpMeta, producer);
                    XmpBasicProperties.SetModDate(xmpWriter.XmpMeta, date.GetW3CDate());
                    XmpBasicProperties.SetMetaDataDate(xmpWriter.XmpMeta, date.GetW3CDate());
                    xmpWriter.Serialize(baos);
                    xmpWriter.Close();
                    xmp = new PdfStream(baos.ToArray());
                } catch (XmpException) {
                    xmpWriter = null;
                }
            }
            if (xmp == null && altMetadata != null) {
                try {
                    MemoryStream baos = new MemoryStream();
                    if (moreInfo == null || xmpMetadata != null) {
                        IXmpMeta xmpMeta = XmpMetaFactory.ParseFromBuffer(altMetadata);

                        PdfProperties.SetProducer(xmpMeta, producer);
                        XmpBasicProperties.SetModDate(xmpMeta, date.GetW3CDate());
                        XmpBasicProperties.SetMetaDataDate(xmpMeta, date.GetW3CDate());

                        SerializeOptions serializeOptions = new SerializeOptions();
                        serializeOptions.Padding = 2000;
                        XmpMetaFactory.Serialize(xmpMeta, baos, serializeOptions);
                    } else {
                        XmpWriter xmpw = CreateXmpWriter(baos, newInfo);
                        xmpw.Close();
                    }
                    xmp = new PdfStream(baos.ToArray());
                } catch (XmpException) {
                    xmp = new PdfStream(altMetadata);
                } catch (IOException) {
                    xmp = new PdfStream(altMetadata);
                }
            }
            if (xmp != null) {
                xmp.Put(PdfName.TYPE, PdfName.METADATA);
                xmp.Put(PdfName.SUBTYPE, PdfName.XML);
                if (crypto != null && !crypto.IsMetadataEncrypted()) {
                    PdfArray ar = new PdfArray();
                    ar.Add(PdfName.CRYPT);
                    xmp.Put(PdfName.FILTER, ar);
                }
                if (append && xmpo != null) {
                    body.Add(xmp, xmpo.IndRef);
                }
                else {
                    catalog.Put(PdfName.METADATA, body.Add(xmp).IndirectReference);
                    MarkUsed(catalog);
                }
            }
            Close(info, skipInfo);
        }
Example #27
0
 /**
 * Adds a template to the document but not to the page resources.
 * @param template the template to add
 * @param forcedName the template name, rather than a generated one. Can be null
 * @return the <CODE>PdfName</CODE> for this template
 */        
 internal PdfName AddDirectTemplateSimple(PdfTemplate template, PdfName forcedName) {
     PdfIndirectReference refa = template.IndirectReference;
     Object[] obj;
     formXObjects.TryGetValue(refa, out obj);
     PdfName name = null;
     if (obj == null) {
         if (forcedName == null) {
             name = new PdfName("Xf" + formXObjectsCounter);
             ++formXObjectsCounter;
         }
         else
             name = forcedName;
         if (template.Type == PdfTemplate.TYPE_IMPORTED) {
             // If we got here from PdfCopy we'll have to fill importedPages
             PdfImportedPage ip = (PdfImportedPage)template;
             PdfReader r = ip.PdfReaderInstance.Reader;
             if (!readerInstances.ContainsKey(r)) {
                 readerInstances[r] = ip.PdfReaderInstance;
             }
             template = null;
         }
         formXObjects[refa] = new Object[]{name, template};
     }
     else
         name = (PdfName)obj[0];
     return name;
 }
Example #28
0
 /** Adds a viewer preference
 * @param preferences the viewer preferences
 * @see PdfViewerPreferences#addViewerPreference
 */
 public virtual void AddViewerPreference(PdfName key, PdfObject value) {
     pdf.AddViewerPreference(key, value);
 }
Example #29
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public virtual void SetAdditionalAction(PdfName actionType, PdfAction action) {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.additional.action.type.1", actionType.ToString()));
     }
     pdf.AddAdditionalAction(actionType, action);
 }
Example #30
0
        /**
        * Copies the format of the sourceTable without copying the content. 
        * @param sourceTable
        * @since 2.1.6 private is now protected
        */

        virtual protected internal void CopyFormat(PdfPTable sourceTable)
        {
            relativeWidths = new float[sourceTable.NumberOfColumns];
            absoluteWidths = new float[sourceTable.NumberOfColumns];
            System.Array.Copy(sourceTable.relativeWidths, 0, relativeWidths, 0, NumberOfColumns);
            System.Array.Copy(sourceTable.absoluteWidths, 0, absoluteWidths, 0, NumberOfColumns);
            totalWidth = sourceTable.totalWidth;
            totalHeight = sourceTable.totalHeight;
            currentColIdx = 0;
            tableEvent = sourceTable.tableEvent;
            runDirection = sourceTable.runDirection;
            if (sourceTable.defaultCell is PdfPHeaderCell)
                defaultCell = new PdfPHeaderCell((PdfPHeaderCell)sourceTable.defaultCell);
            else
                defaultCell = new PdfPCell(sourceTable.defaultCell);
            currentRow = new PdfPCell[sourceTable.currentRow.Length];
            isColspan = sourceTable.isColspan;
            splitRows = sourceTable.splitRows;
            spacingAfter = sourceTable.spacingAfter;
            spacingBefore = sourceTable.spacingBefore;
            headerRows = sourceTable.headerRows;
            footerRows = sourceTable.footerRows;
            lockedWidth = sourceTable.lockedWidth;
            extendLastRow = sourceTable.extendLastRow;
            headersInEvent = sourceTable.headersInEvent;
            widthPercentage = sourceTable.widthPercentage;
            splitLate = sourceTable.splitLate;
            skipFirstHeader = sourceTable.skipFirstHeader;
            skipLastFooter = sourceTable.skipLastFooter;
            horizontalAlignment = sourceTable.horizontalAlignment;
            keepTogether = sourceTable.keepTogether;
            complete = sourceTable.complete;
            loopCheck = sourceTable.loopCheck;
            id = sourceTable.ID;
            role = sourceTable.Role;
            if (sourceTable.accessibleAttributes != null)
                accessibleAttributes = new Dictionary<PdfName, PdfObject>(sourceTable.accessibleAttributes);
            header = sourceTable.GetHeader();
            body = sourceTable.GetBody();
            footer = sourceTable.GetFooter();
        }
Example #31
0
 /**
 * @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(com.lowagie.text.pdf.PdfName)
 */
 public void SetPdfVersion(PdfName version) {
     pdf_version.SetPdfVersion(version);
 }
Example #32
0
 virtual public void SetAccessibleAttribute(PdfName key, PdfObject value) {
     if (accessibleAttributes == null)
         accessibleAttributes = new Dictionary<PdfName, PdfObject>();
     accessibleAttributes[key] = value;
 }
Example #33
0
 /**
  * Creates a RichMediaInstance. Also specifies the content type
  * for the instance. Valid values are 3D, Flash, Sound, and Video.
  * The subtype must match the asset file type of the instance.
  * @param   subtype possible values are:
  * PdfName._3D, PdfName.FLASH, PdfName.SOUND, and PdfName.VIDEO.
  */
 public RichMediaInstance(PdfName subtype) : base(PdfName.RICHMEDIAINSTANCE) {
     Put(PdfName.SUBTYPE, subtype);
     flash = PdfName.FLASH.Equals(subtype);
 }
Example #34
0
 private static void MoveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) {
     Rectangle m = r.GetBoxSize(pageImported, name);
     if (m == null)
         dic2.Remove(key);
     else
         dic2.Put(key, new PdfRectangle(m));
 }
Example #35
0
 /**
 * return the <CODE>PdfIndirectReference</CODE> to the image with a given name.
 *
 * @param name the name of the image
 * @return a <CODE>PdfIndirectReference</CODE>
 */
 internal virtual PdfIndirectReference GetImageReference(PdfName name) {
     return (PdfIndirectReference) imageDictionary.Get(name);
 }
Example #36
0
 private static String GetNameString(PdfDictionary dic, PdfName key) {
     PdfObject obj = PdfReader.GetPdfObject(dic.Get(key));
     if (obj == null || !obj.IsString())
         return null;
     return ((PdfString)obj).ToUnicodeString();
 }
 /**
 * Creates a PdfDeveloperExtension object.
 * @param prefix    the prefix referring to the developer
 * @param baseversion   the number of the base version
 * @param extensionLevel    the extension level within the baseverion.
 */
 public PdfDeveloperExtension(PdfName prefix, PdfName baseversion, int extensionLevel) {
     this.prefix = prefix;
     this.baseversion = baseversion;
     this.extensionLevel = extensionLevel;
 }
 /**
 * Sets the value of the collection item.
 * @param value
 */
 virtual public void AddItem(String key, PdfString value) {
     PdfName fieldname = new PdfName(key);
     PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname);
     if (field.fieldType == PdfCollectionField.TEXT) {
         Put(fieldname, value);
     }
 }