public PdfXObject(byte[] objectData, PdfName name, PdfObjectId objectId) : base(objectId) { this.objectData = objectData; this.name = name; dictionary[PdfName.Names.Type] = PdfName.Names.XObject; }
public MarkedContentPoint( PdfName tag, PdfDirectObject properties ) : base(tag, properties) { }
protected DeviceColorSpace( Document context, PdfName baseDataObject ) : base(context, baseDataObject) { }
/** <summary>Creates a new action within the given document context.</summary> */ public NamedAction( Document context, PdfName actionName ) : base(context, PdfName.Named) { BaseDataObject[PdfName.N] = actionName; }
protected Markup( Page page, PdfName subtype, RectangleF box, string text ) : base(page, subtype, box, text) { }
protected Shape( Page page, RectangleF box, string text, PdfName subtype ) : base(page, subtype, box, text) { }
protected LayerEntity( Document context, PdfName typeName ) : base(context, new PdfDictionary( new PdfName[] {PdfName.Type}, new PdfDirectObject[] {typeName} )) { }
public static ListModeEnum Get( PdfName name ) { if(name == null) return ListModeEnum.AllPages; ListModeEnum? listMode = codes.GetKey(name); if(!listMode.HasValue) throw new NotSupportedException("List mode unknown: " + name); return listMode.Value; }
/** <summary>Gets a specific filter object.</summary> <param name="name">Name of the requested filter.</param> <returns>Filter object associated to the name.</returns> */ public static Filter Get( PdfName name ) { /* NOTE: This is a factory singleton method for any filter-derived object. */ if(name == null) return null; if(name.Equals(PdfName.FlateDecode) || name.Equals(PdfName.Fl)) return FlateDecode; else if(name.Equals(PdfName.LZWDecode) || name.Equals(PdfName.LZW)) throw new NotImplementedException("LZWDecode"); else if(name.Equals(PdfName.ASCIIHexDecode) || name.Equals(PdfName.AHx)) throw new NotImplementedException("ASCIIHexDecode"); else if(name.Equals(PdfName.ASCII85Decode) || name.Equals(PdfName.A85)) return ASCII85Filter; else if(name.Equals(PdfName.RunLengthDecode) || name.Equals(PdfName.RL)) throw new NotImplementedException("RunLengthDecode"); else if(name.Equals(PdfName.CCITTFaxDecode) || name.Equals(PdfName.CCF)) throw new NotImplementedException("CCITTFaxDecode"); else if(name.Equals(PdfName.JBIG2Decode)) throw new NotImplementedException("JBIG2Decode"); else if(name.Equals(PdfName.DCTDecode) || name.Equals(PdfName.DCT)) throw new NotImplementedException("DCTDecode"); else if(name.Equals(PdfName.JPXDecode)) throw new NotImplementedException("JPXDecode"); else if(name.Equals(PdfName.Crypt)) throw new NotImplementedException("Crypt"); return null; }
/** * Gets a color based on a list of operands. */ private static BaseColor GetColor(PdfName colorSpace, List<PdfObject> operands) { if (PdfName.DEVICEGRAY.Equals(colorSpace)) { return GetColor(1, operands); } if (PdfName.DEVICERGB.Equals(colorSpace)) { return GetColor(3, operands); } if (PdfName.DEVICECMYK.Equals(colorSpace)) { return GetColor(4, operands); } return null; }
/** * Constructs a RichMediaAnimation. Also sets the animation style * described by this dictionary. Valid values are None, Linear, and * Oscillating. * @param subtype possible values are * PdfName.NONE, PdfName.LINEAR, PdfName.OSCILLATING */ public RichMediaAnimation(PdfName subtype) : base(PdfName.RICHMEDIAANIMATION) { Put(PdfName.SUBTYPE, subtype); }
/** * Registers a Do handler that will be called when Do for the provided XObject subtype is encountered during content processing. * <br> * If you register a handler, it is a very good idea to pass the call on to the existing registered handler (returned by this call), otherwise you * may inadvertently change the internal behavior of the processor. * @param xobjectSubType the XObject subtype this handler will process, or PdfName.DEFAULT for a catch-all handler * @param handler the handler that will receive notification when the Do oper for the specified subtype is encountered * @return the existing registered handler, if any * @since 5.0.1 */ public IXObjectDoHandler RegisterXObjectDoHandler(PdfName xobjectSubType, IXObjectDoHandler handler){ IXObjectDoHandler old; xobjectDoHandlers.TryGetValue(xobjectSubType, out old); xobjectDoHandlers[xobjectSubType] = handler; return old; }
/** * Displays an XObject using the registered handler for this XObject's subtype * @param xobjectName the name of the XObject to retrieve from the resource dictionary */ private void DisplayXObject(PdfName xobjectName) { PdfDictionary xobjects = resources.GetAsDict(PdfName.XOBJECT); PdfObject xobject = xobjects.GetDirectObject(xobjectName); PdfStream xobjectStream = (PdfStream)xobject; PdfName subType = xobjectStream.GetAsName(PdfName.SUBTYPE); if (xobject.IsStream()){ IXObjectDoHandler handler; xobjectDoHandlers.TryGetValue(subType, out handler); if (handler == null) handler = xobjectDoHandlers[PdfName.DEFAULT]; handler.HandleXObject(this, xobjectStream, xobjects.GetAsIndirectObject(xobjectName)); } else { throw new InvalidOperationException(MessageLocalization.GetComposedMessage("XObject.1.is.not.a.stream", xobjectName)); } }
/** <summary>Sets the Javascript script into the specified base data object.</summary> */ internal static void SetScript( PdfDictionary baseDataObject, PdfName key, string value ) { PdfDataObject scriptObject = baseDataObject.Resolve(key); if(!(scriptObject is PdfStream) && value.Length > 256) {baseDataObject[key] = baseDataObject.File.Register(scriptObject = new PdfStream());} // Insert the script! if(scriptObject is PdfStream) { bytes::IBuffer scriptBuffer = ((PdfStream)scriptObject).Body; scriptBuffer.SetLength(0); scriptBuffer.Append(value); } else {baseDataObject[key] = new PdfTextString(value);} }
/** * 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); }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); PdfDocument document = drawContext.GetDocument(); bool isTagged = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement; bool isArtifact = false; TagTreePointer tagPointer = null; if (isTagged) { tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer(); IAccessibleElement accessibleElement = (IAccessibleElement)GetModelElement(); PdfName role = accessibleElement.GetRole(); if (role != null && !PdfName.Artifact.Equals(role)) { AccessibleAttributesApplier.ApplyLayoutAttributes(accessibleElement.GetRole(), this, document); tagPointer.AddTag(accessibleElement); } else { isTagged = false; if (PdfName.Artifact.Equals(role)) { isArtifact = true; } } } ApplyMargins(occupiedArea.GetBBox(), false); bool isRelativePosition = IsRelativePosition(); if (isRelativePosition) { ApplyAbsolutePositioningTranslation(false); } if (fixedYPosition == null) { fixedYPosition = occupiedArea.GetBBox().GetY() + pivotY; } if (fixedXPosition == null) { fixedXPosition = occupiedArea.GetBBox().GetX(); } PdfCanvas canvas = drawContext.GetCanvas(); if (isTagged) { canvas.OpenTag(tagPointer.GetTagReference()); } else { if (isArtifact) { canvas.OpenTag(new CanvasArtifact()); } } PdfXObject xObject = ((Image)(GetModelElement())).GetXObject(); canvas.AddXObject(xObject, matrix[0], matrix[1], matrix[2], matrix[3], (float)fixedXPosition + deltaX, (float )fixedYPosition); if (true.Equals(GetPropertyAsBoolean(Property.FLUSH_ON_DRAW))) { xObject.Flush(); } if (isTagged || isArtifact) { canvas.CloseTag(); } if (isRelativePosition) { ApplyAbsolutePositioningTranslation(true); } ApplyMargins(occupiedArea.GetBBox(), true); if (isTagged) { tagPointer.MoveToParent(); } }
/** <see cref="GetPath(PdfName)"/> */ private void SetPath( PdfName key, string value ) { BaseDictionary[key] = new PdfString(value); }
private PdfDictionary GetUsageEntry( PdfName key ) { return(Usage.Resolve <PdfDictionary>(key)); }
/** * Converts an annotation structure item to a Form XObject annotation. * @param item the structure item * @throws IOException */ virtual protected void ConvertToXObject(StructureObject item) { PdfDictionary structElem = item.GetStructElem(); if (structElem == null) { return; } PdfDictionary dict = item.GetObjAsDict(); if (dict == null || !dict.CheckType(PdfName.ANNOT)) { return; } PdfDictionary ap = dict.GetAsDict(PdfName.AP); if (ap == null) { return; } PdfNumber structParent = dict.GetAsNumber(PdfName.STRUCTPARENT); if (structParent == null) { return; } PdfStream stream = ap.GetAsStream(PdfName.N); if (stream == null) { return; } stream.Put(PdfName.STRUCTPARENT, structParent); PdfIndirectReference xobjr = ap.GetAsIndirectObject(PdfName.N); if (xobjr == null) { return; } // remove the annotation from the page for (int i = 0; i < annots.Length; i++) { PdfIndirectReference annotref = annots.GetAsIndirectObject(i); if (item.GetObjRef().Number == annotref.Number) { annots.Remove(i); break; } } // replace the existing attributes by a PrintField attribute PdfDictionary attribute = new PdfDictionary(); attribute.Put(PdfName.O, PdfName.PRINTFIELD); PdfString description = dict.GetAsString(PdfName.TU); if (description == null) { description = dict.GetAsString(PdfName.T); } if (PdfName.BTN.Equals(dict.Get(PdfName.FT))) { PdfNumber fflags = dict.GetAsNumber(PdfName.FF); if (fflags != null) { int ff = fflags.IntValue; if ((ff & PdfFormField.FF_PUSHBUTTON) != 0) { attribute.Put(PdfName.ROLE, PdfName.PB); } // I don't think the condition below will ever be true if ((ff & PdfFormField.FF_RADIO) != 0) { attribute.Put(PdfName.ROLE, PdfName.rb); } else { attribute.Put(PdfName.ROLE, PdfName.CB); } } } else { attribute.Put(PdfName.ROLE, PdfName.TV); } attribute.Put(PdfName.DESC, description); // Updating the values of the StructElem dictionary PdfString t = structElem.GetAsString(PdfName.T); if (t == null || t.ToString().Trim().Length == 0) { structElem.Put(PdfName.T, dict.GetAsString(PdfName.T)); } structElem.Put(PdfName.A, attribute); structElem.Put(PdfName.S, PdfName.P); structElem.Put(PdfName.PG, pageref); // Defining a new MCID int mcid = items.ProcessMCID(structParents, item.GetRef()); LOGGER.Info("Using MCID " + mcid); structElem.Put(PdfName.K, new PdfNumber(mcid)); // removing the annotation from the parent tree items.RemoveFromParentTree(structParent); // Adding the XObject to the page PdfName xobj = new PdfName("XObj" + structParent.IntValue); LOGGER.Info("Creating XObject with name " + xobj); xobjects.Put(xobj, xobjr); PdfArray array = dict.GetAsArray(PdfName.RECT); // Getting the position of the annotation Rectangle rect = new Rectangle( array.GetAsNumber(0).FloatValue, array.GetAsNumber(1).FloatValue, array.GetAsNumber(2).FloatValue, array.GetAsNumber(3).FloatValue); rect.Normalize(); // A Do operator is forbidden inside a text block if (inText && !btWrite) { LOGGER.Debug("Introducing extra ET"); byte[] bytes = Encoding.ASCII.GetBytes("ET\n"); baos.Write(bytes, 0, bytes.Length); etExtra = true; } // Writing the marked-content sequence with the Do operator // Note that the position assumes that the CTM wasn't changed in the graphics state // TODO: do the math if the CTM did change! ByteBuffer buf = new ByteBuffer(); buf.Append("/P <</MCID "); buf.Append(mcid); buf.Append(">> BDC\n"); buf.Append("q 1 0 0 1 "); buf.Append(rect.Left.ToString(CultureInfo.InvariantCulture)); buf.Append(" "); buf.Append(rect.Bottom.ToString(CultureInfo.InvariantCulture)); buf.Append(" cm "); buf.Append(xobj.GetBytes()); buf.Append(" Do Q\n"); buf.Append("EMC\n"); buf.Flush(); buf.WriteTo(baos); // if we were inside a text block, we've introduced an ET, so we'll need to write a BT if (inText) { btWrite = true; } }
public byte[] GetImageAsBytes() { if (streamBytes == null) { return(null); } if (!decoded) { // if the stream hasn't been decoded, check to see if it is a single stage JPG or JPX encoded stream. If it is, // then we can just use stream as-is PdfName filter = dictionary.GetAsName(PdfName.FILTER); if (filter == null) { PdfArray filterArray = dictionary.GetAsArray(PdfName.FILTER); if (filterArray.Size == 1) { filter = filterArray.GetAsName(0); } else { throw new UnsupportedPdfException("Multi-stage filters not supported here (" + filterArray + ")"); } } if (PdfName.DCTDECODE.Equals(filter)) { fileType = TYPE_JPG; return(streamBytes); } else if (PdfName.JPXDECODE.Equals(filter)) { fileType = TYPE_JP2; return(streamBytes); } throw new UnsupportedPdfException("Unsupported stream filter " + filter); } pngColorType = -1; width = dictionary.GetAsNumber(PdfName.WIDTH).IntValue; height = dictionary.GetAsNumber(PdfName.HEIGHT).IntValue; bpc = dictionary.GetAsNumber(PdfName.BITSPERCOMPONENT).IntValue; pngBitDepth = bpc; PdfObject colorspace = dictionary.GetDirectObject(PdfName.COLORSPACE); palette = null; icc = null; stride = 0; FindColorspace(colorspace, true); MemoryStream ms = new MemoryStream(); if (pngColorType < 0) { if (bpc != 8) { return(null); } if (PdfName.DEVICECMYK.Equals(colorspace)) { } else if (colorspace is PdfArray) { PdfArray ca = (PdfArray)colorspace; PdfObject tyca = ca.GetDirectObject(0); if (!PdfName.ICCBASED.Equals(tyca)) { return(null); } PRStream pr = (PRStream)ca.GetDirectObject(1); int n = pr.GetAsNumber(PdfName.N).IntValue; if (n != 4) { return(null); } icc = PdfReader.GetStreamBytes(pr); } else { return(null); } stride = 4 * width; TiffWriter wr = new TiffWriter(); wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL, 4)); wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_BITSPERSAMPLE, new int[] { 8, 8, 8, 8 })); wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_PHOTOMETRIC, TIFFConstants.PHOTOMETRIC_SEPARATED)); wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_IMAGEWIDTH, width)); wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_IMAGELENGTH, height)); wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_COMPRESSION, TIFFConstants.COMPRESSION_LZW)); wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_PREDICTOR, TIFFConstants.PREDICTOR_HORIZONTAL_DIFFERENCING)); wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_ROWSPERSTRIP, height)); wr.AddField(new TiffWriter.FieldRational(TIFFConstants.TIFFTAG_XRESOLUTION, new int[] { 300, 1 })); wr.AddField(new TiffWriter.FieldRational(TIFFConstants.TIFFTAG_YRESOLUTION, new int[] { 300, 1 })); wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_RESOLUTIONUNIT, TIFFConstants.RESUNIT_INCH)); wr.AddField(new TiffWriter.FieldAscii(TIFFConstants.TIFFTAG_SOFTWARE, Document.Version)); MemoryStream comp = new MemoryStream(); TiffWriter.CompressLZW(comp, 2, streamBytes, height, 4, stride); byte[] buf = comp.ToArray(); wr.AddField(new TiffWriter.FieldImage(buf)); wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_STRIPBYTECOUNTS, buf.Length)); if (icc != null) { wr.AddField(new TiffWriter.FieldUndefined(TIFFConstants.TIFFTAG_ICCPROFILE, icc)); } wr.WriteFile(ms); fileType = TYPE_TIF; return(ms.ToArray()); } PngWriter png = new PngWriter(ms); png.WriteHeader(width, height, pngBitDepth, pngColorType); if (icc != null) { png.WriteIccProfile(icc); } if (palette != null) { png.WritePalette(palette); } png.WriteData(streamBytes, stride); png.WriteEnd(); fileType = TYPE_PNG; return(ms.ToArray()); }
/** * Returns an entry from the image dictionary. * @param key a key * @return the value */ public PdfObject Get(PdfName key) { return(dictionary.Get(key)); }
protected internal virtual void FlushFontData(String fontName, PdfName subtype) { GetPdfObject().Put(PdfName.Subtype, subtype); if (fontName != null) { GetPdfObject().Put(PdfName.BaseFont, new PdfName(fontName)); } int firstChar; int lastChar; for (firstChar = 0; firstChar < 256; ++firstChar) { if (shortTag[firstChar] != 0) { break; } } for (lastChar = 255; lastChar >= firstChar; --lastChar) { if (shortTag[lastChar] != 0) { break; } } if (firstChar > 255) { firstChar = 255; lastChar = 255; } if (!IsSubset() || !IsEmbedded()) { firstChar = 0; lastChar = shortTag.Length - 1; for (int k = 0; k < shortTag.Length; ++k) { // remove unsupported by encoding values in case custom encoding. // save widths information in case standard pdf encodings (winansi or macroman) if (fontEncoding.CanDecode(k)) { shortTag[k] = 1; } else { if (!fontEncoding.HasDifferences() && fontProgram.GetGlyphByCode(k) != null) { shortTag[k] = 1; } else { shortTag[k] = 0; } } } } if (fontEncoding.HasDifferences()) { // trim range of symbols for (int k = firstChar; k <= lastChar; ++k) { if (!FontConstants.notdef.Equals(fontEncoding.GetDifference(k))) { firstChar = k; break; } } for (int k_1 = lastChar; k_1 >= firstChar; --k_1) { if (!FontConstants.notdef.Equals(fontEncoding.GetDifference(k_1))) { lastChar = k_1; break; } } PdfDictionary enc = new PdfDictionary(); enc.Put(PdfName.Type, PdfName.Encoding); PdfArray diff = new PdfArray(); bool gap = true; for (int k_2 = firstChar; k_2 <= lastChar; ++k_2) { if (shortTag[k_2] != 0) { if (gap) { diff.Add(new PdfNumber(k_2)); gap = false; } diff.Add(new PdfName(fontEncoding.GetDifference(k_2))); } else { gap = true; } } enc.Put(PdfName.Differences, diff); GetPdfObject().Put(PdfName.Encoding, enc); } else { if (!fontEncoding.IsFontSpecific()) { GetPdfObject().Put(PdfName.Encoding, PdfEncodings.CP1252.Equals(fontEncoding.GetBaseEncoding()) ? PdfName. WinAnsiEncoding : PdfName.MacRomanEncoding); } } if (IsForceWidthsOutput() || !IsBuiltInFont() || fontEncoding.HasDifferences()) { GetPdfObject().Put(PdfName.FirstChar, new PdfNumber(firstChar)); GetPdfObject().Put(PdfName.LastChar, new PdfNumber(lastChar)); PdfArray wd = new PdfArray(); for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] == 0) { wd.Add(new PdfNumber(0)); } else { //prevent lost of widths info int uni = fontEncoding.GetUnicode(k); Glyph glyph = uni > -1 ? GetGlyph(uni) : fontProgram.GetGlyphByCode(k); wd.Add(new PdfNumber(glyph != null ? glyph.GetWidth() : 0)); } } GetPdfObject().Put(PdfName.Widths, wd); } PdfDictionary fontDescriptor = !IsBuiltInFont() ? GetFontDescriptor(fontName) : null; if (fontDescriptor != null) { GetPdfObject().Put(PdfName.FontDescriptor, fontDescriptor); fontDescriptor.Flush(); } }
/** <summary>Gets the embedded file associated to the given key.</summary> */ private EmbeddedFile GetEmbeddedFile( PdfName key ) { PdfDictionary embeddedFilesObject = (PdfDictionary)BaseDictionary[PdfName.EF]; if(embeddedFilesObject == null) return null; return EmbeddedFile.Wrap(embeddedFilesObject[key]); }
/** * A name indicating the position of the label specified by setLabel with respect * to the calculated unit value. The characters * specified by setLabelLeftString and setLabelRightString shall be concatenated before considering this * entry. Default value: suffix. * @param pos PdfName.S or PdfName.P */ virtual public void SetLabelPosition(PdfName pos) { base.Put(PdfName.O, pos); }
/** <see cref="GetDependencies(PdfName)"/> */ private void SetDependencies( PdfName key, RelatedFiles value ) { PdfDictionary dependenciesObject = (PdfDictionary)BaseDictionary[PdfName.RF]; if(dependenciesObject == null) {BaseDictionary[PdfName.RF] = dependenciesObject = new PdfDictionary();} dependenciesObject[key] = value.BaseObject; }
private DeviceColor GetColor( PdfName key ) { return(DeviceColor.Get((PdfArray)BaseDataObject.Resolve(key))); }
/** <summary>Gets the highlighting mode corresponding to the given value.</summary> */ private static HighlightModeEnum ToHighlightModeEnum( PdfName value ) { foreach(KeyValuePair<HighlightModeEnum,PdfName> mode in HighlightModeEnumCodes) { if(mode.Value.Equals(value)) return mode.Key; } return HighlightModeEnum.Invert; }
private PdfDirectObject GetInheritableAttribute( PdfName key ) { return(GetInheritableAttribute(BaseDataObject, key)); }
/** * Returns an entry from the image dictionary. * @param key a key * @return the value */ virtual public PdfObject Get(PdfName key) { return dictionary.Get(key); }
private static bool CheckTypeOfPdfDictionary(PdfObject dictionary, PdfName expectedType) { return(dictionary.IsDictionary() && expectedType.Equals(((PdfDictionary)dictionary).GetAsName(PdfName.Type ))); }
public void Touch( PdfName appName ) { Touch(appName, DateTime.Now); }
/// <summary>Setter for the annotation's preset border style.</summary> /// <remarks> /// Setter for the annotation's preset border style. Possible values are /// <list type="bullet"> /// <item><description> /// <see cref="PdfAnnotation.STYLE_SOLID"/> /// - A solid rectangle surrounding the annotation. /// </description></item> /// <item><description> /// <see cref="PdfAnnotation.STYLE_DASHED"/> /// - A dashed rectangle surrounding the annotation. /// </description></item> /// <item><description> /// <see cref="PdfAnnotation.STYLE_BEVELED"/> /// - A simulated embossed rectangle that appears to be raised above the surface of the page. /// </description></item> /// <item><description> /// <see cref="PdfAnnotation.STYLE_INSET"/> /// - A simulated engraved rectangle that appears to be recessed below the surface of the page. /// </description></item> /// <item><description> /// <see cref="PdfAnnotation.STYLE_UNDERLINE"/> /// - A single line along the bottom of the annotation rectangle. /// </description></item> /// </list> /// See also ISO-320001, Table 166. /// </remarks> /// <param name="style">The new value for the annotation's border style.</param> /// <returns> /// this /// <see cref="PdfCircleAnnotation"/> /// instance. /// </returns> /// <seealso cref="GetBorderStyle()"/> public virtual iText.Kernel.Pdf.Annot.PdfCircleAnnotation SetBorderStyle(PdfName style) { return(SetBorderStyle(BorderStyleUtil.SetStyle(GetBorderStyle(), style))); }
/// <summary> /// Checks whether the rendering intent of the document is within the allowed /// range of intents. /// </summary> /// <remarks> /// Checks whether the rendering intent of the document is within the allowed /// range of intents. This is defined in ISO 19005-1 section 6.2.9, and /// unchanged in newer generations of the PDF/A specification. /// </remarks> /// <param name="intent">the intent to be analyzed</param> public abstract void CheckRenderingIntent(PdfName intent);
public AppData GetAppData( PdfName appName ) { return(AppData.Ensure(appName)); }
/** * Sets the viewer preferences for printing. */ public virtual void AddViewerPreference(PdfName key, PdfObject value) { switch (GetIndex(key)) { case 0: // HIDETOOLBAR case 1: // HIDEMENUBAR case 2: // HIDEWINDOWUI case 3: // FITWINDOW case 4: // CENTERWINDOW case 5: // DISPLAYDOCTITLE case 14: // PICKTRAYBYPDFSIZE if (value is PdfBoolean) { viewerPreferences.Put(key, value); } break; case 6: // NONFULLSCREENPAGEMODE if (value is PdfName && IsPossibleValue((PdfName)value, NONFULLSCREENPAGEMODE_PREFERENCES)) { viewerPreferences.Put(key, value); } break; case 7: // DIRECTION if (value is PdfName && IsPossibleValue((PdfName)value, DIRECTION_PREFERENCES)) { viewerPreferences.Put(key, value); } break; case 8: // VIEWAREA case 9: // VIEWCLIP case 10: // PRINTAREA case 11: // PRINTCLIP if (value is PdfName && IsPossibleValue((PdfName)value, PAGE_BOUNDARIES)) { viewerPreferences.Put(key, value); } break; case 12: // PRINTSCALING if (value is PdfName && IsPossibleValue((PdfName)value, PRINTSCALING_PREFERENCES)) { viewerPreferences.Put(key, value); } break; case 13: // DUPLEX if (value is PdfName && IsPossibleValue((PdfName)value, DUPLEX_PREFERENCES)) { viewerPreferences.Put(key, value); } break; case 15: // PRINTPAGERANGE if (value is PdfArray) { viewerPreferences.Put(key, value); } break; case 16: // NUMCOPIES if (value is PdfNumber) { viewerPreferences.Put(key, value); } break; } }
public static PdfViewerPreferencesImp GetViewerPreferences(PdfDictionary catalog) { PdfViewerPreferencesImp preferences = new PdfViewerPreferencesImp(); int prefs = 0; PdfName name = null; // page layout PdfObject obj = PdfReader.GetPdfObjectRelease(catalog.Get(PdfName.PAGELAYOUT)); if (obj != null && obj.IsName()) { name = (PdfName)obj; if (name.Equals(PdfName.SINGLEPAGE)) { prefs |= PdfWriter.PageLayoutSinglePage; } else if (name.Equals(PdfName.ONECOLUMN)) { prefs |= PdfWriter.PageLayoutOneColumn; } else if (name.Equals(PdfName.TWOCOLUMNLEFT)) { prefs |= PdfWriter.PageLayoutTwoColumnLeft; } else if (name.Equals(PdfName.TWOCOLUMNRIGHT)) { prefs |= PdfWriter.PageLayoutTwoColumnRight; } else if (name.Equals(PdfName.TWOPAGELEFT)) { prefs |= PdfWriter.PageLayoutTwoPageLeft; } else if (name.Equals(PdfName.TWOPAGERIGHT)) { prefs |= PdfWriter.PageLayoutTwoPageRight; } } // page mode obj = PdfReader.GetPdfObjectRelease(catalog.Get(PdfName.PAGEMODE)); if (obj != null && obj.IsName()) { name = (PdfName)obj; if (name.Equals(PdfName.USENONE)) { prefs |= PdfWriter.PageModeUseNone; } else if (name.Equals(PdfName.USEOUTLINES)) { prefs |= PdfWriter.PageModeUseOutlines; } else if (name.Equals(PdfName.USETHUMBS)) { prefs |= PdfWriter.PageModeUseThumbs; } else if (name.Equals(PdfName.FULLSCREEN)) { prefs |= PdfWriter.PageModeFullScreen; } else if (name.Equals(PdfName.USEOC)) { prefs |= PdfWriter.PageModeUseOC; } else if (name.Equals(PdfName.USEATTACHMENTS)) { prefs |= PdfWriter.PageModeUseAttachments; } } // set page layout and page mode preferences preferences.ViewerPreferences = prefs; // other preferences obj = PdfReader.GetPdfObjectRelease(catalog .Get(PdfName.VIEWERPREFERENCES)); if (obj != null && obj.IsDictionary()) { PdfDictionary vp = (PdfDictionary)obj; for (int i = 0; i < VIEWER_PREFERENCES.Length; i++) { obj = PdfReader.GetPdfObjectRelease(vp.Get(VIEWER_PREFERENCES[i])); preferences.AddViewerPreference(VIEWER_PREFERENCES[i], obj); } } return(preferences); }
public static Version Get( PdfName version ) { return Get(version.RawValue); }
/** * Add to the marked content stack * @param tag the tag of the marked content * @param dict the PdfDictionary associated with the marked content * @since 5.0.2 */ private void BeginMarkedContent(PdfName tag, PdfDictionary dict) { markedContentStack.Push(new MarkedContentInfo(tag, dict)); }
public virtual PdfObject Visit( PdfName obj, object data ) { return obj; }
public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands) { PdfName xobjectName = (PdfName)operands[0]; processor.DisplayXObject(xobjectName); }
public void OneFile_LinksToTheNextFile_UpdatesLink(string exeFileName) { HtmlToPdfRunner runner = new HtmlToPdfRunner(exeFileName); string htmlFile2Contents = @" <html> <head> </head> <body> Page 2 </body> </html>"; using (TempHtmlFile htmlFile2 = new TempHtmlFile(htmlFile2Contents)) { string htmlFile1Contents = $@" <html> <head> </head> <body> Page 1 <br/> <a href=""{htmlFile2.FilePath}"">Page 2</a> </body> </html>"; using (TempHtmlFile htmlFile1 = new TempHtmlFile(htmlFile1Contents)) { using (TempPdfFile pdfFile = new TempPdfFile(this.TestContext)) { string commandLine = $"\"{htmlFile1.FilePath}\" \"{htmlFile2.FilePath}\" \"{pdfFile.FilePath}\""; HtmlToPdfRunResult result = runner.Run(commandLine); Assert.AreEqual(0, result.ExitCode, result.Output); using (PdfReader pdfReader = new PdfReader(pdfFile.FilePath)) { using (PdfDocument pdfDocument = new PdfDocument(pdfReader)) { Assert.AreEqual(2, pdfDocument.GetNumberOfPages()); // get the first page PdfPage pdfPage = pdfDocument.GetPage(1); // get link annotations List <PdfLinkAnnotation> linkAnnotations = pdfPage.GetAnnotations().OfType <PdfLinkAnnotation>().ToList(); Assert.AreEqual(1, linkAnnotations.Count); // get the first link annotation PdfLinkAnnotation linkAnnotation = linkAnnotations.ElementAt(0); Assert.IsNotNull(linkAnnotation); // get action PdfDictionary action = linkAnnotation.GetAction(); Assert.IsNotNull(action); // get GoTo sub-type PdfName s = action.GetAsName(PdfName.S); if (exeFileName == HtmlToPdfRunner.HtmlToPdfExe) { Assert.AreEqual(PdfName.GoTo, s); // get destination PdfArray destination = action.GetAsArray(PdfName.D); PdfIndirectReference destinationPageReference = destination.GetAsDictionary(0).GetIndirectReference(); PdfName zoom = destination.GetAsName(1); PdfNumber pageOffset = destination.GetAsNumber(2); // get expected values PdfPage pdfPage2 = pdfDocument.GetPage(2); PdfDictionary page2Dictionary = pdfPage2.GetPdfObject(); PdfIndirectReference expectedPageReference = page2Dictionary.GetIndirectReference(); PdfName expectedZoom = PdfName.FitH; float expectedPageOffset = pdfPage2.GetPageSize().GetTop(); // assert Assert.AreEqual(expectedPageReference, destinationPageReference); Assert.AreEqual(expectedZoom, zoom); Assert.AreEqual(expectedPageOffset, pageOffset.FloatValue()); } else if (exeFileName == HtmlToPdfRunner.WkhtmltopdfExe) { Assert.AreEqual(PdfName.URI, s); PdfString uri = action.GetAsString(PdfName.URI); Assert.AreEqual(htmlFile2.FilePath, HttpUtility.UrlDecode(uri.ToString())); } } } } } } }
public override PdfObject GetDirectObject(PdfName key) { for (int i = resourcesStack.Count - 1; i >= 0; i--){ PdfDictionary subResource = resourcesStack[i]; if (subResource != null){ PdfObject obj = subResource.GetDirectObject(key); if (obj != null) return obj; } } return base.GetDirectObject(key); // shouldn't be necessary, but just in case we've done something crazy }
private void Write(PdfName name) { WriteByte('/'); WriteBytes(name.GetInternalContent()); }
public static LayerMembership.VisibilityPolicyEnum Get( PdfName name ) { if(name == null) return LayerMembership.VisibilityPolicyEnum.AnyOn; LayerMembership.VisibilityPolicyEnum? visibilityPolicy = codes.GetKey(name); if(!visibilityPolicy.HasValue) throw new NotSupportedException("Visibility policy unknown: " + name); return visibilityPolicy.Value; }
public static Version Get( PdfName version ) { return(Get(version.RawValue)); }
/** <summary>Gets the related files associated to the given key.</summary> */ private RelatedFiles GetDependencies( PdfName key ) { PdfDictionary dependenciesObject = (PdfDictionary)BaseDictionary[PdfName.RF]; if(dependenciesObject == null) return null; return RelatedFiles.Wrap(dependenciesObject[key]); }
/// <summary> /// Initialize a new instance /// </summary> public PdfPages() { this["Type"] = new PdfName("Pages"); this["Kids"] = kids = new PdfArray(); }
/** <summary>Gets the path associated to the given key.</summary> */ private string GetPath( PdfName key ) { return (string)PdfSimpleObject<object>.GetValue(BaseDictionary[key]); }
public virtual void PrimitivesTest() { String data = "<</Size 70." + "/Value#20 .1" + "/Root 46 0 R" + "/Info 44 0 R" + "/ID[<736f6d652068657820737472696e672>(some simple string )<8C2547D58D4BD2C6F3D32B830BE3259D2>-70.1--0.2]" + "/Name1 --15" + "/Prev ---116.23 >>"; RandomAccessSourceFactory factory = new RandomAccessSourceFactory(); PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1 )))); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.StartDic); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); PdfName name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("Size", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Number); PdfNumber num = new PdfNumber(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("70.", num.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("Value ", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Number); num = new PdfNumber(tok.GetByteContent()); NUnit.Framework.Assert.AreNotSame("0.1", num.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("Root", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Ref); PdfIndirectReference @ref = new PdfIndirectReference(null, tok.GetObjNr(), tok.GetGenNr()); NUnit.Framework.Assert.AreEqual("46 0 R", @ref.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("Info", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Ref); @ref = new PdfIndirectReference(null, tok.GetObjNr(), tok.GetGenNr()); NUnit.Framework.Assert.AreEqual("44 0 R", @ref.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("ID", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.StartArray); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.String); NUnit.Framework.Assert.AreEqual(tok.IsHexString(), true); PdfString str = new PdfString(tok.GetByteContent(), tok.IsHexString()); NUnit.Framework.Assert.AreEqual("some hex string ", str.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.String); NUnit.Framework.Assert.AreEqual(tok.IsHexString(), false); str = new PdfString(tok.GetByteContent(), tok.IsHexString()); NUnit.Framework.Assert.AreEqual("some simple string ", str.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.String); NUnit.Framework.Assert.AreEqual(tok.IsHexString(), true); str = new PdfString(tok.GetByteContent(), tok.IsHexString()); NUnit.Framework.Assert.AreEqual("\u008C%G\u00D5\u008DK\u00D2\u00C6\u00F3\u00D3+\u0083\u000B\u00E3%\u009D " , str.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Number); num = new PdfNumber(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("-70.1", num.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Number); num = new PdfNumber(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("-0.2", num.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.EndArray); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("Name1", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Number); num = new PdfNumber(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("0", num.ToString()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Name); name = new PdfName(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("Prev", name.GetValue()); tok.NextValidToken(); NUnit.Framework.Assert.AreEqual(tok.GetTokenType(), PdfTokenizer.TokenType.Number); num = new PdfNumber(tok.GetByteContent()); NUnit.Framework.Assert.AreEqual("-116.23", num.ToString()); }
/** <see cref="GetEmbeddedFile(PdfName)"/> */ private void SetEmbeddedFile( PdfName key, EmbeddedFile value ) { PdfDictionary embeddedFilesObject = (PdfDictionary)BaseDictionary[PdfName.EF]; if(embeddedFilesObject == null) {BaseDictionary[PdfName.EF] = embeddedFilesObject = new PdfDictionary();} embeddedFilesObject[key] = value.BaseObject; }
/// <summary>Embed a file to a PdfDocument.</summary> /// <param name="doc">PdfDocument to add the file to</param> /// <param name="fileStore">byte[] containing the file</param> /// <param name="description">file description</param> /// <param name="fileDisplay">actual file name stored in the pdf</param> /// <param name="mimeType">mime-type of the file</param> /// <param name="fileParameter">Pdfdictionary containing fil parameters</param> /// <param name="afRelationshipValue">AFRelationship key value, @see AFRelationshipValue. If <CODE>null</CODE>, @see AFRelationshipValue.Unspecified will be added. /// </param> /// <returns>PdfFileSpec containing the file specification of the file as Pdfobject</returns> public static iText.Kernel.Pdf.Filespec.PdfFileSpec CreateEmbeddedFileSpec(PdfDocument doc, byte[] fileStore , String description, String fileDisplay, PdfName mimeType, PdfDictionary fileParameter, PdfName afRelationshipValue ) { PdfStream stream = (PdfStream) new PdfStream(fileStore).MakeIndirect(doc); PdfDictionary @params = new PdfDictionary(); if (fileParameter != null) { @params.MergeDifferent(fileParameter); } if ([email protected](PdfName.ModDate)) { @params.Put(PdfName.ModDate, new PdfDate().GetPdfObject()); } if (fileStore != null) { @params.Put(PdfName.Size, new PdfNumber(stream.GetBytes().Length)); } stream.Put(PdfName.Params, @params); return(CreateEmbeddedFileSpec(doc, stream, description, fileDisplay, mimeType, afRelationshipValue)); }
public static FullFileSpecification.StandardFileSystemEnum? Get( PdfName code ) { return codes.GetKey(code); }
/// <summary>Embed a file to a PdfDocument.</summary> /// <param name="doc">PdfDocument to add the file to</param> /// <param name="fileStore">byte[] containing the file</param> /// <param name="fileDisplay">actual file name stored in the pdf</param> /// <param name="fileParameter">Pdfdictionary containing fil parameters</param> /// <param name="afRelationshipValue">AFRelationship key value, @see AFRelationshipValue. If <CODE>null</CODE>, @see AFRelationshipValue.Unspecified will be added. /// </param> /// <returns>PdfFileSpec containing the file specification of the file as Pdfobject</returns> public static iText.Kernel.Pdf.Filespec.PdfFileSpec CreateEmbeddedFileSpec(PdfDocument doc, byte[] fileStore , String fileDisplay, PdfDictionary fileParameter, PdfName afRelationshipValue) { return(CreateEmbeddedFileSpec(doc, fileStore, null, fileDisplay, null, fileParameter, afRelationshipValue)); }
/** <summary>Gets the Javascript script from the specified base data object.</summary> */ internal static string GetScript( PdfDictionary baseDataObject, PdfName key ) { PdfDataObject scriptObject = baseDataObject.Resolve(key); if(scriptObject == null) return null; else if(scriptObject is PdfTextString) return ((PdfTextString)scriptObject).StringValue; else { bytes::IBuffer scriptBuffer = ((PdfStream)scriptObject).Body; return scriptBuffer.GetString(0,(int)scriptBuffer.Length); } }
/// <summary>Embed a file to a PdfDocument.</summary> /// <param name="doc">PdfDocument to add the file to</param> /// <param name="fileStore">byte[] containing the file</param> /// <param name="description">file description</param> /// <param name="fileDisplay">actual file name stored in the pdf</param> /// <param name="afRelationshipValue">AFRelationship key value, @see AFRelationshipValue. If <CODE>null</CODE>, @see AFRelationshipValue.Unspecified will be added. /// </param> /// <returns>PdfFileSpec containing the file specification of the file as Pdfobject</returns> public static iText.Kernel.Pdf.Filespec.PdfFileSpec CreateEmbeddedFileSpec(PdfDocument doc, byte[] fileStore , String description, String fileDisplay, PdfName afRelationshipValue) { return(CreateEmbeddedFileSpec(doc, fileStore, description, fileDisplay, null, null, afRelationshipValue)); }
/** Creates a FieldLock instance */ public FieldLock(PdfName action, PdfArray fields) { this.action = action; this.fields = fields; }
/// <summary>Embed a file to a PdfDocument.</summary> /// <param name="doc"/> /// <param name="filePath"/> /// <param name="description"/> /// <param name="fileDisplay"/> /// <param name="mimeType"/> /// <param name="fileParameter"/> /// <param name="afRelationshipValue"/> /// <exception cref="System.IO.IOException"/> public static iText.Kernel.Pdf.Filespec.PdfFileSpec CreateEmbeddedFileSpec(PdfDocument doc, String filePath , String description, String fileDisplay, PdfName mimeType, PdfDictionary fileParameter, PdfName afRelationshipValue ) { PdfStream stream = new PdfStream(doc, UrlUtil.OpenStream(UrlUtil.ToURL(filePath))); PdfDictionary @params = new PdfDictionary(); if (fileParameter != null) { @params.MergeDifferent(fileParameter); } if ([email protected](PdfName.ModDate)) { @params.Put(PdfName.ModDate, new PdfDate().GetPdfObject()); } stream.Put(PdfName.Params, @params); return(CreateEmbeddedFileSpec(doc, stream, description, fileDisplay, mimeType, afRelationshipValue)); }
public byte[] Decode(byte[] b, PdfName filterName, PdfObject decodeParams, PdfDictionary streamDictionary) { lastFilterName = filterName; return b; }
public virtual void SetOutputIntentSubtype(PdfName subtype) { GetPdfObject().Put(PdfName.S, subtype); }