Timestamping with PDF Tools v4

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
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Timestamping with PDF Tools v4

Post by SammyDev »

Hello,

I am trying to digitally sign documents with timestamps using the latest version of the PDF Tools 4 SDK (build 201) using the following function:

[DllImport(@"C:\Program Files\Tracker Software\PDF-Tools 4 SDK\Examples\Bin\xcpro40.dll")]
public static extern int PXCp_SetTSAServerW(
ref IntPtr pdf,
[MarshalAs(UnmanagedType.LPWStr)] string serverURL,
[MarshalAs(UnmanagedType.LPWStr)] string user,
[MarshalAs(UnmanagedType.LPWStr)] string password);

I am currently getting the following error: "-2113394897" - "Document is already signed", even though it isn't.
I have been looking at the following thread, to try out different TSA sample servers, but I am always getting the same error
https://forum.pdf-xchange.com/ ... amp#p53908

One thing to note is that i am able to sign a document correctly using the function PXCp_SignDocumentUsingPFXW but cannot figure why the timestamping doesn't work.

Do you have any sample code or any advice regarding this issue ?

Thanks in advance
Sammy
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Re: Timestamping with PDF Tools v4

Post by SammyDev »

Also to give some more information, I succeed in signing with timestamps when printing a document to the PDF-Xchange 4.0 printer, having it configured with the same tsa server as within my sample application.

Here is a shortened view of what my sample application does:

string regKey = "<MyRegistrationKey>";
string devCode = "<MyDevCode>";

string infile = "<PathToInputFile>";
string outfile = "<PathToOutputFile>";
string image = "<PathToImage>";

int handle = -1;
XCPro35_Defs.PXCp_Init(out handle, regKey, devCode);

int iresult = XCPro35_Defs.PXCp_ReadDocumentW(handle, infile, 0);
XCPro35_Defs.PXC_RectF rect4Image = new XCPro35_Defs.PXC_RectF();

rect4Image.left = 0;
rect4Image.right = 1;
rect4Image.top = 1 ;
rect4Image.bottom = 0 ;
IntPtr pdfHandle = new IntPtr(handle);

int tsaResult = XCPro35_Defs.PXCp_SetTSAServerW(ref pdfHandle, "<MyTSAServer>", "<MyLogin>", "<MyPassword>");

int signResult = XCPro35_Defs.PXCp_SignDocumentUsingPFXW(handle,
@"<PathToMyCertificate>", "<MyPassword>", 0, ref rect4Image,
"MyReason", "<MyLocation>", "<MyContactInfo>", image, 0);

int writeResult = XCPro35_Defs.PXCp_WriteDocumentW(handle, outfile, XCPro35_Defs.PXCp_CreationDisposition.PXCp_CreationDisposition_Overwrite, 0);



Also, I cannot find any reference or sample code to that function in the SDK documentation, is this function supported?

Regards
Sammy
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Timestamping with PDF Tools v4

Post by Tracker Supp-Stefan »

Thanks for the details Sammy,

I need to discuss this with one of my colleagues from the Canadian office - and once that's done - we will post back here in this topic.

Best,
Stefan
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Timestamping with PDF Tools v4

Post by Ivan - Tracker Software »

The problem is with wrong functions PXCp_SetTSAServerA/PXCp_SetTSAServerW declaration - document handle should not be passed by ref.
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.
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Re: Timestamping with PDF Tools v4

Post by SammyDev »

Hello Ivan and Stefan, thanks for your responses.

I am now getting a bit confused, we requested the function signatures from the Tracker team in Canada, and this was their response from John Verbeeten:

"The function signatures for setting the time stamp server are:

- PXCPRO40_API HRESULT XCPAPI PXCp_SetTSAServerA(PDFDocument* pdf, LPCSTR lpszServerURL, LPCSTR lpszUser, LPCSTR lpszPassword);
- PXCPRO40_API HRESULT XCPAPI PXCp_SetTSAServerW(PDFDocument* pdf, LPCWSTR lpszServerURL, LPCWSTR lpszUser, LPCWSTR lpszPassword);

In C# you'd import it with something like:

[DllImport("xcpro40")]
public static extern int PXCp_SetTSAServerW(
ref IntPtr pdf,
[MarshalAs(UnmanagedType.LPWStr)] string serverURL,
[MarshalAs(UnmanagedType.LPWStr)] string user,
[MarshalAs(UnmanagedType.LPWStr)] string password);

