Get and Set Text

PDF-XChange Editor SDK for Developers

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

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Get and Set Text

Post by jeffp »

A couple of remaining procedures that I am converting over from the old Pro SDK to the new Editor SDK are getting and setting text on the PDF page. I mainly do this in the OCR context. The OCR engines we use give me word information including coordinates. I then was placing the words on the page using the following calls in the old SDK.

PXC_SetTextOptions
PXC_TextOutA

Can you point me in the right direction or give me a quick example with the Editor SDK. I use Delphi and I need to do this with the Core Layer probably with methods from the IPXC_Page object.

Second, I need to reverse this. I need to be able to recreate these word coordinates by getting the text from the page. Looks like something like IPXC_Page.GetText but I can't quite make out from the help how to set this up. I'm looking to get a word at time with all its position coordinates.

Again, I need to do all this with calls only to the Core Layer.

FYI, I'm putting all this and other Delphi examples into a comprehensive Delphi demo project (expanding on the current one you sent me) that I'd be happy to share and make available for anyone else using Delphi. I'll be posting it once I thoroughly test all my procedures and hammer out some remaining issues.

Thanks again.

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Get and Set Text

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Here's our small sample on the Core SDK. Check this link:
https://github.com/tracker-software/PDFCoreSDK-WPF

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Get and Set Text

Post by jeffp »

Ok. I downloaded you C# example and tried to convert it the best I could to Delphi code.

Here is my simple example that still doesn't work. This will ultimately be used to place "hidden" text behind an OCR'd image, but right now I just want to see the text on the PDF page once I place it and save the PDF file. The example below tries to write out the work "TESTING" to roughly the middle of the first page of the PDF.

What am I missing?

Code: Select all

procedure TPDFCoreLayer.DrawText(ADoc: IPXC_Document);
var
  CC: IPXC_ContentCreator;
  AFont: IPXC_Font;
  AText: String;
  AFontSize, x, y: Double;
  APage: IPXC_Page;
begin
  if Assigned(ADoc) then
  begin
    AFontSize := 15;
    AText := 'TESTING';
    AFont := ADoc.CreateNewFont('Arial', 0, 400);

    ADoc.Pages.Get_Item(0, APage); //Test Page is 612 x 792 points

    //Start roughly in the middle of the page
    x := 300;
    y := 300;

    CC := ADoc.CreateContentCreator;
    CC.SetTextRenderMode(TRM_Fill); //TRM_None;
    CC.SetFont(AFont);
    CC.SetFontSize(AFontSize);
    CC.SetStrokeColorRGB(RGB(0, 0, 0)); //Black

    CC.ShowTextLine(x, y, PChar(AText), -1, 0);
  end;
end;

Thanks again. And I'll be adding this one too to my Delphi demo once I get it working.

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Get and Set Text

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Me and my colleague (who translates the C# code into the Delphi code) will look at it on Monday and will figure out what's the problem.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Get and Set Text

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Here's the updated sample with the working method that you've described:
https://github.com/tracker-software/PDF ... #L155-L156

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Get and Set Text

Post by jeffp »

That did it. Thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Get and Set Text

Post by Sasha - Tracker Dev Team »

Great that worked for you Jeff, we'll mark this topic as closed.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