Posted 21 October 2020, 3:54 am EST
Hi Gregory,
The PDF format does not have a notion of a paragraphs or any “reflowable” text fragments. PDF operators allow to render a line of text at most, no text wrapping is supported. So generally speaking, it is impossible to replace a text fragment in a PDF with an arbitrary fragment (that may be physically larger) without recreating the whole document. While we (GcPdf) do have plans to provide some form of text replacement in the future, it is not here yet and even when done it might not work in all cases - again, if a replacement if physically larger than what it replaces, it may not produce the expected results.
In your particular case, if you know the physical layout of your PDFs, you might be able to ‘wipe out’ the text fragments containing your tags (either by filling them with white, or better yet by redacting the areas), and render regenerated texts with tags replaced with custom content, over the old fragments’ bounds. In other words, if you have a PDF with a multi-line text paragraph (containing the tags), and know the maximum bounds of that paragraph - using GcPdf you can:
- Redact out the area under the max bounds;
- Use TextLayout to render the new text (paragraphs) into that area.
This approach will handle replacements longer than tags well - unless the new paragraph becomes larger than the max area allowed for it, in which case it will be clipped by TextLayout.
Hope this helps,
Dmitry.