internal virtual PdfDestination CopyDestination(PdfObject dest, IDictionary <PdfPage, PdfPage> page2page, PdfDocument toDocument) { PdfDestination d = null; if (dest.IsArray()) { PdfObject pageObject = ((PdfArray)dest).Get(0); foreach (PdfPage oldPage in page2page.Keys) { if (oldPage.GetPdfObject() == pageObject) { // in the copiedArray old page ref will be correctly replaced by the new page ref as this page is already copied PdfArray copiedArray = (PdfArray)dest.CopyTo(toDocument, false); d = new PdfExplicitDestination(copiedArray); break; } } } else { if (dest.IsString() || dest.IsName()) { PdfNameTree destsTree = GetNameTree(PdfName.Dests); IDictionary <String, PdfObject> dests = destsTree.GetNames(); String srcDestName = dest.IsString() ? ((PdfString)dest).ToUnicodeString() : ((PdfName)dest).GetValue(); PdfArray srcDestArray = (PdfArray)dests.Get(srcDestName); if (srcDestArray != null) { PdfObject pageObject = srcDestArray.Get(0); if (pageObject is PdfNumber) { pageObject = GetDocument().GetPage(((PdfNumber)pageObject).IntValue() + 1).GetPdfObject(); } foreach (PdfPage oldPage in page2page.Keys) { if (oldPage.GetPdfObject() == pageObject) { d = new PdfStringDestination(srcDestName); if (!IsEqualSameNameDestExist(page2page, toDocument, srcDestName, srcDestArray, oldPage)) { // in the copiedArray old page ref will be correctly replaced by the new page ref as this page is already copied PdfArray copiedArray = (PdfArray)srcDestArray.CopyTo(toDocument, false); // here we can safely replace first item of the array because array of NamedDestination or StringDestination // never refers to page in another document via PdfNumber, but should always refer to page within current document // via page object reference. copiedArray.Set(0, page2page.Get(oldPage).GetPdfObject()); toDocument.AddNamedDestination(srcDestName, copiedArray); } break; } } } } } return(d); }
protected internal virtual void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfPage page1 = pdfDoc.GetPage(1); float page1Height = page1.GetPageSize().GetHeight(); PdfDestination pdfDestination = PdfExplicitDestination.CreateXYZ(page1, 0, page1Height, 0.75f); pdfDoc.GetCatalog().SetOpenAction(pdfDestination); pdfDoc.Close(); }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); Rectangle rect = this.GetOccupiedAreaBBox(); PdfDestination dest = PdfExplicitDestination.CreateFitH(drawContext.GetDocument().GetLastPage(), rect.GetTop ()); PdfOutline outline = this.parent.AddOutline(this.title); outline.AddDestination(dest); }
private static void MergePdfFiles(string outputFile, List <string> sourceFiles) { using (var writer = new PdfWriter(new FileStream(outputFile, FileMode.OpenOrCreate))) { using (var outputDocument = new PdfDocument(writer)) { outputDocument.InitializeOutlines(); var rootOutline = outputDocument.GetOutlines(false); PdfOutline rootO = rootOutline.AddOutline("Root"); int pages = 1; int count = 1; foreach (var inputFile in sourceFiles) { using (var inputDoc = new PdfDocument(new PdfReader((inputFile)))) { for (int i = 1; i <= inputDoc.GetNumberOfPages(); i++) { var newp = outputDocument.AddNewPage(); var canvas = new PdfCanvas(newp); var origPage = inputDoc.GetPage(i); var copy = origPage.CopyAsFormXObject(outputDocument); canvas.AddXObject(copy, 0, 0); copy.Flush(); origPage = null; canvas.Release(); newp.Flush(); writer.Flush(); canvas = null; newp = null; } var subPages = inputDoc.GetNumberOfPages(); //PdfOutline pdfOutine = inputDoc.GetOutlines(false); /*var link1 = rootO.AddOutline(count.ToString()); * link1.AddDestination(PdfExplicitDestination.CreateFit(outputDocument.GetPage(pages))); * pages += subPages;*/ PdfOutline pdfOutine = inputDoc.GetOutlines(false); //pdfOutine.GetAllChildren().FirstOrDefault().AddOutline; foreach (var aOutline in pdfOutine.GetAllChildren()) { var link1 = rootO.AddOutline(aOutline.GetTitle(), aOutline.pos); link1.AddDestination(PdfExplicitDestination.CreateFit(outputDocument.GetPage(pages))); } pages += subPages; count++; } } } } }
/// <summary> /// creates link to specific page /// </summary> /// <param name="pageIndex">page index</param> /// <param name="textLink">text link</param> /// <returns>paragraph link</returns> protected Paragraph CreateLinkToPage(int pageIndex, string textLink) { //PdfArray array = new PdfArray(); //array.Add(document.GetPdfDocument().GetPage(pageIndex).GetPdfObject()); //array.Add(PdfName.Fit); //PdfDestination dest = PdfDestination.MakeDestination(array); PdfExplicitDestination dest = PdfExplicitDestination.CreateFit(pdfDocument.GetPage(pageIndex)); Paragraph link = new Paragraph(new Link(textLink, PdfAction.CreateGoTo(dest))); return(link); }
private static void SetStartPage(PdfDocument pdfDocument, Job job) { var pageIndex = job.Profile.PdfSettings.ViewerStartsOnPage; // index gets limited to at least 1 and the number of documents pageIndex = Math.Max(1, Math.Min(pageIndex, pdfDocument.GetNumberOfPages())); var navigationPage = pdfDocument.GetPage(pageIndex); pdfDocument.GetCatalog().SetOpenAction(PdfExplicitDestination.CreateXYZ(navigationPage, 0, 0, 1)); }
private static void MergePdfsWithBookmarks(List <string> InFiles, string OutFile) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(OutFile)); pdfDoc.InitializeOutlines(); PdfMerger merger = new PdfMerger(pdfDoc, true, true); List <PdfOutline> listItem = new List <PdfOutline>(); InFiles.ForEach(srcFile => { PdfDocument firstSourcePdf = new PdfDocument(new PdfReader(srcFile)); int pageCount = firstSourcePdf.GetNumberOfPages(); merger.Merge(firstSourcePdf, 1, pageCount); firstSourcePdf.GetOutlines(false).GetDestination(); firstSourcePdf.Close(); if (pageCount % 2 == 1) { pdfDoc.AddNewPage(iTextPageSize.A4); } }); PdfOutline rootOutline = pdfDoc.GetOutlines(false); listItem.AddRange(rootOutline.GetAllChildren()); rootOutline.GetAllChildren().Clear(); string parentTitle = Path.GetFileNameWithoutExtension(OutFile); PdfOutline parent = rootOutline.AddOutline(parentTitle); foreach (var item in listItem) { parent.AddOutline(item); } PdfExplicitDestination destToPage3 = PdfExplicitDestination.CreateFit(pdfDoc.GetFirstPage()); string stringDest = Guid.NewGuid().ToString(); pdfDoc.AddNamedDestination(stringDest, destToPage3.GetPdfObject()); parent.AddAction(PdfAction.CreateGoTo(new PdfStringDestination(stringDest))); if (pdfDoc.GetNumberOfPages() % 2 == 1) { pdfDoc.AddNewPage(iTextPageSize.A4); } pdfDoc.Close(); }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); Rectangle rect = GetOccupiedAreaBBox(); PdfPage page = drawContext.GetDocument().GetPage(GetOccupiedArea().GetPageNumber()); PdfDestination dest = PdfExplicitDestination.CreateXYZ(page, rect.GetLeft(), rect.GetTop(), 0); list.Add(new KeyValuePair <String, PdfDestination>(((Text)modelElement).GetText(), dest)); PdfOutline curOutline = root.AddOutline(((Text)modelElement).GetText()); curOutline.AddDestination(dest); }
internal virtual PdfDestination CopyDestination(PdfObject dest, IDictionary <PdfPage, PdfPage> page2page, PdfDocument toDocument) { PdfDestination d = null; if (dest.IsArray()) { PdfObject pageObject = ((PdfArray)dest).Get(0); foreach (PdfPage oldPage in page2page.Keys) { if (oldPage.GetPdfObject() == pageObject) { // in the copiedArray old page ref will be correctly replaced by the new page ref as this page is already copied PdfArray copiedArray = (PdfArray)dest.CopyTo(toDocument, false); d = new PdfExplicitDestination(copiedArray); break; } } } else { if (dest.IsString()) { PdfNameTree destsTree = GetNameTree(PdfName.Dests); IDictionary <String, PdfObject> dests = destsTree.GetNames(); String srcDestName = ((PdfString)dest).ToUnicodeString(); PdfArray srcDestArray = (PdfArray)dests.Get(srcDestName); if (srcDestArray != null) { PdfObject pageObject = srcDestArray.Get(0); foreach (PdfPage oldPage in page2page.Keys) { if (oldPage.GetPdfObject() == pageObject) { d = new PdfStringDestination(srcDestName); if (!IsEqualSameNameDestExist(page2page, toDocument, srcDestName, srcDestArray, oldPage)) { // in the copiedArray old page ref will be correctly replaced by the new page ref as this page is already copied PdfArray copiedArray = (PdfArray)srcDestArray.CopyTo(toDocument, false); toDocument.AddNamedDestination(srcDestName, copiedArray); } break; } } } } } return(d); }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); String name = "dest" + (counter++); int pageNumber = occupiedArea.GetPageNumber(); toc.Add(new KeyValuePair <String, KeyValuePair <String, int> >(((Text)modelElement).GetText(), new KeyValuePair <String, int>(name, pageNumber))); PdfPage page = drawContext.GetDocument().GetPage(pageNumber); drawContext.GetDocument().AddNamedDestination(name, PdfExplicitDestination.CreateFitH(page, page.GetPageSize().GetTop()).GetPdfObject()); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc, new PageSize(612, 792)); doc.Add(new Paragraph("Hello World")); // Set the height of a page to 842 points and zoom value to 1 (which means 100% zoom) PdfExplicitDestination zoomPage = PdfExplicitDestination.CreateXYZ(pdfDoc.GetPage(1), 0, 842, 1); pdfDoc.GetCatalog().SetOpenAction(zoomPage); doc.Close(); }
public static void BeforeClass() { CreateDestinationFolder(destinationFolder); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + "documentWithOutlines.pdf")); pdfDoc.GetCatalog().SetPageMode(PdfName.UseOutlines); PdfPage firstPage = pdfDoc.AddNewPage(); PdfPage secondPage = pdfDoc.AddNewPage(); PdfOutline rootOutline = pdfDoc.GetOutlines(false); PdfOutline firstOutline = rootOutline.AddOutline("First Page"); PdfOutline secondOutline = rootOutline.AddOutline("Second Page"); firstOutline.AddDestination(PdfExplicitDestination.CreateFit(firstPage)); secondOutline.AddDestination(PdfExplicitDestination.CreateFit(secondPage)); pdfDoc.Close(); }
public virtual void LinkTest02() { String outFileName = destinationFolder + "linkTest02.pdf"; String cmpFileName = sourceFolder + "cmp_linkTest02.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document doc = new Document(pdfDoc); doc.Add(new AreaBreak()).Add(new AreaBreak()); PdfDestination dest = PdfExplicitDestination.CreateXYZ(pdfDoc.GetPage(1), 36, 100, 1); PdfAction action = PdfAction.CreateGoTo(dest); Link link = new Link("TestLink", action); doc.Add(new Paragraph(link)); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdf); PdfDestination jekyll = PdfExplicitDestination.CreateFitH(1, 416); PdfDestination hyde = PdfExplicitDestination.CreateXYZ(1, 150, 516, 2); PdfDestination jekyll2 = PdfExplicitDestination.CreateFitR(2, 50, 380, 130, 440); document.Add(new Paragraph().Add(new Link("Link to Dr. Jekyll", jekyll))); document.Add(new Paragraph().Add(new Link("Link to Mr. Hyde", hyde))); document.Add(new Paragraph().Add(new Link("Link to Dr. Jekyll on page 2", jekyll2))); document.Add(new Paragraph().SetFixedPosition(50, 400, 80).Add("Dr. Jekyll")); document.Add(new Paragraph().SetFixedPosition(150, 500, 80).Add("Mr. Hyde")); document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE)); document.Add(new Paragraph().SetFixedPosition(50, 400, 80).Add("Dr. Jekyll on page 2")); document.Close(); }
public virtual void CreateSimpleDocWithOutlines() { String filename = "simpleDocWithOutlines.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename)); pdfDoc.GetCatalog().SetPageMode(PdfName.UseOutlines); PdfPage firstPage = pdfDoc.AddNewPage(); PdfPage secondPage = pdfDoc.AddNewPage(); PdfOutline rootOutline = pdfDoc.GetOutlines(false); PdfOutline firstOutline = rootOutline.AddOutline("First Page"); PdfOutline secondOutline = rootOutline.AddOutline("Second Page"); firstOutline.AddDestination(PdfExplicitDestination.CreateFit(firstPage)); secondOutline.AddDestination(PdfExplicitDestination.CreateFit(secondPage)); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }
public virtual void RemoteGoToRIllegalDestinationTest() { String outFile = destinationFolder + "remoteGoToDestinationTest01.pdf"; PdfDocument document = new PdfDocument(new PdfWriter(outFile)); document.AddNewPage(); document.AddNewPage(); try { PdfAction.CreateGoToR(new PdfStringFS("Some fake destination"), PdfExplicitDestination.CreateFitB(document .GetPage(1))); NUnit.Framework.Assert.Fail("Exception not thrown"); } catch (ArgumentException e) { NUnit.Framework.Assert.AreEqual("Explicit destinations shall specify page number in remote go-to actions instead of page dictionary" , e.Message); } document.Close(); }
public virtual void SetupAddOutlineInNotOutlineMode() { String filename = sourceFolder + "iphone_user_guide.pdf"; PdfReader reader = new PdfReader(filename); PdfWriter writer = new PdfWriter(destinationFolder + "addOutlinesWithoutOutlineModeResult.pdf"); PdfDocument pdfDoc = new PdfDocument(reader, writer); PdfOutline outlines = new PdfOutline(pdfDoc); PdfOutline firstPage = outlines.AddOutline("firstPage"); PdfOutline firstPageChild = firstPage.AddOutline("firstPageChild"); PdfOutline secondPage = outlines.AddOutline("secondPage"); PdfOutline secondPageChild = secondPage.AddOutline("secondPageChild"); firstPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); firstPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); secondPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); secondPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); pdfDoc.Close(); }
internal virtual PdfDestination CopyDestination(PdfObject dest, IDictionary <PdfPage, PdfPage> page2page, PdfDocument toDocument) { PdfDestination d = null; if (dest.IsArray()) { PdfObject pageObject = ((PdfArray)dest).Get(0); foreach (PdfPage oldPage in page2page.Keys) { if (oldPage.GetPdfObject() == pageObject) { PdfArray array = new PdfArray((PdfArray)dest); array.Set(0, page2page.Get(oldPage).GetPdfObject()); d = new PdfExplicitDestination(array); } } } else { if (dest.IsString()) { PdfNameTree destsTree = GetNameTree(PdfName.Dests); IDictionary <String, PdfObject> dests = destsTree.GetNames(); String name = ((PdfString)dest).ToUnicodeString(); PdfArray array = (PdfArray)dests.Get(name); if (array != null) { PdfObject pageObject = array.Get(0); foreach (PdfPage oldPage in page2page.Keys) { if (oldPage.GetPdfObject() == pageObject) { array.Set(0, page2page.Get(oldPage).GetPdfObject()); d = new PdfStringDestination(name); toDocument.AddNamedDestination(name, array); } } } } } return(d); }
public virtual void AddOutlineInNotOutlineMode() { String filename = "addOutlineInNotOutlineMode.pdf"; PdfReader reader = new PdfReader(sourceFolder + "iphone_user_guide.pdf"); PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument pdfDoc = new PdfDocument(reader, writer); PdfOutline outlines = new PdfOutline(pdfDoc); PdfOutline firstPage = outlines.AddOutline("firstPage"); PdfOutline firstPageChild = firstPage.AddOutline("firstPageChild"); PdfOutline secondPage = outlines.AddOutline("secondPage"); PdfOutline secondPageChild = secondPage.AddOutline("secondPageChild"); firstPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); firstPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); secondPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); secondPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }
public virtual void StructureDestination02Test() { String srcFile = sourceFolder + "customRolesMappingPdf2.pdf"; String outFile = destinationFolder + "structureDestination02Test.pdf"; String cmpFile = sourceFolder + "cmp_structureDestination02Test.pdf"; PdfDocument document = new PdfDocument(new PdfReader(srcFile), new PdfWriter(outFile)); PdfStructElem imgElement = new PdfStructElem((PdfDictionary)document.GetPdfObject(13)); PdfStructureDestination dest = PdfStructureDestination.CreateFit(imgElement); PdfPage secondPage = document.AddNewPage(); PdfPage thirdPage = document.AddNewPage(); PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15)); PdfAction gotoStructAction = PdfAction.CreateGoTo(PdfExplicitDestination.CreateFit(thirdPage)); gotoStructAction.Put(PdfName.SD, dest.GetPdfObject()); linkExplicitDest.SetAction(gotoStructAction); secondPage.AddAnnotation(linkExplicitDest); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_" )); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); for (int i = 0; i < 10; i++) { doc.Add(new Paragraph("Test")); doc.Add(new AreaBreak()); } for (int i = 1; i < 11; i++) { // Create a link destination to the page, specified in the 1st argument. PdfDestination d = PdfExplicitDestination.CreateXYZ(pdfDoc.GetPage(i), 36, 806, 0); Paragraph c = new Paragraph(new Link("Goto page " + i, d)); doc.Add(c); } doc.Close(); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); int insertPageNumber = 4; // Copier contains the additional logic to copy acroform fields to a new page. // PdfPageFormCopier uses some caching logic which can potentially improve performance // in case of the reusing of the same instance. PdfPageFormCopier formCopier = new PdfPageFormCopier(); PdfDocument insertDoc = new PdfDocument(new PdfReader(INSERT)); insertDoc.CopyPagesTo(1, 1, pdfDoc, insertPageNumber, formCopier); insertDoc.Close(); PdfOutline outlines = pdfDoc.GetOutlines(false); PdfOutline outline = outlines.GetAllChildren()[0].AddOutline("Hello", insertPageNumber - 1); outline.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(insertPageNumber))); pdfDoc.Close(); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); Document doc = new Document(pdfDoc); // Make the link destination page fit to the display PdfExplicitDestination destination = PdfExplicitDestination.CreateFit(pdfDoc.GetPage(3)); Link link = new Link( "This is a link. Click it and you'll be forwarded to another page in this document.", // Add link to the 3rd page. PdfAction.CreateGoTo(destination)); // Set highlighting type which is enabled after a click on the annotation link.GetLinkAnnotation().SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT); Paragraph p = new Paragraph(link).SetWidth(240); doc.ShowTextAligned(p, 320, 695, 1, TextAlignment.LEFT, VerticalAlignment.TOP, 0); doc.Close(); }
private static void AddRecursively(List <IBookmark> addedMarks, PdfDocument doc, PdfOutline outlineParent, IBookmark bookmarkParent = null) { if (bookmarkParent != null) { foreach (IBookmark current in addedMarks.FindAll(x => x.ParentId == bookmarkParent.Id)) { var subParent = outlineParent.AddOutline(current.Title); subParent.AddDestination(PdfExplicitDestination.CreateFit(doc.GetPage(current.StartPage))); AddRecursively(addedMarks, doc, subParent, current); } } else { foreach (IBookmark current in addedMarks.FindAll(x => x.ParentId == Guid.Empty)) { var subParent = outlineParent.AddOutline(current.Title); subParent.AddDestination(PdfExplicitDestination.CreateFit(doc.GetPage(current.StartPage))); AddRecursively(addedMarks, doc, subParent, current); } } }
public virtual void SetupAddOutlinesToDocumentTest() { String filename = sourceFolder + "iphone_user_guide.pdf"; PdfReader reader = new PdfReader(filename); PdfWriter writer = new PdfWriter(destinationFolder + "addOutlinesResult.pdf"); PdfDocument pdfDoc = new PdfDocument(reader, writer); pdfDoc.SetTagged(); PdfOutline outlines = pdfDoc.GetOutlines(false); PdfOutline firstPage = outlines.AddOutline("firstPage"); PdfOutline firstPageChild = firstPage.AddOutline("firstPageChild"); PdfOutline secondPage = outlines.AddOutline("secondPage"); PdfOutline secondPageChild = secondPage.AddOutline("secondPageChild"); firstPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); firstPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); secondPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); secondPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); outlines.GetAllChildren()[0].GetAllChildren()[1].AddOutline("testOutline", 1).AddDestination(PdfExplicitDestination .CreateFit(pdfDoc.GetPage(102))); pdfDoc.Close(); }
public virtual void DestTest01() { String srcFile = sourceFolder + "simpleNoLinks.pdf"; String outFile = destinationFolder + "destTest01.pdf"; String cmpFile = sourceFolder + "cmp_destTest01.pdf"; PdfDocument document = new PdfDocument(new PdfReader(srcFile), new PdfWriter(outFile)); PdfPage firstPage = document.GetPage(1); PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15)); linkExplicitDest.SetAction(PdfAction.CreateGoTo(PdfExplicitDestination.CreateFit(document.GetPage(2)))); firstPage.AddAnnotation(linkExplicitDest); PdfLinkAnnotation linkStringDest = new PdfLinkAnnotation(new Rectangle(35, 760, 160, 15)); PdfExplicitDestination destToPage3 = PdfExplicitDestination.CreateFit(document.GetPage(3)); String stringDest = "thirdPageDest"; document.AddNamedDestination(stringDest, destToPage3.GetPdfObject()); linkStringDest.SetAction(PdfAction.CreateGoTo(new PdfStringDestination(stringDest))); firstPage.AddAnnotation(linkStringDest); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_" )); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); Rectangle linkLocation = new Rectangle(523, 770, 36, 36); int[] borders = { 0, 0, 1 }; // Make the link destination page fit to the display PdfExplicitDestination destination = PdfExplicitDestination.CreateFit(pdfDoc.GetPage(3)); PdfAnnotation annotation = new PdfLinkAnnotation(linkLocation) // Set highlighting type which is enabled after a click on the annotation .SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT) // Add link to the 3rd page. .SetAction(PdfAction.CreateGoTo(destination)) .SetBorder(new PdfArray(borders)); pdfDoc.GetFirstPage().AddAnnotation(annotation); pdfDoc.Close(); }
private void addOutline(List <MergeItem> mergeTree, PdfOutline child, int currDepth) { int pageNumber; foreach (MergeItem mi in mergeTree) { if (mi.fileItem.isMissing) { continue; } pageNumber = findPageNumber(mi); if (pageNumber == -2) { continue; } PdfOutline grandChild = child.AddOutline(mi.bookmarkTitle); grandChild.SetOpen(!COLLAPSE_FILE_BOOKMARKS); if (pageNumber >= 0) { grandChild.AddDestination( PdfExplicitDestination.CreateFit(pageNumber)); } if (mi.mergeItems != null) { addOutline(mi.mergeItems, grandChild, currDepth + 1); } } }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); PdfDocument srcDoc1 = new PdfDocument(new PdfReader(SRC1)); PdfDocument srcDoc2 = new PdfDocument(new PdfReader(SRC2)); PdfDocument srcDoc3 = new PdfDocument(new PdfReader(SRC3)); int numberOfPages1 = srcDoc1.GetNumberOfPages(); int numberOfPages2 = srcDoc2.GetNumberOfPages(); int numberOfPages3 = srcDoc3.GetNumberOfPages(); PdfMerger merger = new PdfMerger(pdfDoc); merger.SetCloseSourceDocuments(true) .Merge(srcDoc1, 1, numberOfPages1) .Merge(srcDoc2, 1, numberOfPages2) .Merge(srcDoc3, 1, numberOfPages3); PdfOutline rootOutline = pdfDoc.GetOutlines(false); int page = 1; PdfOutline helloWorld = rootOutline.AddOutline("Hello World"); helloWorld.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(page))); page += numberOfPages1; PdfOutline link1 = helloWorld.AddOutline("link1"); link1.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(page))); page += numberOfPages2; PdfOutline link2 = rootOutline.AddOutline("Link 2"); link2.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(page))); pdfDoc.Close(); }
public virtual void AddOutlinesToDocumentTest() { PdfReader reader = new PdfReader(sourceFolder + "iphone_user_guide.pdf"); String filename = "addOutlinesToDocumentTest.pdf"; PdfWriter writer = new PdfWriter(destinationFolder + filename); PdfDocument pdfDoc = new PdfDocument(reader, writer); pdfDoc.SetTagged(); PdfOutline outlines = pdfDoc.GetOutlines(false); PdfOutline firstPage = outlines.AddOutline("firstPage"); PdfOutline firstPageChild = firstPage.AddOutline("firstPageChild"); PdfOutline secondPage = outlines.AddOutline("secondPage"); PdfOutline secondPageChild = secondPage.AddOutline("secondPageChild"); firstPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); firstPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1))); secondPage.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); secondPageChild.AddDestination(PdfExplicitDestination.CreateFit(pdfDoc.GetPage(2))); outlines.GetAllChildren()[0].GetAllChildren()[1].AddOutline("testOutline", 1).AddDestination(PdfExplicitDestination .CreateFit(pdfDoc.GetPage(102))); pdfDoc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }