public void AddAnnotation(PdfAnnotation annot) { ArrayList allAnnots = new ArrayList(); if (annot.IsForm()) { PdfFormField field = (PdfFormField)annot; if (field.Parent != null) { return; } ExpandFields(field, allAnnots); if (cstp.fieldTemplates == null) { cstp.fieldTemplates = new Hashtable(); } } else { allAnnots.Add(annot); } for (int k = 0; k < allAnnots.Count; ++k) { annot = (PdfAnnotation)allAnnots[k]; if (annot.IsForm()) { if (!annot.IsUsed()) { Hashtable templates = annot.Templates; if (templates != null) { foreach (object tpl in templates.Keys) { cstp.fieldTemplates[tpl] = null; } } } PdfFormField field = (PdfFormField)annot; if (field.Parent == null) { AddDocumentField(field.IndirectReference); } } if (annot.IsAnnotation()) { PdfObject pdfobj = PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN); PdfArray annots = null; if (pdfobj == null || !pdfobj.IsArray()) { annots = new PdfArray(); pageN.Put(PdfName.ANNOTS, annots); } else { annots = (PdfArray)pdfobj; } annots.Add(annot.IndirectReference); if (!annot.IsUsed()) { PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT); if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0)) { int rotation = reader.GetPageRotation(pageN); Rectangle pageSize = reader.GetPageSizeWithRotation(pageN); switch (rotation) { case 90: annot.Put(PdfName.RECT, new PdfRectangle( pageSize.Top - rect.Bottom, rect.Left, pageSize.Top - rect.Top, rect.Right)); break; case 180: annot.Put(PdfName.RECT, new PdfRectangle( pageSize.Right - rect.Left, pageSize.Top - rect.Bottom, pageSize.Right - rect.Right, pageSize.Top - rect.Top)); break; case 270: annot.Put(PdfName.RECT, new PdfRectangle( rect.Bottom, pageSize.Right - rect.Left, rect.Top, pageSize.Right - rect.Right)); break; } } } } if (!annot.IsUsed()) { annot.SetUsed(); cstp.AddToBody(annot, annot.IndirectReference); } } }
/** * Adds a blank page. * @param rect The page dimension * @param rotation The rotation angle in degrees * @since 2.1.5 */ public void AddPage(Rectangle rect, int rotation) { PdfRectangle mediabox = new PdfRectangle(rect, rotation); PageResources resources = new PageResources(); PdfPage page = new PdfPage(mediabox, new Hashtable(), resources.Resources, 0); page.Put(PdfName.TABS, Tabs); root.AddPage(page); ++currentPageNumber; }
/** * Constructs a <CODE>PdfPage</CODE>. * * @param mediaBox a value for the <B>MediaBox</B> key * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object */ internal PdfPage(PdfRectangle mediaBox, Hashtable boxSize, PdfDictionary resources) : this(mediaBox, boxSize, resources, 0) { }
/** * Rotates the mediabox, but not the text in it. * * @return a <CODE>PdfRectangle</CODE> */ internal PdfRectangle RotateMediaBox() { this.mediaBox = mediaBox.Rotate; Put(PdfName.MEDIABOX, this.mediaBox); return(this.mediaBox); }
/** * Rotates the mediabox, but not the text in it. * * @return a <CODE>PdfRectangle</CODE> */ internal PdfRectangle RotateMediaBox() { this.mediaBox = mediaBox.Rotate; Put(PdfName.MEDIABOX, this.mediaBox); return this.mediaBox; }
// constructors /** * Constructs a <CODE>PdfPage</CODE>. * * @param mediaBox a value for the <B>MediaBox</B> key * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object * @param rotate a value for the <B>Rotate</B> key */ internal PdfPage(PdfRectangle mediaBox, Hashtable boxSize, PdfDictionary resources, int rotate) : base(PAGE) { this.mediaBox = mediaBox; Put(PdfName.MEDIABOX, mediaBox); Put(PdfName.RESOURCES, resources); if (rotate != 0) { Put(PdfName.ROTATE, new PdfNumber(rotate)); } for (int k = 0; k < boxStrings.Length; ++k) { PdfObject rect = (PdfObject)boxSize[boxStrings[k]]; if (rect != null) Put(boxNames[k], rect); } }
/** * Makes a new page and sends it to the <CODE>PdfWriter</CODE>. * * @return a <CODE>bool</CODE> * @throws DocumentException on error */ public override bool NewPage() { lastElementType = -1; if (writer == null || (writer.DirectContent.Size == 0 && writer.DirectContentUnder.Size == 0 && (pageEmpty || writer.IsPaused()))) { SetNewPageSizeAndMargins(); return false; } if (!open || close) { throw new Exception("The document isn't open."); } IPdfPageEvent pageEvent = writer.PageEvent; if (pageEvent != null) pageEvent.OnEndPage(writer, this); //Added to inform any listeners that we are moving to a new page (added by David Freels) base.NewPage(); // the following 2 lines were added by Pelikan Stephan indentation.imageIndentLeft = 0; indentation.imageIndentRight = 0; // we flush the arraylist with recently written lines FlushLines(); // we prepare the elements of the page dictionary // [U1] page size and rotation int rotation = pageSize.Rotation; // [C10] if (writer.IsPdfX()) { if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim")) throw new PdfXConformanceException("Only one of ArtBox or TrimBox can exist in the page."); if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) { if (thisBoxSize.ContainsKey("crop")) thisBoxSize["trim"] = thisBoxSize["crop"]; else thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation); } } // [M1] pageResources.AddDefaultColorDiff(writer.DefaultColorspace); if (writer.RgbTransparencyBlending) { PdfDictionary dcs = new PdfDictionary(); dcs.Put(PdfName.CS, PdfName.DEVICERGB); pageResources.AddDefaultColorDiff(dcs); } PdfDictionary resources = pageResources.Resources; // we create the page dictionary PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation); page.Put(PdfName.TABS, writer.Tabs); // we complete the page dictionary // [C9] if there is XMP data to add: add it if (xmpMetadata != null) { PdfStream xmp = new PdfStream(xmpMetadata); xmp.Put(PdfName.TYPE, PdfName.METADATA); xmp.Put(PdfName.SUBTYPE, PdfName.XML); PdfEncryption crypto = writer.Encryption; if (crypto != null && !crypto.IsMetadataEncrypted()) { PdfArray ar = new PdfArray(); ar.Add(PdfName.CRYPT); xmp.Put(PdfName.FILTER, ar); } page.Put(PdfName.METADATA, writer.AddToBody(xmp).IndirectReference); } // [U3] page actions: transition, duration, additional actions if (this.transition!=null) { page.Put(PdfName.TRANS, this.transition.TransitionDictionary); transition = null; } if (this.duration>0) { page.Put(PdfName.DUR,new PdfNumber(this.duration)); duration = 0; } if (pageAA != null) { page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference); pageAA = null; } // [U4] we add the thumbs if (thumb != null) { page.Put(PdfName.THUMB, thumb); thumb = null; } // [U8] we check if the userunit is defined if (writer.Userunit > 0f) { page.Put(PdfName.USERUNIT, new PdfNumber(writer.Userunit)); } // [C5] and [C8] we add the annotations if (annotationsImp.HasUnusedAnnotations()) { PdfArray array = annotationsImp.RotateAnnotations(writer, pageSize); if (array.Size != 0) page.Put(PdfName.ANNOTS, array); } // [F12] we add tag info if (writer.IsTagged()) page.Put(PdfName.STRUCTPARENTS, new PdfNumber(writer.CurrentPageNumber - 1)); if (text.Size > textEmptySize) text.EndText(); else text = null; writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, text, writer.DirectContent, pageSize)); // we initialize the new page InitPage(); return true; }
internal void SetBoxSize(String boxName, Rectangle size) { if (size == null) boxSize.Remove(boxName); else boxSize[boxName] = new PdfRectangle(size); }