Print Page | Close Window

Sign field name is showing as JUNK value

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3921
Printed Date: 25 Apr 24 at 1:00PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Sign field name is showing as JUNK value
Posted By: rizzz86
Subject: Sign field name is showing as JUNK value
Date 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.

https://smallpdf.com/shared#st=57009b31-59b6-476e-a32e-909fbea6e8c7&fn=Encrypted+and+Signed.pdf&ct=1622118186928&tl=share-document&rf=link" rel="nofollow - 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;
        }



Replies:
Posted By: Ingo
Date Posted: 28 May 21 at 11:18PM
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.

This will give you a sample:
https://www.debenu.com/kb/add-visual-digital-signature-to-a-pdf-programmatically/



-------------
Cheers,
Ingo



Posted By: rizzz86
Date Posted: 02 Jun 21 at 7:20AM
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.



Posted By: Ingo
Date Posted: 03 Jun 21 at 8:50PM
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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk