/// <summary>Sets the /P and /A values corresponding to provided annotation, which is already added to a page. /// </summary> /// <param name="pdfAnnotation">the annotation to be set</param> /// <param name="pdfDocument">the corresponding document</param> /// <returns>this object wrapper</returns> public virtual iText.Kernel.Pdf.Action.PdfTarget SetAnnotation(PdfFileAttachmentAnnotation pdfAnnotation, PdfDocument pdfDocument) { PdfPage page = pdfAnnotation.GetPage(); if (null == page) { throw new PdfException(PdfException.AnnotationShallHaveReferenceToPage); } else { Put(PdfName.P, new PdfNumber(pdfDocument.GetPageNumber(page) - 1)); int indexOfAnnotation = -1; IList <PdfAnnotation> annots = page.GetAnnotations(); for (int i = 0; i < annots.Count; i++) { if (annots[i] != null && pdfAnnotation.GetPdfObject().Equals(annots[i].GetPdfObject())) { indexOfAnnotation = i; break; } } Put(PdfName.A, new PdfNumber(indexOfAnnotation)); } return(this); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Rectangle rect = new Rectangle(36, 700, 100, 100); String embeddedFileName = "test.docx"; // the 3rd argument is the file description. // the 5th argument is the mime-type of the embedded file; // the 6th argument is the AFRelationship key value. PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDoc, PATH, null, embeddedFileName, null, null); PdfAnnotation attachment = new PdfFileAttachmentAnnotation(rect, fileSpec); // This method sets the text that will be displayed for the annotation or the alternate description, // if this type of annotation does not display text. attachment.SetContents("Click me"); // Create XObject and draw it with the imported image on the canvas // to add XObject as normal appearance. PdfFormXObject xObject = new PdfFormXObject(rect); ImageData imageData = ImageDataFactory.Create(IMG); PdfCanvas canvas = new PdfCanvas(xObject, pdfDoc); canvas.AddImageFittedIntoRectangle(imageData, rect, true); attachment.SetNormalAppearance(xObject.GetPdfObject()); pdfDoc.AddNewPage().AddAnnotation(attachment); pdfDoc.Close(); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (PdfDocument pdf = new PdfDocument(@"Sample Data\Attachments.pdf")) { StringBuilder attachmentNames = new StringBuilder(); // collect names of files attached to the document foreach (PdfFileSpecification spec in pdf.SharedAttachments) { attachmentNames.AppendLine(spec.Specification); } // collect names of files used in file attachment annotations foreach (PdfPage page in pdf.Pages) { foreach (PdfWidget widget in page.Widgets) { if (widget.Type != PdfWidgetType.FileAttachment) { continue; } PdfFileAttachmentAnnotation fileAnnot = (PdfFileAttachmentAnnotation)widget; attachmentNames.AppendLine(fileAnnot.File.Specification); } } MessageBox.Show(attachmentNames.ToString(), "Attachments List"); } }
public virtual void GetAnnotationSetAsIntsTest() { using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { int pageNumber = 1; int annotationIndex = 0; PdfTarget target = PdfTarget.CreateChildTarget(pageNumber, annotationIndex); PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20)); document.AddNewPage(); document.GetPage(1).AddAnnotation(annotation); NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), target.GetAnnotation(document).GetPdfObject()); } }
public virtual void GetAnnotationSetAsAnnotationTest() { using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20)); document.AddNewPage(); document.GetPage(1).AddAnnotation(annotation); PdfDictionary content = new PdfDictionary(); content.Put(new PdfName("Key"), new PdfString("Value")); PdfTarget target = PdfTarget.Create(new PdfDictionary()); target.SetAnnotation(annotation, document); NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), target.GetAnnotation(document).GetPdfObject()); } }
public virtual void SetAnnotationWithoutPageTest() { NUnit.Framework.Assert.That(() => { using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { document.AddNewPage(); PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20)); PdfTarget target = PdfTarget.Create(new PdfDictionary()); target.SetAnnotation(annotation, document); } } , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(PdfException.AnnotationShallHaveReferenceToPage)) ; }
public virtual void GetAnnotationSetAsStringTest() { using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { String namedDestination = "namedDestination"; String annotationIdentifier = "annotationIdentifier"; PdfTarget target = PdfTarget.CreateChildTarget(namedDestination, annotationIdentifier); PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20)); annotation.SetName(new PdfString(annotationIdentifier)); document.AddNewPage(); document.GetPage(1).AddAnnotation(annotation); document.GetCatalog().GetNameTree(PdfName.Dests).AddEntry(namedDestination, new PdfArray(new PdfNumber(1)) ); PdfAnnotation retrievedAnnotation = target.GetAnnotation(document); NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), retrievedAnnotation.GetPdfObject()); } }
public virtual void AnnotationCheckTest01() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 650, 400, 100); PdfAnnotation annot = new PdfFileAttachmentAnnotation(rect); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_CONTAIN_THE_F_KEY)) ; }
/// <summary>Sets the /P and /A values corresponding to provided annotation, which is already added to a page. /// </summary> /// <param name="pdfAnnotation">the annotation to be set</param> /// <param name="pdfDocument">the corresponding document</param> /// <returns>this object wrapper</returns> public virtual iText.Kernel.Pdf.Action.PdfTarget SetAnnotation(PdfFileAttachmentAnnotation pdfAnnotation, PdfDocument pdfDocument) { PdfPage page = pdfAnnotation.GetPage(); if (null == page) { throw new PdfException(PdfException.AnnotationShallHaveReferenceToPage); } else { Put(PdfName.P, new PdfNumber(pdfDocument.GetPageNumber(page))); Put(PdfName.A, new PdfNumber(page.GetAnnotations().IndexOf(pdfAnnotation))); } return(this); }
public virtual void AnnotationCheckTest01() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfAnnotation annot = new PdfFileAttachmentAnnotation(rect); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_TYPE_0_IS_NOT_PERMITTED, PdfName.FileAttachment.GetValue()))); ; }
public virtual void SetAnnotationTest() { using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { PdfFileAttachmentAnnotation annotation0 = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20)); PdfFileAttachmentAnnotation annotation1 = new PdfFileAttachmentAnnotation(new Rectangle(1, 1, 21, 21)); PdfFileAttachmentAnnotation annotation2 = new PdfFileAttachmentAnnotation(new Rectangle(2, 2, 22, 22)); document.AddNewPage(); document.GetPage(1).AddAnnotation(annotation0); document.GetPage(1).AddAnnotation(annotation1); document.GetPage(1).AddAnnotation(annotation2); PdfTarget target = PdfTarget.Create(new PdfDictionary()); target.SetAnnotation(annotation2, document); PdfDictionary dictionary = target.GetPdfObject(); NUnit.Framework.Assert.AreEqual(0, dictionary.GetAsNumber(PdfName.P).IntValue()); NUnit.Framework.Assert.AreEqual(2, dictionary.GetAsNumber(PdfName.A).IntValue()); } }
/// <summary>Gets the annotation specified by /A and /P entry values.</summary> /// <param name="pdfDocument">specifies the corresponding document</param> /// <returns>the annotation specified by /A and /P entry value.</returns> public virtual PdfFileAttachmentAnnotation GetAnnotation(PdfDocument pdfDocument) { PdfObject pValue = GetPdfObject().Get(PdfName.P); PdfPage page = null; if (pValue is PdfNumber) { // zero-based index is used page = pdfDocument.GetPage(((PdfNumber)pValue).IntValue() + 1); } else { if (pValue is PdfString) { PdfNameTree destsTree = pdfDocument.GetCatalog().GetNameTree(PdfName.Dests); IDictionary <String, PdfObject> dests = destsTree.GetNames(); PdfArray pdfArray = (PdfArray)dests.Get(((PdfString)pValue).GetValue()); if (null != pdfArray) { if (pdfArray.Get(0) is PdfNumber) { page = pdfDocument.GetPage(((PdfNumber)pdfArray.Get(0)).IntValue()); } else { page = pdfDocument.GetPage((PdfDictionary)pdfArray.Get(0)); } } } } IList <PdfAnnotation> pageAnnotations = null; if (null != page) { pageAnnotations = page.GetAnnotations(); } PdfObject aValue = GetPdfObject().Get(PdfName.A); PdfFileAttachmentAnnotation resultAnnotation = null; if (null != pageAnnotations) { if (aValue is PdfNumber) { resultAnnotation = (PdfFileAttachmentAnnotation)pageAnnotations[((PdfNumber)aValue).IntValue()]; } else { if (aValue is PdfString) { foreach (PdfAnnotation annotation in pageAnnotations) { if (aValue.Equals(annotation.GetName())) { resultAnnotation = (PdfFileAttachmentAnnotation)annotation; break; } } } } } if (null == resultAnnotation) { ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Pdf.Action.PdfTarget)); logger.Error(iText.IO.LogMessageConstant.SOME_TARGET_FIELDS_ARE_NOT_SET_OR_INCORRECT); } return(resultAnnotation); }
private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); Random rnd = new Random(); // Random binary data to be used a file content for file attachment annotations. byte[] fileData = new byte[256]; PdfPage page = document.Pages.Add(); string[] fileAttachmentAnnotationNames = new string[] { "Graph", "Paperclip", "PushPin", "Tag" }; page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation(); faa.Author = "Xfinium.Pdf"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat"; page.Annotations.Add(faa); faa.Location = new PdfPoint(50, 100 + 40 * i); page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } byte[] rgb = new byte[3]; page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation(); faa.Author = "Xfinium.Pdf"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat"; rnd.NextBytes(rgb); faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(faa); faa.Location = new PdfPoint(300, 100 + 40 * i); page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700); PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation(); customFileAttachmentAnnotation.Author = "Xfinium.Pdf"; customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon."; page.Annotations.Add(customFileAttachmentAnnotation); customFileAttachmentAnnotation.IconName = "Custom icon appearance"; customFileAttachmentAnnotation.Location = new PdfPoint(50, 720); PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50); PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10); PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10); customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Graphics.CompressAndClose(); customFileAttachmentAnnotation.NormalAppearance = customAppearance; }
private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); Random rnd = new Random(); // Random binary data to be used a file content for file attachment annotations. byte[] fileData = new byte[256]; PdfPage page = document.Pages.Add(); string[] fileAttachmentAnnotationNames = new string[] { "Graph", "Paperclip", "PushPin", "Tag" }; page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation(); faa.Author = "Xfinium.Pdf"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat"; page.Annotations.Add(faa); faa.Location = new PdfPoint(50, 100 + 40 * i); page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } byte[] rgb = new byte[3]; page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation(); faa.Author = "Xfinium.Pdf"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat"; rnd.NextBytes(rgb); faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(faa); faa.Location = new PdfPoint(300, 100 + 40 * i); page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700); PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation(); customFileAttachmentAnnotation.Author = "Xfinium.Pdf"; customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon."; page.Annotations.Add(customFileAttachmentAnnotation); customFileAttachmentAnnotation.IconName = "Custom icon appearance"; customFileAttachmentAnnotation.Location = new PdfPoint(50, 720); PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50); PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10); PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10); customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Graphics.CompressAndClose(); customFileAttachmentAnnotation.NormalAppearance = customAppearance; }
/// <summary> /// Exports the inner. /// </summary> /// <param name="stream">The stream</param> /// <param name="doc">The doc.</param> /// <param name="saveAuto">if set to <c>true</c> [save auto].</param> /// <param name="checkEmpty">if set to <c>true</c> [check empty].</param> /// <param name="processSettings">if set to <c>true</c> [process settings].</param> /// <param name="otfu">The otfu.</param> /// <param name="frc">The FRC.</param> /// <param name="pageCount">The page count.</param> internal void ExportInner(Stream stream, PdfDocument doc, bool saveAuto, bool checkEmpty, bool processSettings, OpenTypeFontUtility otfu, GcReportContext frc, int pageCount) { bool flag2; doc = doc ?? CreatePdfDocument(); this.currentDoc = doc; if (processSettings) { this.settings.AppendTo(doc); } bool flag = false; if (otfu != null) { this.openTypeFontUtility = otfu; this.openTypeFontUtility.Dpi = this.Dpi; } else { this.openTypeFontUtility = new OpenTypeFontUtility(GcReportContext.defaultFont, this.Dpi); flag = true; this.openTypeFontUtility.ExternalFont += this.ExternalFont; } if (frc != null) { this.context = frc; } else { GcReportContext context = new GcReportContext(this.report, this.Dpi, this.openTypeFontUtility) { UnitsPerInch = 0x48 }; this.context = context; this.context.GeneratePageBlocks(); } if (this.report.Watermark != null) { this.report.Watermark.Height = (int)this.context.PageRects.PageRectangle.Height; this.report.Watermark.Width = (int)this.context.PageRects.PageRectangle.Width; } ExporterState state = new ExporterState(this.context) { BlackAndWhite = this.report.BlackAndWhite }; int num = 0; foreach (List <GcPageBlock> list in this.context.Pages) { state.PageCount += list.Count; num = Math.Max(list.Count, num); } if (pageCount >= 0) { state.PageCount = pageCount; } else { state.PageCount += this.report.FirstPageNumber - 1; } switch (this.context.Report.PageOrder) { case PrintPageOrder.Auto: flag2 = this.context.Pages.Count >= num; break; case PrintPageOrder.DownThenOver: flag2 = true; break; case PrintPageOrder.OverThenDown: flag2 = false; break; default: throw new ArgumentOutOfRangeException(); } List <PageState> list2 = new List <PageState>(); if (flag2) { for (int i = 0; i < num; i++) { state.CurrentHPageNumber++; state.CurrentVPageNumber = 0; foreach (List <GcPageBlock> list3 in this.context.Pages) { if (list3.Count > i) { state.CurrentPageNumber++; state.CurrentVPageNumber++; list2.Add(new PageState(state.CurrentHPageNumber, state.CurrentVPageNumber, state.CurrentPageNumber, list3[i])); } } } } else { foreach (List <GcPageBlock> list4 in this.context.Pages) { state.CurrentVPageNumber++; state.CurrentHPageNumber = 0; foreach (GcPageBlock block in list4) { state.CurrentPageNumber++; state.CurrentHPageNumber++; list2.Add(new PageState(state.CurrentHPageNumber, state.CurrentVPageNumber, state.CurrentPageNumber, block)); } } } if (list2.Count > 0) { if (string.IsNullOrEmpty(this.report.PageRange)) { foreach (PageState state2 in list2) { state.CurrentHPageNumber = state2.HPageIndex; state.CurrentVPageNumber = state2.VPageIndex; state.CurrentPageNumber = (state2.PageIndex + this.report.FirstPageNumber) - 1; this.ExportPage(state, doc, state2.PageBlock); } } else { foreach (int num3 in Utilities.GetPageRange(this.report.PageRange, list2.Count)) { PageState state3 = list2[num3 - 1]; state.CurrentHPageNumber = state3.HPageIndex; state.CurrentVPageNumber = state3.VPageIndex; state.CurrentPageNumber = (state3.PageIndex + this.report.FirstPageNumber) - 1; this.ExportPage(state, doc, state3.PageBlock); } } } if (checkEmpty && (doc.Pages.PageCount <= 0)) { this.ExportEmptyPage(state, doc); } if (state.Bookmarks.Count > 0) { PdfOutlineItem item; if (doc.Outlines.Items.Count > 0) { item = doc.Outlines.Items[0]; } else { item = new PdfOutlineItem(this.report.Bookmark, state.FirstPage); doc.Outlines.Items.Add(item); } Dictionary <Bookmark, List <PdfOutlineItem> > dictionary = new Dictionary <Bookmark, List <PdfOutlineItem> >(); foreach (ExporterState.BookmarkState state4 in state.Bookmarks) { PdfOutlineItem item2 = new PdfOutlineItem(state4.Bookmark.Text, new PdfXYZDestination(state4.Page, (float)state4.Location.X, (float)state4.Location.Y, 0f)); if (!dictionary.ContainsKey(state4.Bookmark)) { dictionary.Add(state4.Bookmark, new List <PdfOutlineItem>()); } dictionary[state4.Bookmark].Add(item2); } foreach (KeyValuePair <Bookmark, List <PdfOutlineItem> > pair in dictionary) { Bookmark bookmark = pair.Key; List <PdfOutlineItem> list6 = pair.Value; if ((bookmark.Parent == null) || !dictionary.ContainsKey(bookmark.Parent)) { foreach (PdfOutlineItem item3 in list6) { item.ChildItems.Add(item3); } } else { List <PdfOutlineItem> list7 = dictionary[bookmark.Parent]; foreach (PdfOutlineItem item4 in list6) { PdfOutlineItem item5 = list7[0]; if (list7.Count > 1) { foreach (PdfOutlineItem item6 in list7) { if (item6.Dest.TargetPage == item4.Dest.TargetPage) { item5 = item6; break; } } } item5.ChildItems.Add(item4); } } } } if (processSettings) { if ((this.settings.DestinationType != DestinationType.Auto) || (doc.Pages.PageCount > 0)) { PdfArray array = new PdfArray(); if ((this.settings.OpenPageNumber <= doc.Pages.PageCount) && (doc.Pages.PageCount > 0)) { array.Add(doc.Pages.Kids[this.settings.OpenPageNumber - 1]); } else { array.Add(doc.Pages.Kids[0]); } switch (this.settings.DestinationType) { case DestinationType.Auto: break; case DestinationType.FitPage: array.Add(PdfName.Fit); break; case DestinationType.FitWidth: array.Add(PdfName.FitH); break; case DestinationType.FitHeight: array.Add(PdfName.FitV); array.Add(PdfNumber.Zero); break; case DestinationType.FitBox: array.Add(PdfName.FitB); break; default: throw new ArgumentOutOfRangeException(); } doc.Add(PdfName.OpenAction, array); } if ((this.settings.DocumentAttachments.Count > 0) && (doc.Pages.PageCount > 0)) { PdfPage page = doc.Pages.Kids[doc.Pages.PageCount - 1] as PdfPage; if (page != null) { foreach (DocumentAttachment attachment in this.settings.DocumentAttachments) { if ((!string.IsNullOrEmpty(attachment.Name) && (attachment.FileStreamInner != null)) && attachment.FileStreamInner.CanRead) { PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation { FileSpecification = { FileName = attachment.Name } }; attachment.FileStreamInner.WriteTo((Stream)annotation.FileSpecification.FileStream.Data); annotation.FileSpecification.FileStream.Size = attachment.FileStreamInner.Length; annotation.FileSpecification.FileStream.MIME = attachment.ContentType; annotation.ModifiedDate = DateTime.Now; annotation.FileSpecification.FileStream.ModifyDate = DateTime.Now; annotation.FileSpecification.FileStream.CreationDate = DateTime.Now; if (!string.IsNullOrEmpty(attachment.Description)) { annotation.Contents = attachment.Description; } if (attachment.Compress) { annotation.FileSpecification.FileStream.Filters.Enqueue(PdfFilter.FlateFilter); } annotation.Flags = PdfAnnotationBase.Flag.NoView | PdfAnnotationBase.Flag.Hidden | PdfAnnotationBase.Flag.Invisible; annotation.Rectangle = new PdfRectangle(-100f, -100f, 1f, 1f); page.Annotations.Add(annotation); } } } } } if (saveAuto) { SavePdfDocment(doc, stream); } if (flag) { this.openTypeFontUtility.ExternalFont -= this.ExternalFont; } }