PXCp_ET_GetElement gives "Invalid Argument"

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.

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Support Staff, moderators

Post Reply
neilpitman
User
Posts: 39
Joined: Fri Jun 17, 2005 8:38 am

PXCp_ET_GetElement gives "Invalid Argument"

Post by neilpitman » Wed Aug 13, 2008 1:28 pm

We are find that PXCp_ET_GetElement always gives "Invalid Argument" - perhaps we are not using the correct calling sequence? Using 3.601131

VS 2005 project attached, and key code shown below

XCPro35_Defs.PXP_TETextComposeOptions m_TextComposeOptions;
XCPro35_Defs.PXP_TextElement m_tel ;

Console.WriteLine("Analyzing PDF " + pdfFile);

hr = XCPro35_Defs.PXCp_Init(out m_pdf, Key, DevCode);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_Init");




hr = XCPro35_Defs.PXCp_ReadDocumentW(m_pdf, pdfFile, 0);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ReadDocumentW");



hr = XCPro35_Defs.PXCp_GetPagesCount(m_pdf, out pages);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_GetPagesCount");


Console.WriteLine("PDF File has " + pages + " pages");

for (int pagenum = 0; pagenum < pages; pagenum++)
{


hr = XCPro35_Defs.PXCp_ET_Prepare(m_pdf);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_Prepare");

hr = XCPro35_Defs.PXCp_ET_AnalyzePageContent(m_pdf, 0);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_AnalyzePageContent");


hr = XCPro35_Defs.PXCp_ET_GetElementCount(m_pdf, out elementCount);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_GetElementCount");

hr = XCPro35_Defs.PXCp_ImageGetCountOnPage(m_pdf, pagenum, out images);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ImageGetCountOnPage");


hr = XCPro35_Defs.PXCp_ET_GetCurrentComposeParams(m_pdf, out m_TextComposeOptions);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_GetCurrentComposeParams");


hr = XCPro35_Defs.PXCp_ET_GetPageContentAsTextW(m_pdf, pagenum, ref m_TextComposeOptions, out pBuffer, ref buflen);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_GetPageContentAsTextW");

string strBuffer = Marshal.PtrToStringUni(pBuffer, buflen);


Console.WriteLine("Page " + pagenum + " has " + images + " images and " + elementCount + " elements. Text of length " + strBuffer.Length);



for (int ei = 0; ei < elementCount; elementCount++)
{
hr = XCPro35_Defs.PXCp_ET_GetElement(m_pdf, ei, out m_tel, 0);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_GetElement");
}

}
}

Ivan - Tracker Software
Site Admin
Posts: 3587
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by Ivan - Tracker Software » Thu Aug 14, 2008 3:46 pm

Looks like you didn't initialize m_tel variable. You need to initialize cbSize field with sizeof of this structure and set a mask fields with flags combination which defines which information you need to get.

HTH
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

neilpitman
User
Posts: 39
Joined: Fri Jun 17, 2005 8:38 am

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by neilpitman » Fri Aug 15, 2008 1:12 pm

Thanks for the guidance - we have tried as shown below but still get the "Invalid Argument" error. Is there an example available we can look at ?

......
XCPro35_Defs.PXP_TextElement m_tel = new XCPro35_Defs.PXP_TextElement();

m_tel.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(m_tel);

m_tel.mask = (int)XCPro35_Defs.PXP_TextElementMask.PTEM_Text;

hr = XCPro35_Defs.PXCp_ET_GetElement(m_pdf, 0, out m_tel, 0);
if (!PXCp_Error.IS_DS_SUCCESSFUL(hr)) doError(hr, "PXCp_ET_GetElement");

Ivan - Tracker Software
Site Admin
Posts: 3587
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by Ivan - Tracker Software » Fri Aug 15, 2008 2:41 pm

Can you send me complete sample project?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

neilpitman
User
Posts: 39
Joined: Fri Jun 17, 2005 8:38 am

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by neilpitman » Fri Aug 15, 2008 2:50 pm

It was attached to the original post. Thanks.

Ivan - Tracker Software
Site Admin
Posts: 3587
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by Ivan - Tracker Software » Fri Aug 15, 2008 3:07 pm

Sorry, but I see no attached files here.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

neilpitman
User
Posts: 39
Joined: Fri Jun 17, 2005 8:38 am

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by neilpitman » Fri Aug 15, 2008 3:22 pm

