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);
}
}
Accessing text elements in C#
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
-
- Site Admin
- Posts: 64
- Joined: Wed Jun 30, 2004 4:45 pm
- Location: Maryland, USA
Re: Accessing text elements in C#
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!
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!