public virtual void SetLinkDestinationToPageAppendMode() { String input = sourceFolder + "100pages.pdf"; String output = destinationFolder + "setLinkDestinationToPageAppendMode.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfReader(input), new PdfWriter(output), new StampingProperties() .UseAppendMode()); PdfPage page1 = pdfDoc.GetPage(1); PdfPage page2 = pdfDoc.GetPage(2); PdfIndirectReference page1IndRef = page1.GetPdfObject().GetIndirectReference(); PdfIndirectReference page2IndRef = page2.GetPdfObject().GetIndirectReference(); PdfDictionary aDict = ((PdfLinkAnnotation)page1.GetAnnotations()[0]).GetAction(); new PdfAction(aDict).Put(PdfName.D, PdfExplicitDestination.CreateXYZ(page2, 300, 400, 1).GetPdfObject()); PageFlushingHelper flushingHelper = new PageFlushingHelper(pdfDoc); flushingHelper.AppendModeFlush(2); flushingHelper.UnsafeFlushDeep(1); // annotation is flushed NUnit.Framework.Assert.IsTrue(aDict.IsFlushed()); // page is not flushed NUnit.Framework.Assert.IsFalse(page1IndRef.CheckState(PdfObject.FLUSHED)); // page is released NUnit.Framework.Assert.IsNull(page1IndRef.refersTo); // page is not flushed NUnit.Framework.Assert.IsFalse(page2IndRef.CheckState(PdfObject.FLUSHED)); // page is released NUnit.Framework.Assert.IsNull(page2IndRef.refersTo); // exception is not thrown pdfDoc.Close(); }
protected void ManipulatePdf(String dest) { // Creates directory and new pdf file by content of the read pdf FileInfo file = new FileInfo(PDF); file.Directory.Create(); PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(PDF)); for (int i = 1; i < pdfDoc.GetNumberOfPages();) { if (GetFactors(++i).Count > 1) { continue; } // Adding named destinations for further usage depending on the needs PdfPage pdfPage = pdfDoc.GetPage(i); Rectangle pageRect = pdfPage.GetPageSize(); float getLeft = pageRect.GetLeft(); float getTop = pageRect.GetTop(); PdfExplicitDestination destObj = PdfExplicitDestination.CreateXYZ(pdfPage, getLeft, getTop, 1); pdfDoc.AddNamedDestination("prime" + i, destObj.GetPdfObject()); } pdfDoc.Close(); CreateXml(PDF, dest); }
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(); }
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)); }
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); }
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 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(); }
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(); }
static void Main(string[] args) { var inputFile = @"d:\temp\a.pdf"; var outputFile = @"d:\temp\b.pdf"; try { using (var reader = new PdfReader(inputFile)) using (var writer = new PdfWriter(outputFile)) { var pdfDocument = new PdfDocument(reader, writer); var extractor = new TextLinesExtractionStrategy(); var processor = new PdfCanvasProcessor(extractor); var numPages = pdfDocument.GetNumberOfPages(); var outlineHead = pdfDocument.GetOutlines(true); var captionPattern = new Regex(@"^\s*\d+\.\s*.*$"); for (var i = 0; i < numPages; i++) { var page = pdfDocument.GetPage(1 + i); processor.ProcessPageContent(page); System.Diagnostics.Debug.WriteLine("PageSize:" + page.GetPageSize()); foreach (var line in extractor.Lines) { var captionMatch = captionPattern.Match(line.Text); if (!captionMatch.Success) { continue; } var captionText = captionMatch.Groups[0].Value; var captionHead = line.Ascent.GetBoundingRectangle(); var captionDest = PdfExplicitDestination.CreateXYZ(page, captionHead.GetLeft(), captionHead.GetTop(), float.NaN); outlineHead.AddOutline(captionText).AddDestination(captionDest); } extractor.Clear(); } pdfDocument.Close(); } } catch (Exception ex) { Console.WriteLine("Err:" + ex.Message); } finally { var resultFile = new FileInfo(outputFile); if (resultFile.Exists && resultFile.Length <= 0) { resultFile.Delete(); } Console.WriteLine("Press any key to exit."); Console.ReadKey(true); } }