sign existing pdf file

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
oskpm
User
Posts: 41
Joined: Tue Aug 31, 2010 8:44 am

sign existing pdf file

Post by oskpm »

Hello,

signing a new created pdf file (PXC_NewDocument(...)) works fine, but how can you
sign an existing file?

some pseudocode so far...

Code: Select all


	PDFDocument pdf;
	HRESULT res = PXCp_Init(&pdf, "XXX","XXX");
	//...
	PXCp_ReadDocumentA(pdf, "c:\\1.pdf", d);

	_PXCPage*                page = NULL;
	PXC_GetPage(&pdf, 0, &page);
	// page ... OK

	//Cert stuff and pCertContext... OK

	hr = PXC_SignDocumentA(&pdf, pCertContext, page, &sr, 
	 "Cause", "Loc", "ContactInfo", NULL,
	 Sign_GR_NoGraphics| Sign_TX_Name | Sign_TX_Date | Sign_TX_Reason | Sign_TX_DName);
	
	if (IS_DS_FAILED(hr))
	{
	 // this fails ... Error Message via PXC_Err_FormatSeverity() is 'Error'
	}
Any hints?

Thanks in advance
Peter
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: sign existing pdf file

Post by Tracker Supp-Stefan »

Hello Peter,

The functions in the XCPRO40 LIB are aimed at manipulating existing documents, so please have a look at
PXCp_SignDocumentW and the other two Signature functions in the XCPRO library.

Best,
Stefan
oskpm
User
Posts: 41
Joined: Tue Aug 31, 2010 8:44 am

Re: sign existing pdf file

Post by oskpm »

Hello Stefan,

thanks for reply.

Unfortunately also with the functions from XCPro (PXCp_...) there is no success:

My sample code:

Code: Select all

HRESULT hr ;
	PDFDocument pdf;

	hr = PXCp_Init(&pdf, "xxx","xxx");
	ASSERT( IS_DS_SUCCESSFUL(hr) );	// OK


	hr =  PXCp_ReadDocumentW(pdf, L"c:\\1.pdf", 0);
	ASSERT(  IS_DS_SUCCESSFUL(hr) ); // OK
	

	HCERTSTORE       hCertStore = NULL;       
	PCCERT_CONTEXT   pCertContext = NULL;	
	hCertStore = CertOpenSystemStore(NULL, "MY");
	
	ASSERT(hCertStore); // OK 
	

	pCertContext = CryptUIDlgSelectCertificateFromStore(
                               hCertStore,      
                               this->m_hWnd,
                               NULL, 
                               NULL,
                               CRYPTUI_SELECT_LOCATION_COLUMN,
                               0,
                               NULL);
	ASSERT( pCertContext ); //OK


	PXC_RectF sr;
	sr.left = I2L(1);
	sr.right = I2L(4);
	sr.top = I2L(3);
	sr.bottom = I2L(4);

	hr = PXCp_SignDocumentW(&pdf, pCertContext, 0, &sr,  L"Test Reason", L"Test Location", 	 L"Test Contact Info", NULL,
							 Sign_GR_Name | Sign_TX_Name | Sign_TX_Date |Sign_TX_Location | Sign_TX_Reason | 
							 Sign_TX_DName);

	///////////////////
	// not successful /
	///////////////////
	ASSERT( IS_DS_SUCCESSFUL(hr) );
Do you have any other ideas?

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

Re: sign existing pdf file

Post by Tracker Supp-Stefan »

Hello Peter,

Checking with the guys in our dev team now. I hope to have some more ideas for you shortly.

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

Re: sign existing pdf file

Post by Ivan - Tracker Software »

Code: Select all

...
///////////////////
   // not successful /
   ///////////////////
   ASSERT( IS_DS_SUCCESSFUL(hr) );
Can you say the value or hr when code fails?
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.
oskpm
User
Posts: 41
Joined: Tue Aug 31, 2010 8:44 am

Re: sign existing pdf file

Post by oskpm »

Hello Ivan,

the value of hr is -2113394928

PXC_Err_FormatErrorCode() gives 'Error' as error message


Regards,
Peter
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: sign existing pdf file

Post by Lzcat - Tracker Supp »

 
hr = PXCp_SignDocumentW(&pdf, pCertContext, 0, &sr, L"Test Reason", L"Test Location", L"Test Contact Info", NULL,
Sign_GR_Name | Sign_TX_Name | Sign_TX_Date |Sign_TX_Location | Sign_TX_Reason |
Sign_TX_DName);
In your code signt '&' (ampersand) marked as red shold be removed. You are lucky that you did not got crash.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
oskpm
User
Posts: 41
Joined: Tue Aug 31, 2010 8:44 am

Re: sign existing pdf file

Post by oskpm »

 
In your code signt '&' (ampersand) marked as red shold be removed. You are lucky that you did not got crash.
That's it, thanks a lot!

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

Re: sign existing pdf file

Post by Tracker Supp-Stefan »

Glad to hear it's working now Peter!

Cheers,
Stefan
Post Reply