DigitalSignature Sign New PDF


DigitalSignature Sign New PDF

What is PDF?

  • PDF (short for Portable Document Format) is a reasonably standard text file format of Adobe Systems. Similar to the Word (.doc) format, PDF supports raw text (text) along with fonts, graphic images, sounds, and many other effects. However, displaying PDF documents does not depend on the working environment of the user (machine configuration, software, and operating system).

Why PDF?

  • PDF is an accessible text file format of Adobe Systems. Just like standard text files such as Word files, PDF support contain text documents, images ... With high-security features, PDF is currently one of the text files used quite a lot to store essential data in the world.
  • To read the PDF file on your computer, you must have software that supports this format. Popular software today is Adobe Reader or Foxit Reader.
  • Surely, PDF files have many advantages, and here are some of the most common benefits that you refer to.
  • As a technology software, the first requirement is safety and security, we can say that the PDF file has high security and a variety of options for users to choose.
  • The range of support on most devices from computers to mobile devices.
  • The PDF file also features regular documents; the PDF format can also display completely the same in all different working environments.
  • And notably, the file size is usually quite small.
  • Some Key Features Of PDF Files
  • PDF files are usually quite small in size, so low volumes are easy to share via the internet.
  • Encrypted PDF files with a lot of software, so the security is very high.
  • PDF is viewed and presented on any device, including computers, laptops, mobile devices, smartphones, etc. - Create files and convert to other text files quickly.

When PDF?

  • In the 1990s, when information technology was not developed as it is today, there were many inadequacies in the issue of image data transmission, content, documents with large file images that could not be transmitted. Also, computers and devices were not as modern as they are today, they could handle only a small part, so at that time, an invention needed to solve the problems that people. As a result, software developers have started using links to other resources on the computer. To reduce the amount of content, you need to transfer or save to your computer. And that is the reason for the advent of PDF.
  • However, the popularity of the PDF format at the beginning was relatively slow. Early versions of PDF did not support external hyperlinks, reducing its usefulness on the web. The increased file size compared to plain text also means that the time it takes to download a PDF document will be longer, which is also a problem with slow modems of the time.
  • Adobe soon offered the Acrobat Reader (now Adobe Reader) for free and continues to support the prototype PDF format. Eventually, PDF became the standard format for printable documents on the web.
  • The PDF format has been changed many times and is currently under development.

What is Digital Signature?

  • Digital Signature is considered as a subset of Electronic Signature. Unlike handwritten signatures, a Digital Signature is challenging to forge cause it contains unique encrypted information of the signer and easily verified.
  • The Public Key Digital Signature (or Public Key infrastructure) is a model that uses cryptographic techniques to attach to each user a crucial public-secret pair and thereby can digitally sign documents, as well as exchanging confidential information. Public keys are usually distributed through public-key authentication. The process of using digital signatures includes two procedures: signature creation and signature checking.
  • The concept of digital signatures - though often used in the same sense as digital signatures, actually has a broader meaning. An electronic signature refers to any method (not necessarily a password) to identify the owner of an electronic document. Digital signatures include both a telex address and a paper signature transmitted by fax.

The advantages of digital signatures

