Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
Sign field name is showing as JUNK value |
Post Reply ![]() |
Author | |
rizzz86 ![]() Beginner ![]() ![]() Joined: 17 Oct 16 Location: Bahrain Status: Offline Points: 15 |
![]() ![]() ![]() ![]() ![]() Posted: 27 May 21 at 1:36PM |
I am facing an issue where the encrypted and signed document is showing the sign field name with junk value.
This is the resultant PDF which is showing sign field name as junk. If we sign PDF without encrypting the PDF it shows the correct field name. But if we do the encryption first the field name becomes junk. I need help regarding this behavior and how can I resolve this Following is a code snippet that we are using to Encrypt and then sign the PDF: public string DigitallySignAndEncryptPDF(string fileToSign, string fieldName, string certificateFile, string certificatePassword, string imageFile, bool isEncrypt) { string signedPath = ""; string inputFile = ""; try { byte[] pdfBytes = File.ReadAllBytes(fileToSign); if (isEncrypt) pdfBytes = ProtectPDF(pdfBytes, "", out bool error); X509Certificate2 cert = new X509Certificate2(certificateFile, certificatePassword); inputFile = Path.Combine(m_CurrentDirectory, "Input_" + Guid.NewGuid() + ".pdf"); File.WriteAllBytes(inputFile, pdfBytes); signedPath = Path.Combine(m_CurrentDirectory, "Output_" + Guid.NewGuid() + ".pdf"); int nResult = QP.SignFile(inputFile, m_MasterPassword, "Test Sign Field", signedPath, certificateFile, certificatePassword, m_ReasonToSign, m_LocationOfSign, m_ContactInforToSign); } catch(Exception ex) { MessageBox.Show(ex.Message); signedPath = ""; } finally { if (string.IsNullOrEmpty(inputFile) == false && File.Exists(inputFile)) { File.Delete(inputFile); } } return signedPath; } public byte[] ProtectPDF(byte[] pdfToProtect, string password, out bool error) { error = true; byte[] protectedPDF = null; try { int nLoaded = QP.LoadFromString(pdfToProtect, ""); if (nLoaded == 1) { int nProtected = QP.Encrypt(m_MasterPassword, password, 3, QP.EncodePermissions(0, 0, 0, 0, 0,0, 0, 0)); if (nProtected == 1) { protectedPDF = QP.SaveToString(); error = false; } } } catch (Exception ex) { ; } return protectedPDF; } |
|
![]() |
|
Ingo ![]() Moderator Group ![]() ![]() Joined: 29 Oct 05 Status: Offline Points: 3529 |
![]() ![]() ![]() ![]() ![]() |
Hi Rizwan,
this isn't possible in one process! You can set a password/encryption in the first process and reload the file in a further process to sign it. Passwords can be set directly into a pdf and within the sign process. https://www.debenu.com/kb/add-visual-digital-signature-to-a-pdf-programmatically/ |
|
Cheers,
Ingo |
|
![]() |
|
rizzz86 ![]() Beginner ![]() ![]() Joined: 17 Oct 16 Location: Bahrain Status: Offline Points: 15 |
![]() ![]() ![]() ![]() ![]() |
Thanks Ingo for your feedback.
I tried out what you have suggested. But it still shows the junk field name. Then I tried the same from Debenu Demo app and there it works fine. The only difference I see is the DLL that is being used in the Demo app and our project. Demo app is using "DebenuPDFLibraryAX1411.dll" and our project is using "DebenuPDFLibraryDLL1212.dll". Still trying to figure out if this is the issue or not. |
|
![]() |
|
Ingo ![]() Moderator Group ![]() ![]() Joined: 29 Oct 05 Status: Offline Points: 3529 |
![]() ![]() ![]() ![]() ![]() |
Hi Rizwan,
AX means activeX but you've used the normal dll. Your release 12.12 seems to be a bit older than the release 14.11 as activeX - perhaps there's a problem... A LastErrorCode after each function-call shows any errors or success... |
|
Cheers,
Ingo |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store