Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Enumerating text objects |
Post Reply |
Author | |
beki
Beginner Joined: 23 Jun 06 Status: Offline Points: 7 |
Post Options
Thanks(0)
Posted: 24 Jun 06 at 1:33AM |
Does the QuickPDF library has a way to enumerate all text objects on a page and modify them?
Tomislav |
|
beki
Beginner Joined: 23 Jun 06 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
Ok, GetPageText(2) will do the job. But is there a way to modify text through QuickPDF right in the PDF?
Tomislav |
|
chicks
Debenu Quick PDF Library Expert Joined: 29 Oct 05 Location: United States Status: Offline Points: 251 |
Post Options
Thanks(0)
|
There is, but it's not easy. PDF really isn't meant to be edited this way. There can be all sorts of markup within a word or phrase, making it very difficult to pick out.
Here's a simple example (vbscript) that will change the word "spouse" to "mate" in the IRS' f1040ez.pdf document. Note that some gaps are left in a couple of places, because each chunk of text has its own positioning information - it would be nearly impossible to close the gaps without a huge amount of effort. Try to change "Spouse" to "Mate", and you'll begin to see the difficulties. Dim QP, i, p, content Dim inFileName, outFileName, QuickPDFKey '-- Init iSedQuickPDF Set QP = CreateObject("iSED.QuickPDF") '-- Get QuickPDF Key QuickPDFKey = WScript.Arguments(0) '-- Set file names inFileName = "f1040ez.pdf" outFileName = "out.pdf" '-- Unlock the PDF library Call QP.UnlockKey(QuickPDFKey) '-- Load the input PDF Call QP.LoadFromFile(inFileName) For p = 1 to QP.PageCount() Call QP.SelectPage(p) WScript.Echo "Page: " & p For i = 0 to QP.LayerCount()-1 Call QP.SelectLayer(i) WScript.Echo "Layer: " & i content = QP.GetPageContent() If InStr(content, "spouse") Then WScript.Echo "Found" content = Replace(content, "spouse", "mate") Call QP.SetPageContent(content) End If Next Next Call QP.SaveToFile(outFileName) '-- Clean up Set QP = Nothing |
|
beki
Beginner Joined: 23 Jun 06 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
Thanx chicks, this makes your point clear.
So it is something I will not be going to do, finding the text items on the page, but your code is very usefully describing the page structure. Tomislav |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Chicks!
Your sample shows how to go through each layer ... I've thought with CombineLayers i've the content of all layers together immediately without calling each layer...? Best regards, Ingo |
|
beki
Beginner Joined: 23 Jun 06 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
Do you know of a method to remove parts of text on a specific page? Based on a rectangle?
Tomislav |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Tomislav!
Here's a code snippet that should help: QP.SetMeasurementUnits(0); QP.SetFillColor(1,1,1); for i := 1 to QP.PageCount do begin QP.SelectPage(i); QP.CombineLayers; QP.DrawBox(1, QP.PageHeight - pixels, QP.PageWidth, pixels, 1); // . . . end; Best regards, Ingo |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store