The use of digital signatures offers several advantages:

  • Traceability
  • Public key cryptography systems allow you to encrypt text with a secret key that only the owner of the key knows. To use a Digital signatures, the text needs to be encrypted using a hash function (the "hashed" text into a string, usually a fixed length and shorter than the text) and then using the secret key of the key owner. To encrypt, then we get a digital signature. When it is necessary to check, the receiver decodes (with the Digital signatures) to retrieve the original string (generated through the original hash) and checks it with the hash of the received text. If these two values ​​(strings) match, the recipient can trust that the text comes from the owner of the secret key. Of course, we cannot guarantee 100% that the document is not tampered with because someone can still break the system.
  • The issue of authentication is especially essential for financial transactions. For example, a bank branch sends a packet to the center in the form of (a, b).
  • Here, a is the account number, and b is the amount transferred to that account.
  • A fraudster may send a certain amount of money to retrieve the packet's content and retransmit the resulting packet repeatedly for profit (retransmission of the packet).
  • Integrity
  • Both parties involved in the information process can trust that the text has not been modified during transmission because if the text is changed, the hash function will be changed and immediately detected. The encryption process will hide the content of the packet for third parties but does not prevent changes in its content. An example of this case is a homomorphism attack: following the example above, a fraudster deposited USD 1,000,000 into his account, blocking the packet (a, b) that spent branch sent to the center and then sent a package (a, b3) instead to become a millionaire immediately! But that is the security issue of the branch for the banking center. This problem is not necessarily related to the integrity of the information. Message from the sender to the branch, because someone has hashed and encrypted the data to send to its correct destination, the branch, the remaining issue of the branch's security to its center.
  • Undeniableity
  • In a transaction, a party may refuse to receive a document that is sent by itself. To prevent this possibility, the recipient may require the sender to attach a digital signature to the document. When there is a dispute, the recipient will use this signature as evidence for a third party to resolve. However, someone still can reveal the secret key and the undeniable nor completely attainable.

Sign an Existing PDF with Digital Signature

  • With the outstanding advantages of the security aspect of Digital Signatures, along with the popularity of PDF format, you will probably want to combine both of the above to bring a protocol suite that is both highly secure, medium universal in practice. Then, PDF Office Component will be the best choice for you.
  • PDF Office Component allows you to sign an existing PDF document that identifies the signer of the document.



  • ContactInfo
  • LocationInfo
  • Reason
  • Document certification status

Source Code

  • First and foremost, you must have yourself a PDF document. You can achieve this by leveraging the PdfDocument class:
  • C# Version: PdfDocument doc = new PdfDocument();
  • VB Version: Dim doc As New PdfDocument()
  • You can then add new pages to this document:
  • C# Version: PdfPage page = doc.Pages.Add();
  • VB Version: Dim page As PdfPage = doc.Pages.Add()
  • The PdfDigitalSignature class allows you to create a new digital signature. We take advantage of that class with the following code snippet:
    PdfDigitalSignature signature = new PdfDigitalSignature(doc, page, pdfCert, "Signature");

You can even create a new Certificate with the following snippet:

    PdfCertificate pdfCert = new PdfCertificate(Cert, Password);
  • You can take advantage of these snippets and embed them in your application after you have installed PDF Packet to bring the ability to sign your PDF documents digitally. And here is an illustration of the usage of this library:
  • C# Version:
            // Create a new instance of PdfDocument class.
            PdfDocument doc = new PdfDocument();
            PdfDigitalSignature signature = null;
            PdfBitmap bmp = null;
            PdfGraphics g;
            PdfPage page = doc.Pages.Add();
            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
            PdfPen pen = new PdfPen(brush, 0.2f);
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);

                PdfCertificate pdfCert = new PdfCertificate(CommonDataPath + "\\Key.pfx", "password");
                signature = new PdfDigitalSignature(page, pdfCert, "Signature");
                bmp = new PdfBitmap(CommonDataPath + "\\Logo.gif");

                signature.Bounds = new RectangleF(new PointF(5, 5), bmp.PhysicalDimension);
                signature.ContactInfo = "";
                signature.LocationInfo = "California";
                signature.Reason = "I am author of this document.";

                if (Certificated)
                    signature.Certificated = true;
                    signature.Certificated = false;
                g = signature.Appearence.Normal.Graphics;
            catch (System.ArgumentNullException exc)
                g = signature.Appearence.Normal.Graphics;

                ShowWarning("Warning Certificate not found \"Cannot sign This Document\": " + exc.Message);
                //Draw the Text at specified location.
                g.DrawString("Warning this document is not signed", font, brush, new PointF(0, 20));
                g.DrawString("Create a self signed Digital ID to sign this document", font, brush, new PointF(20, 40));
                g.DrawLine(pen, new PointF(0, 100), new PointF(page.GetClientSize().Width, 200));
                g.DrawLine(pen, new PointF(0, 200), new PointF(page.GetClientSize().Width, 100));
            string validto = "Valid To: " + signature.Certificate.ValidTo.ToString();
            string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();

            g.DrawImage(bmp, 0, 0);

            doc.Pages[0].Graphics.DrawString("Certificate Info", font, pen, brush, 0, 70);
            doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 20, 90);
            doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 20, 110);

            doc.Pages[0].Graphics.DrawString("- Click on the signature on this page to validate Signature\n- Click document status icon on the bottom left of the acrobat reader to check Document Status", font, pen, brush, 0, 150);

            // Save the PDF file.
            var outputPath = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + ".pdf");

            return outputPath;

