Please help with PXC_SignDocumentXXX in VB.NET
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
-
- User
- Posts: 29
- Joined: Thu Sep 04, 2008 2:06 pm
Please help with PXC_SignDocumentXXX in VB.NET
Hello,
I spent several hours trying to make any of the PXC_SignDocumentXXX funtions work but with no luck.
I have a simple test scenario - create new PDF document, add a new page and a picture on the page (our intend is to use PDF for e-archiving of scanned documents). Then I add another new page to put the sign on and try to sign the document - which failes.
Without trying to sign the document, I am able to save it and view it in the Adobe Reader.
---------------------------------------------------
#My 1. approach - using PXC_SignDocumentW
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentW( _
ByVal pdf As Integer _
, ByVal PCertt As IntPtr _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function
...
Dim cert As New X509Certificate2("123pass123456.pfx", "123456")
PXC_SignDocumentW( _
myPdfDoc _
, cert.Handle _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0) _
=> fails with an AccessViolationException
---------------------------------------------------
#My 2. approach - using PXC_SignDocumentBufW
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentBufW( _
ByVal pdf As Integer _
, ByVal pPXCBuf() As Byte _
, ByVal nPFXLen As Integer _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszPFXPassword As String _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function
...
' get PKCS#7
Dim cert As New X509Certificate2("123pass123456.pfx", "123456")
Dim certColl As New X509Certificate2Collection
certColl .Add(cert)
Dim bin() As Byte = certColl .Export(X509ContentType.Pkcs7, "123456")
' sign PDF document
PXC_SignDocumentBufW( _
myPdfDoc _
, bin _
, bin.Length _
, "123456" _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0)
=> fails with an undocumented error code: -2081153022
---------------------------------------------------
#My 3. approach - using PXC_SignDocumentUsingPFXW
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentUsingPFXW( _
ByVal pdf As Integer _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszPFXFile As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszPFXPassword As String _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function
...
PXC_SignDocumentUsingPFXW( _
myPdfDoc _
, "123pass123456.pfx" _
, "123456" _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0)
=> fails with an AccessViolationException
---------------------------------------------------
I tried all functions with several certificates, including the one provided in this example project:
https://forum.pdf-xchange.com/ ... 14&p=17427
I also tried all versions with several values for dwFlags, passing NULL (Nothing in VB) as lpwszImageFile and many other approaches I can't remeber...
I will be gratefull for any hint
Ondrej Bouda
---------------------------------------------------
My configuration:
* PDF-XChange PRO 4 SDK, build 4.0.0.150
* VB.NET 2008, ver. 9.0.30729.1 SP (with SP1)
* Win Vista Business SP1
I spent several hours trying to make any of the PXC_SignDocumentXXX funtions work but with no luck.
I have a simple test scenario - create new PDF document, add a new page and a picture on the page (our intend is to use PDF for e-archiving of scanned documents). Then I add another new page to put the sign on and try to sign the document - which failes.
Without trying to sign the document, I am able to save it and view it in the Adobe Reader.
---------------------------------------------------
#My 1. approach - using PXC_SignDocumentW
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentW( _
ByVal pdf As Integer _
, ByVal PCertt As IntPtr _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function
...
Dim cert As New X509Certificate2("123pass123456.pfx", "123456")
PXC_SignDocumentW( _
myPdfDoc _
, cert.Handle _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0) _
=> fails with an AccessViolationException
---------------------------------------------------
#My 2. approach - using PXC_SignDocumentBufW
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentBufW( _
ByVal pdf As Integer _
, ByVal pPXCBuf() As Byte _
, ByVal nPFXLen As Integer _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszPFXPassword As String _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function
...
' get PKCS#7
Dim cert As New X509Certificate2("123pass123456.pfx", "123456")
Dim certColl As New X509Certificate2Collection
certColl .Add(cert)
Dim bin() As Byte = certColl .Export(X509ContentType.Pkcs7, "123456")
' sign PDF document
PXC_SignDocumentBufW( _
myPdfDoc _
, bin _
, bin.Length _
, "123456" _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0)
=> fails with an undocumented error code: -2081153022
---------------------------------------------------
#My 3. approach - using PXC_SignDocumentUsingPFXW
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentUsingPFXW( _
ByVal pdf As Integer _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszPFXFile As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszPFXPassword As String _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszReason As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszLocation As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszContactInfo As String _
, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpwszImageFile As String _
, ByVal dwFlags As Integer _
) As Integer
End Function
...
PXC_SignDocumentUsingPFXW( _
myPdfDoc _
, "123pass123456.pfx" _
, "123456" _
, ByVal page As Integer _
, ByVal rect As PXC_RectF _
, myPage _
, pageSize _
, "test" _
, "anywhere" _
, "test@test" _
, "" _
, 0)
=> fails with an AccessViolationException
---------------------------------------------------
I tried all functions with several certificates, including the one provided in this example project:
https://forum.pdf-xchange.com/ ... 14&p=17427
I also tried all versions with several values for dwFlags, passing NULL (Nothing in VB) as lpwszImageFile and many other approaches I can't remeber...
I will be gratefull for any hint
Ondrej Bouda
---------------------------------------------------
My configuration:
* PDF-XChange PRO 4 SDK, build 4.0.0.150
* VB.NET 2008, ver. 9.0.30729.1 SP (with SP1)
* Win Vista Business SP1
-
- Site Admin
- Posts: 3556
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: Please help with PXC_SignDocumentXXX in VB.NET
Can you send me complete sample project which I can test here (without certificate for sure). Looks like trouble is into functions declarations.
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.
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.
-
- User
- Posts: 29
- Joined: Thu Sep 04, 2008 2:06 pm
Re: Please help with PXC_SignDocumentXXX in VB.NET
Here is the sample project.
I noticed that the PXC_SignDocumentW and PXC_SignDocumentUsingPFXW don't throw AccessViolationException anymore - now they simply freeze instead...
Thank you for your effort!
I noticed that the PXC_SignDocumentW and PXC_SignDocumentUsingPFXW don't throw AccessViolationException anymore - now they simply freeze instead...
Thank you for your effort!
You do not have the required permissions to view the files attached to this post.
-
- Site Admin
- Posts: 3556
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: Please help with PXC_SignDocumentXXX in VB.NET
Sorry, I'm not so familiar with VB, but when you create a PFX from the certificate, it isn't a valid PFX file. You can check this - just save the buffer you get here:
into the file with .pfx extension, and when try to open this file with Explorer instead of seeing the Certificate Import Wizard you will see an error message window:
"Invalid Public Key Security Object File. This file is invalid for use as the following: Personal Information Exchange".
But when I use signing via AddSign_UsingPFXW, all works fine.
Code: Select all
Dim cert() As Byte = certcoll.Export(X509ContentType.Pkcs7, CertPassw)
"Invalid Public Key Security Object File. This file is invalid for use as the following: Personal Information Exchange".
But when I use signing via AddSign_UsingPFXW, all works fine.
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.
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.
-
- User
- Posts: 29
- Joined: Thu Sep 04, 2008 2:06 pm
Re: Please help with PXC_SignDocumentXXX in VB.NET
Ad AddSign_UsingPFXW - I tested this function on 3 other computers with the same result: Task manager shows that the application uses 50% CPU, application will never finish...
2x test config: Win Vista Bussiness + .NET 3.5 + all OS updates
1x test config: Win XP Professional + .NET 3.5 + all OS updates
1x test config: clean installation Win XP Professional + .NET 3.5 only
Is there any external required library that I could be missing?
Could the problem be caused by the .NET 3.5 enviroment?
Ad PXC_SignDocumentBufW - according to the documentation, the certificate should come in the PKCS#7 format. Should you save the buffer as ".p7b", you will be able to import it:
Note: Windows uses the ".p7b" extension for files containing PKCS#7, and ".pfx" for PKCS#12 - for this reason you weren't able to import a ".pfx" file with ".p7b" content.
I tried to use the function directly with the PKCS#12 file content (without converting it to PKCS#7) and I got the same freezing as with the other functions:
It seems, that there is a mistake in the documentation and the PXC_SignDocumentBufW function requires rather a PKCS#12 content - is it so?
2x test config: Win Vista Bussiness + .NET 3.5 + all OS updates
1x test config: Win XP Professional + .NET 3.5 + all OS updates
1x test config: clean installation Win XP Professional + .NET 3.5 only
Is there any external required library that I could be missing?
Could the problem be caused by the .NET 3.5 enviroment?
Ad PXC_SignDocumentBufW - according to the documentation, the certificate should come in the PKCS#7 format. Should you save the buffer as ".p7b", you will be able to import it:
Code: Select all
IO.File.WriteAllBytes("t-cert.pk7", cert)
I tried to use the function directly with the PKCS#12 file content (without converting it to PKCS#7) and I got the same freezing as with the other functions:
Code: Select all
Dim cert() As Byte = IO.File.ReadAllBytes("123pass123456.pfx")
-
- Site Admin
- Posts: 3556
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: Please help with PXC_SignDocumentXXX in VB.NET
Yes, PKCS#12 should be, not PKCS#7.
Freezing of Sing functions can be a result of wrong rect passed to them -- looks like problem is into the routing which calculates font's sizes for strings into signature appearance.
Freezing of Sing functions can be a result of wrong rect passed to them -- looks like problem is into the routing which calculates font's sizes for strings into signature appearance.
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.
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.
-
- User
- Posts: 29
- Joined: Thu Sep 04, 2008 2:06 pm
Re: Please help with PXC_SignDocumentXXX in VB.NET
Well, I tried to play with rect values - small/large rect height and width, swapping left/right and bottom/top, I tried to pass the values from the example in the documentation - but with no luck, I get always the same 'freezing'.
Any other idea?
I'd suppose that if the function gets wrong parameters, it should abort with an error code but never freeze...
Any other idea?
I'd suppose that if the function gets wrong parameters, it should abort with an error code but never freeze...
-
- User
- Posts: 29
- Joined: Thu Sep 04, 2008 2:06 pm
Re: Please help with PXC_SignDocumentXXX in VB.NET
Any progress in this?
Did you try to compile the project and run the .exe on a clean WinXP installation (with only .NET 3.5 installed)?
At this time, we are evaluating the PDF-XChange PRO SDK if it is suitable for our applications and untill this it looked good...
Did you try to compile the project and run the .exe on a clean WinXP installation (with only .NET 3.5 installed)?
At this time, we are evaluating the PDF-XChange PRO SDK if it is suitable for our applications and untill this it looked good...
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: Please help with PXC_SignDocumentXXX in VB.NET
Hello.
Please, look at the sample project which is attached to this message.
HTH
Please, look at the sample project which is attached to this message.
HTH
You do not have the required permissions to view the files attached to this post.
-
- User
- Posts: 29
- Joined: Thu Sep 04, 2008 2:06 pm
Re: Please help with PXC_SignDocumentXXX in VB.NET
Thank you very much, it worsk!
The problem was in the PXC_SignDocumentXXX function declarations:
where the rectangle should be passed by reference:
The problem was in the PXC_SignDocumentXXX function declarations:
Code: Select all
<DllImport("pxclib40")> _
Public Function PXC_SignDocumentUsingPFXW( ... )
Code: Select all
ByVal rect As PXC_RectF ' wrong - does not work
ByRef rect As PXC_RectF ' works fine
-
- Site Admin
- Posts: 5219
- Joined: Tue Jun 29, 2004 10:34 am
- Location: United Kingdom
Re: Please help with PXC_SignDocumentXXX in VB.NET
Pleased all is well
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
Best regards
Tracker Support
http://www.tracker-software.com