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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Sign field name is showing as JUNK value
  FAQ FAQ  Forum Search   Register Register  Login Login

Sign field name is showing as JUNK value

 Post Reply Post Reply
Author
Message
rizzz86 View Drop Down
Beginner
Beginner
Avatar

Joined: 17 Oct 16
Location: Bahrain
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote rizzz86 Quote  Post ReplyReply Direct Link To This Post Topic: Sign field name is showing as JUNK value
    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;
        }
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3437
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
rizzz86 View Drop Down
Beginner
Beginner
Avatar

Joined: 17 Oct 16
Location: Bahrain
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote rizzz86 Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3437
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store