private ImageRenderInfo(GraphicsState gs, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary) { this.gs = gs; this.refi = refi; this.inlineImageInfo = null; this.colorSpaceDictionary = colorSpaceDictionary; }
private ImageRenderInfo(GraphicsState gs, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary) { this.gs = gs; this.refi = null; this.inlineImageInfo = inlineImageInfo; this.colorSpaceDictionary = colorSpaceDictionary; }
virtual public void CacheObject(PdfIndirectReference iref, PdfObject obj) { if (obj.Type == 0) { cachedObjects[new RefKey(iref)] = obj; } else if (obj is PdfDictionary) { cachedObjects[new RefKey(iref)] = CleverPdfDictionaryClone((PdfDictionary) obj); } else if (obj.IsArray()) { cachedObjects[new RefKey(iref)] = CleverPdfArrayClone((PdfArray) obj); } }
/** * Creates a StructureObject for an OBJR dictionary. * @param structElem the parent structure element * @param ref the reference of the parent structure element * @param dict the object reference dictionary */ public StructureObject(PdfDictionary structElem, PdfIndirectReference refa, PdfDictionary dict) { this.structElem = structElem; this.refa = refa; this.obj = dict.GetDirectObject(PdfName.OBJ); this.objref = dict.GetAsIndirectObject(PdfName.OBJ); this.structParent = ((PdfDictionary) obj).GetAsNumber(PdfName.STRUCTPARENT).IntValue; PdfIndirectReference pg = dict.GetAsIndirectObject(PdfName.PG); if (pg == null) pg = structElem.GetAsIndirectObject(PdfName.PG); this.pageref = pg.Number; }
public PdfPageTree(PdfIndirectReference pages, PdfPageTree parent) : base(pages, parent, PdfObjectType.PageTree) { IsContainer = true; var pagetree = pages.Dereference<PdfDictionary>(); pagetree.ExpectsType("Pages"); foreach (PdfKeyValuePair pair in pagetree.Items) { switch (pair.Key.Text) { case "Type": // skip Type Pages break; case "Kids": PdfArray kids = pair.Value as PdfArray; Kids = new List<IPdfObject>(); foreach (PdfIndirectReference item in kids.Items) { var dic = item.Dereference<PdfDictionary>(); String type = dic["Type"].Text; if (type == "Pages") Kids.Add(new PdfPageTree(item, this)); else if (type == "Page") Kids.Add(new PdfPage(item, this)); else throw new Exception("Content of Kids in a Page Tree Node must be either a Page or another Page Tree Node"); } break; case "Count": Count = new PdfCount(pair.Value as PdfNumeric); _items.Add(Count); break; default: HandleKeyValuePair(pair); break; } } _items.AddRange(Kids); }
private ImageRenderInfo(Matrix ctm, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary) { this.ctm = ctm; this.refi = null; this.inlineImageInfo = inlineImageInfo; this.colorSpaceDictionary = colorSpaceDictionary; }
/** * Creates a StructureMCID using an MCID. * @param obj an MCID */ public StructureMCID(PdfIndirectReference pg, PdfNumber mcid) { this.pageref = pg.Number; this.mcid = mcid.IntValue; }
/** * Creates new PdfTemplate * * @param wr the <CODE>PdfWriter</CODE> */ internal PdfTemplate(PdfWriter wr) : base(wr) { type = TYPE_TEMPLATE; pageResources = new PageResources(); pageResources.AddDefaultColor(wr.DefaultColorspace); thisReference = writer.PdfIndirectReference; }
public RefKey(PdfIndirectReference referemce) { num = referemce.Number; gen = referemce.Generation; }
/** * Parses the content of a page, replacing appearances of annotations * with Form XObjects. * @param page a page dictionary * @throws IOException */ virtual public void Parse(PdfDictionary page, PdfIndirectReference pageref) { LOGGER.Info("Parsing page with reference " + pageref); // initializing member variables baos = new MemoryStream(); this.page = page; this.pageref = pageref; structParents = page.GetAsNumber(PdfName.STRUCTPARENTS); if (structParents == null) { throw new DocumentException(MessageLocalization.GetComposedMessage("can.t.read.document.structure")); } annots = page.GetAsArray(PdfName.ANNOTS); if (annots == null) { annots = new PdfArray(); } PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES); xobjects = resources.GetAsDict(PdfName.XOBJECT); if (xobjects == null) { xobjects = new PdfDictionary(); resources.Put(PdfName.XOBJECT, xobjects); } // parsing the content stream of the page PRStream stream = (PRStream)page.GetAsStream(PdfName.CONTENTS); byte[] contentBytes = PdfReader.GetStreamBytes(stream); PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(RASFACTORY.CreateSource(contentBytes))); PdfContentParser ps = new PdfContentParser(tokeniser); List <PdfObject> operands = new List <PdfObject>(); while (ps.Parse(operands).Count > 0) { PdfLiteral opr = (PdfLiteral)operands[operands.Count - 1]; ProcessOperator(opr, operands); } // dealing with orphans while (items.Count > 0 && items[0].GetPageref() == pageref.Number) { StructureItem item = items[0]; if (item is StructureObject) { ConvertToXObject((StructureObject)item); items.RemoveAt(0); } } if (annots.Length == 0) { page.Remove(PdfName.ANNOTS); } else { PdfDictionary annot; for (int i = 0; i < annots.Size; i++) { annot = annots.GetAsDict(i); if (annot.GetAsNumber(PdfName.STRUCTPARENT) == null) { throw new DocumentException(MessageLocalization.GetComposedMessage("could.not.flatten.file.untagged.annotations.found")); } } } // replacing the content stream baos.Flush(); baos.Close(); stream.SetData(baos.ToArray()); // showing how many items are left LOGGER.Info(String.Format("There are {0} items left for processing", items.Count)); }
/** * Create an ImageRenderInfo object based on an XObject (this is the most common way of including an image in PDF) * @param ctm the coordinate transformation matrix at the time the image is rendered * @param ref a reference to the image XObject * @return the ImageRenderInfo representing the rendered XObject * @since 5.0.1 */ public static ImageRenderInfo CreateForXObject(Matrix ctm, PdfIndirectReference refi) { return(new ImageRenderInfo(ctm, refi)); }
void outputDss() { PdfWriter writer = pdfStamper.Writer; PdfReader reader = pdfStamper.Reader; PdfDictionary dss = new PdfDictionary(); PdfDictionary vrim = new PdfDictionary(); PdfArray ocsps = new PdfArray(); PdfArray crls = new PdfArray(); PdfArray certs = new PdfArray(); writer.AddDeveloperExtension(PdfDeveloperExtension.ESIC_1_7_EXTENSIONLEVEL5); writer.AddDeveloperExtension(new PdfDeveloperExtension(PdfName.ADBE, new PdfName("1.7"), 8)); PdfDictionary catalog = reader.Catalog; pdfStamper.MarkUsed(catalog); foreach (PdfName vkey in validated.Keys) { PdfArray ocsp = new PdfArray(); PdfArray crl = new PdfArray(); PdfArray cert = new PdfArray(); PdfDictionary vri = new PdfDictionary(); foreach (byte[] b in validated[vkey].crls) { PdfStream ps = new PdfStream(b); ps.FlateCompress(); PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference; crl.Add(iref); crls.Add(iref); } foreach (byte[] b in validated[vkey].ocsps) { PdfStream ps = new PdfStream(buildOCSPResponse(b)); ps.FlateCompress(); PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference; ocsp.Add(iref); ocsps.Add(iref); } foreach (byte[] b in validated[vkey].certs) { PdfStream ps = new PdfStream(b); ps.FlateCompress(); PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference; cert.Add(iref); certs.Add(iref); } if (ocsp.Length > 0) { vri.Put(PdfName.OCSP, writer.AddToBody(ocsp, false).IndirectReference); } if (crl.Length > 0) { vri.Put(PdfName.CRL, writer.AddToBody(crl, false).IndirectReference); } if (cert.Length > 0) { vri.Put(PdfName.CERT, writer.AddToBody(cert, false).IndirectReference); } vri.Put(PdfName.TU, new PdfDate()); vrim.Put(vkey, writer.AddToBody(vri, false).IndirectReference); } dss.Put(PdfName.VRI, writer.AddToBody(vrim, false).IndirectReference); if (ocsps.Length > 0) { dss.Put(PdfName.OCSPS, writer.AddToBody(ocsps, false).IndirectReference); } if (crls.Length > 0) { dss.Put(PdfName.CRLS, writer.AddToBody(crls, false).IndirectReference); } if (certs.Length > 0) { dss.Put(PdfName.CERTS, writer.AddToBody(certs, false).IndirectReference); } catalog.Put(PdfName.DSS, writer.AddToBody(dss, false).IndirectReference); }
private ImageRenderInfo(Matrix ctm, PdfIndirectReference refi) { this.ctm = ctm; this.refi = refi; }
public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) { ImageRenderInfo renderInfo = new ImageRenderInfo(processor.Gs().ctm, refi); processor.renderListener.RenderImage(renderInfo); }
// --------------------------------------------------------------------------- public void Write(Stream stream) { // step 1 using (Document document = new Document()) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7); writer.AddDeveloperExtension( PdfDeveloperExtension.ADOBE_1_7_EXTENSIONLEVEL3 ); // step 3 document.Open(); // step 4 writer.AddJavaScript(File.ReadAllText(JS)); // we prepare a RichMediaAnnotation RichMediaAnnotation richMedia = new RichMediaAnnotation( writer, new Rectangle(36, 560, 561, 760) ); // we embed the swf file PdfFileSpecification fs = PdfFileSpecification.FileEmbedded( writer, RESOURCE, "FestivalCalendar2.swf", null ); // we declare the swf file as an asset PdfIndirectReference asset = richMedia.AddAsset( "FestivalCalendar2.swf", fs ); // we create a configuration RichMediaConfiguration configuration = new RichMediaConfiguration( PdfName.FLASH ); RichMediaInstance instance = new RichMediaInstance(PdfName.FLASH); instance.Asset = asset; configuration.AddInstance(instance); // we add the configuration to the annotation PdfIndirectReference configurationRef = richMedia.AddConfiguration( configuration ); // activation of the rich media RichMediaActivation activation = new RichMediaActivation(); activation.Configuration = configurationRef; richMedia.Activation = activation; // we add the annotation PdfAnnotation richMediaAnnotation = richMedia.CreateAnnotation(); richMediaAnnotation.Flags = PdfAnnotation.FLAGS_PRINT; writer.AddAnnotation(richMediaAnnotation); String[] days = new String[] { "2011-10-12", "2011-10-13", "2011-10-14", "2011-10-15", "2011-10-16", "2011-10-17", "2011-10-18", "2011-10-19" }; for (int i = 0; i < days.Length; i++) { Rectangle rect = new Rectangle(36 + (65 * i), 765, 100 + (65 * i), 780); PushbuttonField button = new PushbuttonField(writer, rect, "button" + i); button.BackgroundColor = new GrayColor(0.75f); button.BorderStyle = PdfBorderDictionary.STYLE_BEVELED; button.TextColor = GrayColor.GRAYBLACK; button.FontSize = 12; button.Text = days[i]; button.Layout = PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT; button.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS; button.ProportionalIcon = true; button.IconHorizontalAdjustment = 0; PdfFormField field = button.Field; RichMediaCommand command = new RichMediaCommand( new PdfString("getDateInfo") ); command.Arguments = new PdfString(days[i]); RichMediaExecuteAction action = new RichMediaExecuteAction( richMediaAnnotation.IndirectReference, command ); field.Action = action; writer.AddAnnotation(field); } TextField text = new TextField( writer, new Rectangle(36, 785, 559, 806), "date" ); text.Options = TextField.READ_ONLY; writer.AddAnnotation(text.GetTextField()); } }
/** Each spot color used in a document has an instance of this class. * @param colorName the color name * @param indirectReference the indirect reference to the font * @param scolor the <CODE>PDfSpotColor</CODE> */ internal ColorDetails(PdfName colorName, PdfIndirectReference indirectReference, ICachedColorSpace scolor) { this.colorSpaceName = colorName; this.indirectReference = indirectReference; this.colorSpace = scolor; }
/** * Create an ImageRenderInfo object based on an XObject (this is the most common way of including an image in PDF) * @param ctm the coordinate transformation matrix at the time the image is rendered * @param ref a reference to the image XObject * @return the ImageRenderInfo representing the rendered XObject * @since 5.0.1 */ public static ImageRenderInfo CreateForXObject(Matrix ctm, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary){ return new ImageRenderInfo(ctm, refi, colorSpaceDictionary); }
private void OutputDss(PdfDictionary dss, PdfDictionary vrim, PdfArray ocsps, PdfArray crls, PdfArray certs) { writer.AddDeveloperExtension(PdfDeveloperExtension.ESIC_1_7_EXTENSIONLEVEL5); PdfDictionary catalog = reader.Catalog; stp.MarkUsed(catalog); foreach (PdfName vkey in validated.Keys) { PdfArray ocsp = new PdfArray(); PdfArray crl = new PdfArray(); PdfArray cert = new PdfArray(); PdfDictionary vri = new PdfDictionary(); foreach (byte[] b in validated[vkey].crls) { PdfStream ps = new PdfStream(b); ps.FlateCompress(); PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference; crl.Add(iref); crls.Add(iref); } foreach (byte[] b in validated[vkey].ocsps) { PdfStream ps = new PdfStream(b); ps.FlateCompress(); PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference; ocsp.Add(iref); ocsps.Add(iref); } foreach (byte[] b in validated[vkey].certs) { PdfStream ps = new PdfStream(b); ps.FlateCompress(); PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference; cert.Add(iref); certs.Add(iref); } if (ocsp.Size > 0) { vri.Put(PdfName.OCSP, writer.AddToBody(ocsp, false).IndirectReference); } if (crl.Size > 0) { vri.Put(PdfName.CRL, writer.AddToBody(crl, false).IndirectReference); } if (cert.Size > 0) { vri.Put(PdfName.CERT, writer.AddToBody(cert, false).IndirectReference); } vrim.Put(vkey, writer.AddToBody(vri, false).IndirectReference); } dss.Put(PdfName.VRI, writer.AddToBody(vrim, false).IndirectReference); if (ocsps.Size > 0) { dss.Put(PdfName.OCSPS, writer.AddToBody(ocsps, false).IndirectReference); } if (crls.Size > 0) { dss.Put(PdfName.CRLS, writer.AddToBody(crls, false).IndirectReference); } if (certs.Size > 0) { dss.Put(PdfName.CERTS, writer.AddToBody(certs, false).IndirectReference); } catalog.Put(PdfName.DSS, writer.AddToBody(dss, false).IndirectReference); }
public PdfPageTree(PdfIndirectReference pages) : this(pages, null) { }
/** * 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 void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi) { PdfDictionary resources = stream.GetAsDict(PdfName.RESOURCES); // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted // this is probably not necessary (if we fail on this, probably the entire content stream processing // operation should be rejected byte[] contentBytes; contentBytes = ContentByteUtils.GetContentBytesFromContentObject(stream); PdfArray matrix = stream.GetAsArray(PdfName.MATRIX); new PushGraphicsState().Invoke(processor, null, null); if (matrix != null) { float a = matrix.GetAsNumber(0).FloatValue; float b = matrix.GetAsNumber(1).FloatValue; float c = matrix.GetAsNumber(2).FloatValue; float d = matrix.GetAsNumber(3).FloatValue; float e = matrix.GetAsNumber(4).FloatValue; float f = matrix.GetAsNumber(5).FloatValue; Matrix formMatrix = new Matrix(a, b, c, d, e, f); processor.Gs().ctm = formMatrix.Multiply(processor.Gs().ctm); } processor.ProcessContent(contentBytes, resources); new PopGraphicsState().Invoke(processor, null, null); }
/** * Create an ImageRenderInfo object based on an XObject (this is the most common way of including an image in PDF) * @param ctm the coordinate transformation matrix at the time the image is rendered * @param ref a reference to the image XObject * @return the ImageRenderInfo representing the rendered XObject * @since 5.0.1 */ public static ImageRenderInfo CreateForXObject(GraphicsState gs, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary) { return new ImageRenderInfo(gs, refi, colorSpaceDictionary); }
public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi) { PdfDictionary resources = stream.GetAsDict(PdfName.RESOURCES); // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted // this is probably not necessary (if we fail on this, probably the entire content stream processing // operation should be rejected byte[] contentBytes; contentBytes = ContentByteUtils.GetContentBytesFromContentObject(stream); PdfArray matrix = stream.GetAsArray(PdfName.MATRIX); new PushGraphicsState().Invoke(processor, null, null); if (matrix != null){ float a = matrix.GetAsNumber(0).FloatValue; float b = matrix.GetAsNumber(1).FloatValue; float c = matrix.GetAsNumber(2).FloatValue; float d = matrix.GetAsNumber(3).FloatValue; float e = matrix.GetAsNumber(4).FloatValue; float f = matrix.GetAsNumber(5).FloatValue; Matrix formMatrix = new Matrix(a, b, c, d, e, f); processor.Gs().ctm = formMatrix.Multiply(processor.Gs().ctm); } processor.ProcessContent(contentBytes, resources); new PopGraphicsState().Invoke(processor, null, null); }
/** * Parses the content of a page, replacing appearances of annotations * with Form XObjects. * @param page a page dictionary * @throws IOException */ virtual public void Parse(PdfDictionary page, PdfIndirectReference pageref) { LOGGER.Info("Parsing page with reference " + pageref); // initializing member variables baos = new MemoryStream(); this.page = page; this.pageref = pageref; structParents = page.GetAsNumber(PdfName.STRUCTPARENTS); if(structParents == null) throw new DocumentException(MessageLocalization.GetComposedMessage("can.t.read.document.structure")); annots = page.GetAsArray(PdfName.ANNOTS); if(annots == null) annots = new PdfArray(); PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES); xobjects = resources.GetAsDict(PdfName.XOBJECT); if (xobjects == null) { xobjects = new PdfDictionary(); resources.Put(PdfName.XOBJECT, xobjects); } // parsing the content stream of the page PRStream stream = (PRStream) page.GetAsStream(PdfName.CONTENTS); byte[] contentBytes = PdfReader.GetStreamBytes(stream); PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(RASFACTORY.CreateSource(contentBytes))); PdfContentParser ps = new PdfContentParser(tokeniser); List<PdfObject> operands = new List<PdfObject>(); while (ps.Parse(operands).Count > 0) { PdfLiteral opr = (PdfLiteral) operands[operands.Count - 1]; ProcessOperator(opr, operands); } // dealing with orphans while (items.Count > 0 && items[0].GetPageref() == pageref.Number) { StructureItem item = items[0]; if (item is StructureObject) { ConvertToXObject((StructureObject) item); items.RemoveAt(0); } } if(annots.Length == 0) { page.Remove(PdfName.ANNOTS); } else { PdfDictionary annot; for(int i = 0; i < annots.Size; i++) { annot = annots.GetAsDict(i); if(annot.GetAsNumber(PdfName.STRUCTPARENT) == null) throw new DocumentException(MessageLocalization.GetComposedMessage("could.not.flatten.file.untagged.annotations.found")); } } // replacing the content stream baos.Flush(); baos.Close(); stream.SetData(baos.ToArray()); // showing how many items are left LOGGER.Info(String.Format("There are {0} items left for processing", items.Count)); }
public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) { // ignore XObject subtype }
/** * Create an ImageRenderInfo object based on an XObject (this is the most common way of including an image in PDF) * @param ctm the coordinate transformation matrix at the time the image is rendered * @param ref a reference to the image XObject * @return the ImageRenderInfo representing the rendered XObject * @since 5.0.1 */ public static ImageRenderInfo CreateForXObject(Matrix ctm, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary) { return(new ImageRenderInfo(ctm, refi, colorSpaceDictionary)); }
public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) { PdfDictionary colorSpaceDic = processor.resources.GetAsDict(PdfName.COLORSPACE); ImageRenderInfo renderInfo = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi, colorSpaceDic); processor.renderListener.RenderImage(renderInfo); }
/** * Create an ImageRenderInfo object based on an XObject (this is the most common way of including an image in PDF) * @param ctm the coordinate transformation matrix at the time the image is rendered * @param ref a reference to the image XObject * @return the ImageRenderInfo representing the rendered XObject * @since 5.0.1 */ public static ImageRenderInfo CreateForXObject(GraphicsState gs, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary) { return(new ImageRenderInfo(gs, refi, colorSpaceDictionary)); }
private ImageRenderInfo(Matrix ctm, PdfIndirectReference refi, PdfDictionary colorSpaceDictionary) { this.ctm = ctm; this.refi = refi; this.inlineImageInfo = null; this.colorSpaceDictionary = colorSpaceDictionary; }
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())); } } } } } } }