Hi...
my mission is to locate a certain word inside a pdf file and insert an image next to this word
if anyone can recommend me on some api's or examples i will be very grateful.
Thanx ahead
Daniel
Hi...
my mission is to locate a certain word inside a pdf file and insert an image next to this word
if anyone can recommend me on some api's or examples i will be very grateful.
Thanx ahead
Daniel
This problem is best solved by finding the visual coordinates of the target word, then drawing the image as an overlay at those coordinates — rewriting raw content streams to splice graphics into existing text is fragile. Given the earlier posts, has tried a common Java PDF library and others raised editability concerns; a practical path is to extract character positions, compute a bounding box for the matched word, and append an image to the page at an offset from that box.
A concise workflow (works reliably with Apache PDFBox):
Example (pseudo steps):
override writeString(text, List<TextPosition> positions) -> store positions per-char
search pageString for "target"
for each match -> compute bbox from positions[matchStart..matchEnd]
append image with PDPageContentStream at bbox coordinates Caveats and tips: PDF coordinates are page-based (watch rotation and origin), text may be split into many small TextPosition objects (hyphenation, columns, ligatures), and some PDFs use outlines or paths instead of text (OCR required). Test across representative PDFs and scale/offset the image to avoid overlapping glyphs. See Apache PDFBox examples for detailed APIs and samples: Apache PDFBox examples.
Jump to Post— Ezzaral 2,714Try iText for PDF processing.
I know this api and I'm working alot with it... but i haven't found a way to do it with this api...
small wonder. PDF files are readonly, so you can't change them.
Try iText for PDF processing.
I do remember any search functions in iText...
However it should be possible if you use PdfDictionary object as described in chapter 18 of iText book. Only problem is you have to get around cross-referencing of PDF document. Very-very dirty work
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.