VB Version:

            ' Create a new instance of PdfDocument class.
            Dim doc As New PdfDocument()
            Dim signature As PdfDigitalSignature = Nothing
            Dim bmp As PdfBitmap = Nothing
            Dim g As PdfGraphics
            Dim page As PdfPage = doc.Pages.Add()
            Dim brush As New PdfSolidBrush(Color.Black)
            Dim pen As New PdfPen(brush, 0.2F)
            Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)

                Dim pdfCert As New PdfCertificate(CommonDataPath & "\Key.pfx", "password")
                signature = New PdfDigitalSignature(page, pdfCert, "Signature")
                bmp = New PdfBitmap(CommonDataPath & "\Logo.gif")

                signature.Bounds = New RectangleF(New PointF(5, 5), bmp.PhysicalDimension)
                signature.ContactInfo = ""
                signature.LocationInfo = "California"
                signature.Reason = "I am author of this document."

                If Certificated Then
                    signature.Certificated = True
                    signature.Certificated = False
                End If
                g = signature.Appearence.Normal.Graphics
            Catch exc As System.ArgumentNullException
                g = signature.Appearence.Normal.Graphics

                ShowWarning("Warning Certificate not found ""Cannot sign This Document"": " & exc.Message)
                'Draw the Text at specified location.
                g.DrawString("Warning this document is not signed", font, brush, New PointF(0, 20))
                g.DrawString("Create a self signed Digital ID to sign this document", font, brush, New PointF(20, 40))
                g.DrawLine(pen, New PointF(0, 100), New PointF(page.GetClientSize().Width, 200))
                g.DrawLine(pen, New PointF(0, 200), New PointF(page.GetClientSize().Width, 100))
            End Try
            Dim validto As String = "Valid To: " & signature.Certificate.ValidTo.ToString()
            Dim validfrom As String = "Valid From: " & signature.Certificate.ValidFrom.ToString()

            g.DrawImage(bmp, 0, 0)

            doc.Pages(0).Graphics.DrawString("Certificate Info", font, pen, brush, 0, 70)
            doc.Pages(0).Graphics.DrawString(validfrom, font, pen, brush, 20, 90)
            doc.Pages(0).Graphics.DrawString(validto, font, pen, brush, 20, 110)

            doc.Pages(0).Graphics.DrawString("- Click on the signature on this page to validate Signature" & vbLf & "- Click document status icon on the bottom left of the acrobat reader to check Document Status", font, pen, brush, 0, 150)

            ' Save the PDF file.
            Dim outputPath = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & ".pdf")

            Return outputPath

The full source code of this example is available in our PDF package.

A live demo for DigitalSignature Sign New PDF is also available on our site. If you also need PDF functionality, check out our PDF online demos.

45-Day Money Back Guarantee

We will refund your full money in 45 days
if you are not satisfied with our products

Buy Now
You have successfully subcribed to our mailing list.
Dont miss out Get update on new articles and other opportunities Subscribe