You may end up using “int” instead of IntPtr for the pdf document depending on how the rest of your project is handling these pointers and your platform (32 vs 64 bit), etc.

If you need a more complete example (with the document signing function imports, etc) please do not hesitate to contact us via the forums "


I have tried using an int type as for the document argument and passing it without reference, i am now getting a 0 as a result of this function call(operation succeeded) but my output document is not timestamped.

Do you have examples, sample code or documentation concerning ? I can't find any reference in the documentation

Thanks in advance
Sammy
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Timestamping with PDF Tools v4

Post by Ivan - Tracker Software »

Sorry, it was my mistake I have released wrong info.
The correct function declaration should be:

C++

Code: Select all

PXCPRO40_API HRESULT XCPAPI PXCp_SetTSAServerA(PDFDocument pdf, LPCSTR lpszServerURL, LPCSTR lpszUser, LPCSTR lpszPassword);
PXCPRO40_API HRESULT XCPAPI PXCp_SetTSAServerW(PDFDocument pdf, LPCWSTR lpszServerURL, LPCWSTR lpszUser, LPCWSTR lpszPassword);
C#:

Code: Select all

[DllImport("xcpro40")]
public static extern int PXCp_SetTSAServerW(int pdfDocument,
    [MarshalAs(UnmanagedType.LPWStr)] string serverURL,
    [MarshalAs(UnmanagedType.LPWStr)] string user,
    [MarshalAs(UnmanagedType.LPWStr)] string password);
Please let me know it that helps.
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.
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Re: Timestamping with PDF Tools v4

Post by SammyDev »

No problem Ivan,

I am using this function signature now, and I am getting a 0 result (operation completed sucessfully) but when I check the created output document, the time stamping has not been applied.

I either tried:

PXCp_SignDocumentUsingPFXW ...
PXCp_SetTSAServerA ...
PXCp_WriteDocumentW ..

or this order:

PXCp_SetTSAServerA ...
PXCp_SignDocumentUsingPFXW ...
PXCp_WriteDocumentW ...

I succeeded in time stamping with same certificate to the same tsa server when printing to the PDF-X Change printer driver and this worked to me. Looks like some bug in this function

Would you have some sample code that uses this function and that works for you that I could try ? As this function doesn't work for me here

Thanks in advance

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

Re: Timestamping with PDF Tools v4

Post by Ivan - Tracker Software »

I have updated our C# example for the PDF-Tools SDK (see attachment). Please check if the "Sign document" example works on your side.
Attachments
PXCProDemo.zip
(178.5 KiB) Downloaded 234 times
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.
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Re: Timestamping with PDF Tools v4

Post by SammyDev »

Ivan,

Thanks for the sample app. Unfortunately TSA signing still doesn't work from here.

Signing without TSA returns no problem, but when setting the TSA server, I am getting an AccessViolationException when executing the function SignDocumentUsingPFXW.
Exception detail:

System.AccessViolationException was caught
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=XCProDemoCSharp
StackTrace:
at XCPro40Demo.XCPro35_Defs.PXCp_SignDocumentUsingPFXW(Int32 hDocument, String pwszPFXFile, String pwszPFXPassword, Int32 PageNumber, PXC_RectF& rect, String pwszReason, String pwszLocation, String pwszContactInfo, String pwszImageFile, Int32 nFlags)
at XCPro40Demo.frmSignDocument.btnOK_Click(Object sender, EventArgs e) in C:\Users\sdeveille\Desktop\PXCProDemo\frmSignDocument.cs:line 132

Can you please advise us, as time stamping is an important feature we want to put in place soon.

Thanks.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Timestamping with PDF Tools v4

Post by John - Tracker Supp »

Hi Sammy - a bug was found and this will be corrected in the next release early next week, 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
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Re: Timestamping with PDF Tools v4

Post by SammyDev »

Hi John,

Ok please let me know when your latest build will be ready

Thanks
sammy.deveille@equisys.com
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Timestamping with PDF Tools v4

Post by John - Tracker Supp »

Hi Sammy - should be up and available now from ;

https://www.pdf-xchange.com/product/downloads/sdk

Cheers
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
SammyDev
User
Posts: 9
Joined: Thu Mar 10, 2011 2:56 pm

Re: Timestamping with PDF Tools v4

Post by SammyDev »

Hi John,

Just tested time stamping against the latest build. All working,
Cheers!
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Timestamping with PDF Tools v4

Post by John - Tracker Supp »

Excellent news - thanks Sammy :)
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
Post Reply