Print Page | Close Window

Find and replace text within a PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2158
Printed Date: 16 Jul 25 at 3:32PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Find and replace text within a PDF
Posted By: DanButton
Subject: Find and replace text within a PDF
Date Posted: 17 Feb 12 at 4:48PM
Hi,

Just wondering if there's a handy way to find and replace text within a PDF.

Scenario:
We have a PDF with text placement tags in it (note, this is not a PDF Form with fields as such), such as:
==========
Date <date>
Dear <firstname>, this is a PDF with some wonderful stuff on it.
==========

Having find and replace would allow us to search for <date> and replace it programmatically with today's date. Likewise with the <firstname> text area. However, the <firstname> bit could possibly present a problem as the length of the firstname may influence the placement of the text following it.

Anyone done anything like this before with QuickPDF without using a PDF form? Any planned functionality?

Any tips would be great.

Thanks

DB



Replies:
Posted By: edvoigt
Date Posted: 17 Feb 12 at 9:09PM
Hi,

here a short idea. The problem seems to be the replace part.

The bad part of my solution idea: you have to search alone in a object-content. It is to get over QP.GetObjectToString. It is nothing for people without a little understanding of PDF-operators. You would have to look for textoutputoperation and to find there your keys like <date>. The problem is, that it must not be a single string. It looks other (I show the most simple case):

BT
1 0 0 1 70.8661 680.315 Tm
(<date>)Tj
ET


But if there is letterspacing used, it looks more complicated.

Let's assume you find this. Then you may replace (look into the PDF-spec. to be sytactically correct) it by your wished string.

The good part is small: After this you give the modified objectcontent easy via QP.SetObjectFromString back to QPL.

The documentation says "This is for advanced use only."

There is some work for you.


Cheers,
Werner


Posted By: DanButton
Date Posted: 20 Feb 12 at 9:14AM
Thanks Werner - that's something for me to get started with - I'll give that a try!

Cheers,

DB


Posted By: AndrewC
Date Posted: 22 Feb 12 at 2:55PM
QPL currently doesn't support the replacing of text in a PDF file.

It is not always easy to implement such a function as there are many ways to draw the same text in a PDF file

1.

BT
1 0 0 1 70.8661 680.315 Tm
(<date>)Tj
ET

2.

BT
1 0 0 1 70.8661 680.315 Tm
(da)-10.0(te)Tj
ET

3. 

BT
1 0 0 1 66.8661 680.315 Tm
(d)Tj
ETBT
1 0 0 1 70.8661 680.315 Tm
(a)Tj
ETBT
1 0 0 1 74.8661 680.315 Tm
(t)Tj
ET
BT
1 0 0 1 78.8661 680.315 Tm
(e)Tj
ET



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk