Accessing text elements in C#

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

DaveGanote
User
Posts: 3
Joined: Mon Nov 15, 2010 8:41 pm

Accessing text elements in C#

Post by DaveGanote »

I'm attempting to access the text elements of a PDF using the below C# routine. While the code works up until I get the text element count, each attempt to retrieve one of the text elements by calling PXCp_ET_GetElement() results in an 'invalid parameter' (0x82080001) error. I've tried various ways of initializing the PXP_TextElement structure prior to calling PXCp_ET_GetElement() with no success.

Can the PXCp_ET_GetElement() routine be called successfully from C#?

Thanks

Dave Ganote

-----------------------

private void TestPDFTextElements(string pdfFilename)
{
// Create the handle to the pdf.
int pdfHandle = 0;
// substitute with real values to run code.
string regKey = string.Empty;
string devCode = string.Empty;
int res = XCPro35_Defs.PXCp_Init(out pdfHandle, regKey, devCode);
res = XCPro35_Defs.PXCp_ReadDocumentW(pdfHandle, pdfFilename, 0);

// Prepare for text operations
res = XCPro35_Defs.PXCp_ET_Prepare(pdfHandle);
try
{
res = XCPro35_Defs.PXCp_ET_AnalyzePageContent(pdfHandle, 0);

// Get text elements count
int textElementCount = 0;
res = XCPro35_Defs.PXCp_ET_GetElementCount(pdfHandle, out textElementCount);

// Access text elements
XCPro35_Defs.PXP_TextElement textElement;
for (int i = 0; i < textElementCount; i++)
{
textElement.Count = 0;
textElement.mask = 0;
res = XCPro35_Defs.PXCp_ET_GetElement(pdfHandle, i, out textElement, 0);
if (res >= 0)
{
Console.WriteLine(textElement.Count.ToString());
}
}
}
finally
{
res = XCPro35_Defs.PXCp_ET_Finish(pdfHandle);
XCPro35_Defs.PXCp_Delete(pdfHandle);
}
}
Tracker - Clarion Support
Site Admin
Posts: 64
Joined: Wed Jun 30, 2004 4:45 pm
Location: Maryland, USA

Re: Accessing text elements in C#

Post by Tracker - Clarion Support »

Hi Dave!

In the example you provided, before calling PXCp_ET_GetElement, you need to set textElement.cbSize to the size of the XCPro35_Defs.PXP_TextElement or you will get an error.

HTH!
Craig Ransom
Tracker Software - Clarion Support
http://www.tracker-software.com