public static void CropPdf() { var xll = 200; var yll = 170; var w = 800; var h = 800; var reader = new iTextSharp.text.pdf.PdfReader(@"C:\Projects\31g\trunk\temp\pdf\20140208110036_20.pdf"); var n = reader.NumberOfPages; iTextSharp.text.pdf.PdfDictionary pageDict; var pfgRect = new iTextSharp.text.pdf.PdfRectangle(xll, yll, w, h); for (var i = 1; i <= n; i++) { pageDict = reader.GetPageN(i); pageDict.Put(iTextSharp.text.pdf.PdfName.CROPBOX, pfgRect); } var stamper = new iTextSharp.text.pdf.PdfStamper(reader, new System.IO.FileStream(string.Format(@"C:\Projects\31g\trunk\Notes\misc\Maps\Europe_565BCE.pdf", xll, yll, w, h), FileMode.Create)); stamper.Close(); reader.Close(); }
// --------------------------------------------------------------------------- /** * Manipulates a PDF file src with the file dest as result * @param src the original PDF */ public byte[] ManipulatePdf(byte[] src) { PdfReader reader = new PdfReader(src); int n = reader.NumberOfPages; PdfDictionary pageDict; PdfRectangle rect = new PdfRectangle(55, 76, 560, 816); for (int i = 1; i <= n; i++) { pageDict = reader.GetPageN(i); pageDict.Put(PdfName.CROPBOX, rect); } using (MemoryStream ms = new MemoryStream()) { using (PdfStamper stamper = new PdfStamper(reader, ms)) { } return ms.ToArray(); } }
/// <summary> /// Rotates the mediabox, but not the text in it. /// </summary> /// <returns>a PdfRectangle </returns> internal PdfRectangle RotateMediaBox() { MediaBox = MediaBox.Rotate; Put(PdfName.Mediabox, MediaBox); return(MediaBox); }
internal void SetBoxSize(String boxName, Rectangle size) { if (size == null) boxSize.Remove(boxName); else boxSize[boxName] = new PdfRectangle(size); }
// 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, Dictionary<string, PdfRectangle> 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) { if (!boxSize.ContainsKey(boxStrings[k])) continue; Put(boxNames[k], boxSize[boxStrings[k]]); } }
/** * 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, Dictionary<string, PdfRectangle> boxSize, PdfDictionary resources) : this(mediaBox, boxSize, resources, 0) { }
private void WriteAttributes(Image image) { if (image != null) { if (image.Width > 0) this.SetAttribute(PdfName.WIDTH, new PdfNumber(image.Width)); if (image.Height > 0) this.SetAttribute(PdfName.HEIGHT, new PdfNumber(image.Height)); image.Rotation = 10; image.Rotation = 10f; PdfRectangle rect = new PdfRectangle(image, ((Rectangle) image).Rotation); this.SetAttribute(PdfName.BBOX, rect); if (image.Alt != null) Put(PdfName.ALT, new PdfString(image.Alt)); if (image.BackgroundColor != null) { BaseColor color = image.BackgroundColor; this.SetAttribute(PdfName.BACKGROUNDCOLOR, new PdfArray(new float[] { color.R / 255f, color.G / 255f, color.B / 255f })); } } }
// 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 * @throws DocumentException */ internal PdfPage(PdfRectangle mediaBox, Dictionary<string, PdfRectangle> boxSize, PdfDictionary resources, int rotate) : base(PAGE) { this.mediaBox = mediaBox; if (mediaBox != null && (mediaBox.Width > 14400 || mediaBox.Height > 14400)) { throw new DocumentException(MessageLocalization.GetComposedMessage("the.page.size.must.be.smaller.than.14400.by.14400.its.1.by.2", mediaBox.Width, mediaBox.Height)); } 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) { if (!boxSize.ContainsKey(boxStrings[k])) continue; Put(boxNames[k], boxSize[boxStrings[k]]); } }
// 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); } }
/// <summary> /// Rotates the mediabox, but not the text in it. /// </summary> /// <returns>a PdfRectangle </returns> internal PdfRectangle RotateMediaBox() { _mediaBox = _mediaBox.Rotate; Put(PdfName.Mediabox, _mediaBox); return(_mediaBox); }
public List<LocationModel> ReadPdfFile(String fileName) { string strText = string.Empty; PdfReader reader = new PdfReader(fileName); var locationList = new List<LocationModel>(); for (int page = 1; page <= reader.NumberOfPages; page++) { var p = reader.GetPageN(page); var pageSize = reader.GetPageSizeWithRotation(page); var rotation = pageSize.Rotation; float factor; if (pageSize.Height > pageSize.Width) { //Portait factor = 2000 / pageSize.Width; } else{ //landscape factor = 1700 / pageSize.Height; } var annotationList = p.GetAsArray(iTextSharp.text.pdf.PdfName.ANNOTS); ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage(reader, page, strategy); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); foreach (PdfObject annot in annotationList.ArrayList) { PdfDictionary annotationDict = (PdfDictionary)PdfReader.GetPdfObject(annot); var subtype = annotationDict.Get(PdfName.SUBTYPE); if (subtype == PdfName.FREETEXT) { var content = annotationDict.GetAsString(PdfName.CONTENTS); var tmp = annotationDict.GetAsArray(PdfName.RECT); var rect = new PdfRectangle(tmp.GetAsNumber(0).FloatValue, tmp.GetAsNumber(1).FloatValue, tmp.GetAsNumber(2).FloatValue, tmp.GetAsNumber(3).FloatValue); var left = Convert.ToDouble(rect.Right); var top = Convert.ToDouble(pageSize.Height - rect.Top); // Convert Bottom to Top Coordinate System //Comment this line if the coordinate is weird /* if (rotation == 90) { left = pageSize.Height > pageSize.Width ? Convert.ToDouble(rect[3].ToString()) : pageSize.Height - float.Parse(rect[2].ToString()); top = pageSize.Height > pageSize.Width ? float.Parse(rect[2].ToString()) : float.Parse(rect[3].ToString()); } */ //Comment this line if the coordinate is weird //left = Convert.ToDouble(rect[3].ToString()); //top = Convert.ToDouble(rect[0].ToString()); var offsetX = 30; var offsetY = 20; var location = new LocationModel { X = Convert.ToInt32(Double.Parse(left.ToString()) * factor) + offsetX, Y = Convert.ToInt32(Double.Parse(top.ToString()) * factor) + offsetY, Title = content.ToString() }; locationList.Add(location); } } } reader.Close(); return locationList; }
/** * 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, Rectangle cropBox, PdfResources resources) : this(mediaBox, cropBox, resources, null) { }
/** * 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, Rectangle cropBox, PdfIndirectReference resources) : this(mediaBox, cropBox, resources, null) { }
/** * 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; isNewpage = true; if (writer == null || (writer.DirectContent.Size == 0 && writer.DirectContentUnder.Size == 0 && (pageEmpty || writer.IsPaused()))) { 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 imageIndentLeft = 0; 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); PdfDictionary resources = pageResources.Resources; // we create the page dictionary PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation); // we complete the page dictionary // [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(); isNewpage = false; return true; }
private void WriteAttributes(Image image) { if (image != null) { if (image.Width > 0) this.SetAttribute(PdfName.WIDTH, new PdfNumber(image.Width)); if (image.Height > 0) this.SetAttribute(PdfName.HEIGHT, new PdfNumber(image.Height)); image.Rotation = 10; image.Rotation = 10f; PdfRectangle rect = new PdfRectangle(image, ((Rectangle) image).Rotation); this.SetAttribute(PdfName.BBOX, rect); if (image.Alt != null) Put(PdfName.ALT, new PdfString(image.Alt)); } }
public void ApplyCTM(System.Drawing.Drawing2D.Matrix ctm) { PdfArray origRect = GetAsArray(PdfName.RECT); if(origRect != null) { PdfRectangle rect; if(origRect.Size == 4) { rect = new PdfRectangle(origRect.GetAsNumber(0).FloatValue, origRect.GetAsNumber(1).FloatValue, origRect.GetAsNumber(2).FloatValue, origRect.GetAsNumber(3).FloatValue); } else { rect = new PdfRectangle(origRect.GetAsNumber(0).FloatValue, origRect.GetAsNumber(1).FloatValue); } Put(PdfName.RECT, rect.Transform(ctm)); } }
/** * 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) { }
/// <summary> /// Constructs a PdfPage . /// </summary> /// <param name="mediaBox">a value for the <B>MediaBox</B> key</param> /// <param name="boxSize"></param> /// <param name="resources">an indirect reference to a PdfResources -object</param> internal PdfPage(PdfRectangle mediaBox, Hashtable boxSize, PdfDictionary resources) : this(mediaBox, boxSize, resources, 0) { }
private void WriteAttributes(PdfTemplate template) { if (template != null) { this.SetAttribute(PdfName.O, PdfName.LAYOUT); if (template.Width > 0) { this.SetAttribute(PdfName.WIDTH, new PdfNumber(template.Width)); } if (template.Height > 0) { this.SetAttribute(PdfName.HEIGHT, new PdfNumber(template.Height)); } PdfRectangle rect = new PdfRectangle(template.BoundingBox); this.SetAttribute(PdfName.BBOX, rect); } }
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); } } }
virtual public PdfArray RotateAnnotations(PdfWriter writer, Rectangle pageSize) { PdfArray array = new PdfArray(); int rotation = pageSize.Rotation % 360; int currentPage = writer.CurrentPageNumber; for (int k = 0; k < annotations.Count; ++k) { PdfAnnotation dic = annotations[k]; int page = dic.PlaceInPage; if (page > currentPage) { delayedAnnotations.Add(dic); continue; } if (dic.IsForm()) { if (!dic.IsUsed()) { Dictionary<PdfTemplate,object> templates = dic.Templates; if (templates != null) acroForm.AddFieldTemplates(templates); } PdfFormField field = (PdfFormField)dic; if (field.Parent == null) acroForm.AddDocumentField(field.IndirectReference); } if (dic.IsAnnotation()) { array.Add(dic.IndirectReference); if (!dic.IsUsed()) { PdfArray tmp = dic.GetAsArray(PdfName.RECT); PdfRectangle rect; if (tmp.Size == 4) { rect = new PdfRectangle(tmp.GetAsNumber(0).FloatValue, tmp.GetAsNumber(1).FloatValue, tmp.GetAsNumber(2).FloatValue, tmp.GetAsNumber(3).FloatValue); } else { rect = new PdfRectangle(tmp.GetAsNumber(0).FloatValue, tmp.GetAsNumber(1).FloatValue); } if (rect != null) { switch (rotation) { case 90: dic.Put(PdfName.RECT, new PdfRectangle( pageSize.Top - rect.Bottom, rect.Left, pageSize.Top - rect.Top, rect.Right)); break; case 180: dic.Put(PdfName.RECT, new PdfRectangle( pageSize.Right - rect.Left, pageSize.Top - rect.Bottom, pageSize.Right - rect.Right, pageSize.Top - rect.Top)); break; case 270: dic.Put(PdfName.RECT, new PdfRectangle( rect.Bottom, pageSize.Right - rect.Left, rect.Top, pageSize.Right - rect.Right)); break; } } } } if (!dic.IsUsed()) { dic.SetUsed(); writer.AddToBody(dic, dic.IndirectReference); } } return array; }
/** * 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 * @throws DocumentException */ internal PdfPage(PdfRectangle mediaBox, Dictionary <string, PdfRectangle> boxSize, PdfDictionary resources) : this(mediaBox, boxSize, resources, 0) { }
/** * Adds a blank page. * @param rect The page dimension * @param rotation The rotation angle in degrees * @since 2.1.5 * @throws DocumentException */ public void AddPage(Rectangle rect, int rotation) { if (mergeFields && !mergeFieldsInternalCall) { throw new ArgumentException(MessageLocalization.GetComposedMessage("1.method.cannot.be.used.in.mergeFields.mode.please.use.addDocument", "addPage")); } PdfRectangle mediabox = new PdfRectangle(rect, rotation); PageResources resources = new PageResources(); PdfPage page = new PdfPage(mediabox, new Dictionary<String, PdfRectangle>(), resources.Resources, 0); page.Put(PdfName.TABS, Tabs); root.AddPage(page); ++currentPageNumber; }
/** * 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; }
public IList<IAccessibleElement> EndPage() { if (PageEmpty) { return null; } IList<IAccessibleElement> savedMcBlocks = null; FlushFloatingElements(); lastElementType = -1; IPdfPageEvent pageEvent = writer.PageEvent; if (pageEvent != null) pageEvent.OnEndPage(writer, this); // 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.IsPdfIso()) { if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim")) throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("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); if (IsTagged(writer)) { page.Put(PdfName.TABS, PdfName.S); } else { page.Put(PdfName.TABS, writer.Tabs); } page.Merge(writer.PageDictEntries); writer.ResetPageDictEntries(); // we complete the page dictionary // [U3] page actions: additional actions if (pageAA != null) { page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference); pageAA = null; } // [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 (IsTagged(writer)) page.Put(PdfName.STRUCTPARENTS, new PdfNumber(GetStructParentIndex(writer.CurrentPage))); if (text.Size > textEmptySize || IsTagged(writer)) text.EndText(); else text = null; if (IsTagged(writer)) { savedMcBlocks = writer.DirectContent.SaveMCBlocks(); } writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, !IsTagged(writer) ? text : null, writer.DirectContent, pageSize)); annotationsImp.ResetAnnotations(); writer.ResetContent(); return savedMcBlocks; }
/** * 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 Dictionary<String, PdfRectangle>(), resources.Resources, 0); page.Put(PdfName.TABS, Tabs); root.AddPage(page); ++currentPageNumber; }
virtual public void ApplyCTM(AffineTransform ctm) { PdfArray origRect = GetAsArray(PdfName.RECT); if(origRect != null) { PdfRectangle rect; if(origRect.Size == 4) { rect = new PdfRectangle(origRect.GetAsNumber(0).FloatValue, origRect.GetAsNumber(1).FloatValue, origRect.GetAsNumber(2).FloatValue, origRect.GetAsNumber(3).FloatValue); } else { rect = new PdfRectangle(origRect.GetAsNumber(0).FloatValue, origRect.GetAsNumber(1).FloatValue); } Put(PdfName.RECT, rect.Transform(ctm)); } }
/** * 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() { FlushFloatingElements(); lastElementType = -1; if (PageEmpty) { SetNewPageSizeAndMargins(); return false; } if (!open || close) { throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.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.IsPdfIso()) { if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim")) throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("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); if (IsTagged(writer)) { page.Put(PdfName.TABS, PdfName.S); } else { page.Put(PdfName.TABS, writer.Tabs); } page.Merge(writer.PageDictEntries); writer.ResetPageDictEntries(); // we complete the page dictionary // [U3] page actions: additional actions if (pageAA != null) { page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference); pageAA = null; } // [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 (IsTagged(writer)) page.Put(PdfName.STRUCTPARENTS, new PdfNumber(GetStructParentIndex(writer.CurrentPage))); if (text.Size > textEmptySize || IsTagged(writer)) text.EndText(); else text = null; IList<IAccessibleElement> mcBlocks = null; if (IsTagged(writer)) { mcBlocks = writer.DirectContent.SaveMCBlocks(); } writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, !IsTagged(writer) ? text : null, writer.DirectContent, pageSize)); // we initialize the new page InitPage(); if (IsTagged(writer)) { writer.DirectContentUnder.RestoreMCBlocks(mcBlocks); } return true; }
/** * 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 (PageEmpty) { SetNewPageSizeAndMargins(); return false; } if (!open || close) { throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.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(MessageLocalization.GetComposedMessage("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; }