Adding Text to a PDF Document

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Adding Text to a PDF Document

Post by jeffp »

I am a bit confused as to how to add text to a PDF document via your API. Here's my situation: I'm dealing with PDF files that are essentially images of paper documents that have been scanned in. I first extract a TIFF image of each page of the PDF and send it to my OCR engine. The OCR engine give be back an array of words with positioning coordinates of each word. I then need to place each word in a text object on the pdf page so it lines up behind the part of the image where the word is located. The text also need to be invisible.

I'm making the switch from the Amyuni PDF product. In that product, they talk in terms of Objects. In this case, I created a "Text Object", filled out its attributes, and placed in on the page. Below is a quick example of some Delphi code used with Amyui to place some text on a page:

FPDF.CreateObject(acObjectTypeText, AName);
with FPDF.GetObjectByName(AName) do
begin
Attribute['TextFont'] := Format('%s, %d, %s, %s, 0', [_OCRFont, AFontSize, ABoldText, AItalicText]);
Attribute['Text'] := AWord.Text;
Attribute['Left'] := AWord.Left;
Attribute['Right'] := AWord.Left + AWord.Width;
Attribute['Top'] := AWord.Top;
Attribute['Bottom'] := AWord.Top + AWord.Height;
Attribute['TextColor'] := AWord.Color;
Attribute['TextRenderingMode'] := _TextRenderMode;
end;

I'm trying to find the equivalent of this in your PDF Tools SDK. I see talk of Annotations, but it says that is like the skicky notes which I don't think will work here.

I'm also looking for a way to pull out the names of all form fields on a page as well as to set their values via code.

I'm new to PDF Tools SDK so I may be missing something, but I have read most of the documentation.
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Adding Text to a PDF Document

Post by Corwin - Tracker Sup »

Hello,

Maybe this small Delphi 7 sample can help you.

HTH.
Attachments
AddTextToPDF.zip
(214.09 KiB) Downloaded 159 times
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Adding Text to a PDF Document

Post by jeffp »

Ok. I see that to add text I need to use the PXC Library and not the XCPRO Library. However, this brings up a big issue for me. The PXC Library and the demo you sent can add text to a "new" PDF page. I need to add this text to an "existing" PDF page. When I OCR my existing PDF document, I have to place the OCR text back in that same document.

Is there any way to add text to and EXISTING PDF document?
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Adding Text to a PDF Document

Post by Corwin - Tracker Sup »

You will need to create new PDF with all required text and then just merge it with existed PDF using PXCp_PlaceContents function.

HTH
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Adding Text to a PDF Document

Post by jeffp »

Perfect. Would you happen to have a Delphi Example for this?
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Adding Text to a PDF Document

Post by Corwin - Tracker Sup »

Here is base sample:
Attachments
AddTextToPDF2.zip
(299.93 KiB) Downloaded 168 times
Post Reply