V4 Project attached
Attachments
pdfinfo.zip
(54.1 KiB) Downloaded 238 times

Ivan - Tracker Software
Site Admin
Posts: 3587
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by Ivan - Tracker Software » Fri Aug 15, 2008 6:34 pm

Real sizeof(PXP_TextElement) is 132 bytes, but System.Runtime.InteropServices.Marshal.SizeOf(m_tel) return 140

will check what causes such a difference and will shortly advise how to resolve - thanks for your patience.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

neilpitman
User
Posts: 39
Joined: Fri Jun 17, 2005 8:38 am

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by neilpitman » Thu Aug 28, 2008 2:12 pm

Please could you advise of the solution for this problem.

Thanks

John - Tracker Supp
Site Admin
Posts: 8201
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by John - Tracker Supp » Fri Aug 29, 2008 2:41 pm

We are working on this now and a resolution should be available shortly.

Thanks for your patience.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by Corwin - Tracker Sup » Tue Sep 02, 2008 12:05 pm

Please try the following solution:
In XCPro35_Declares.cs change PXP_TETextComposeOptions definition to

Code: Select all

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PXP_TextElement 
{
	public int cbSize;
	public int mask;
      [MarshalAs(UnmanagedType.LPWStr)] 
      public string Characters;
	public double[] Offsets;
	public int Count;
	public int FontIndex;
	public double FontSize;
	public PXC_Matrix Matrix;
	public double CharSpace;
	public double WordSpace;
	public double Th;
	public double Leading;
	public double Rise;
	public int FillColor;
	public int StrokeColor;
	public PXC_TextRenderingMode RenderingMode;
};
and add this code to your project:

Code: Select all

for (int ei = 0; ei < elementCount; ei++)
{
   XCPro35_Defs.PXP_TextElement TextElement = new XCPro35_Defs.PXP_TextElement();
   TextElement.cbSize =  System.Runtime.InteropServices.Marshal.SizeOf(TextElement);
   TextElement.mask = 0;

   hr = XCPro35_Defs.PXCp_ET_GetElement(m_pdf, ei, ref TextElement, 0);
   if (PXCp_Error.IS_DS_SUCCESSFUL(hr) && TextElement.Count > 0)
   {      
       char[] CharArr = new char[TextElement.Count];
       TextElement.Characters = new string(CharArr);
       TextElement.mask = (int)XCPro35_Defs.PXP_TextElementMask.PTEM_Text;
       hr = XCPro35_Defs.PXCp_ET_GetElement(m_pdf, ei, ref TextElement, (int)XCPro35_Defs.PXP_GetTextElementFlags.GTEF_IgnorePageRotation);
       if (PXCp_Error.IS_DS_SUCCESSFUL(hr))
           Console.WriteLine("ei"+ei.ToString()+' '+TextElement.Characters);
   }
}
HTH

neilpitman
User
Posts: 39
Joined: Fri Jun 17, 2005 8:38 am

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by neilpitman » Tue Sep 02, 2008 1:49 pm

Presumably the declares change was to PXP_TextElement not PXP_TETextComposeOptions?

I tried that but then get

Error 3 The best overloaded method match for 'pdfinfo.XCPro35_Defs.PXCp_ET_GetElement(int, int, out pdfinfo.XCPro35_Defs.PXP_TextElement, int)' has some invalid arguments C:\dev\pdfinfo\pdfinfosample\pdfinfo.cs 110 34 pdfinfo

Error 4 Argument '3' must be passed with the 'out' keyword C:\dev\pdfinfo\pdfinfosample\pdfinfo.cs 110 81 pdfinfo

Perhaps if you have complete Declares and pdfinfo.cs files which work at your end you would be able to post them?

Thanks

Neil Pitman

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: PXCp_ET_GetElement gives "Invalid Argument"

Post by Corwin - Tracker Sup » Tue Sep 02, 2008 3:20 pm

Function PXCp_ET_GetElement (in XCPro35_Declares.cs) also must be chaned to
[DllImport("xcpro35")] public static extern int PXCp_ET_GetElement(int pDocument, int index, ref PXP_TextElement pElement, int flags);

Fixed project is attached to this message.
Attachments
pdfinfosample.zip
(39.41 KiB) Downloaded 237 times

Post Reply