I have a pdf data file. I need to add a link to the file at the top of each sheet. That at a clique on it the file on which it specifies opened. I searched the Internet for information on iTextSharp , but it seems that it can only create. What library can this be done? It is desirable that this library be more or less documented either with examples or if it is possible to piece where.

  • ITextSharp has its own git . And there are many examples. - Tivyram

1 answer 1

IText can also be used to add content to PDF documents. However, document editing (search / replace) is not supported by most libraries, since PDF documents are simply not editable.

The latest version of iText 7.1.x , examples can be found at https://developers.itextpdf.com/content/itext-7-examples/itext-7-manipulating-existing-pdf

It should be relatively easy (pseudo-code)

 PdfDocument pdfDocument = new PdfDocument(new PdfReader(SRC), new PdfWriter(DST)); Paragraph para = new Paragraph("Lorem Ipsum") .setFontColor(ColorConstants.DARK_GRAY) .setTextAlignment(alignment) .setFontSize(12f + RND.nextInt(5)); ParagraphRenderer renderer = (ParagraphRenderer) para.createRendererSubTree(); renderer.setParent(new DocumentRenderer(new Document(pdfDocument))); renderer.layout(new LayoutContext(new LayoutArea(pageNumber, new Rectangle(x, y, w, h)))); renderer.draw(new DrawContext(pdfDocument, new PdfCanvas(pdfDocument.getPage(pageNumber), false), true /* tagging */));