DigitalSignature Sign Existing PDF

Pdf

DigitalSignature Sign Existing 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:

  1. 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).
  1. 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.
  1. 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.

Example

Properties

  • Certificate file - Choose the certificate file
  • Password - If you protected the certificate file with a password
  • Signature properties like
    • Reason - add the reason on signature
    • Contact - add contact details like Phone, Email, Messenger, etc.
    • Location - add the location of the signature

Source Code

  • 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 two 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:
    PdfDigitalSignature signature;
    PdfBitmap bmp;
    if (string.IsNullOrWhiteSpace(SourceFile) || string.IsNullOrWhiteSpace(Cert) || !SourceFile.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase) || !Cert.EndsWith(".pfx", StringComparison.OrdinalIgnoreCase))
    {
        ShowError("Please select a PDF document to sign, along with certificate and the password");
        return null;
    }
    PdfCertificate pdfCert;
    try
    {
        pdfCert = new PdfCertificate(Cert, Password);
        using (PdfImportedDocument doc = new PdfImportedDocument(SourceFile))
        {
            bmp = new PdfBitmap(CommonDataPath + "\\Logo.gif");
            PdfPageBase page = doc.Pages[0];
            signature = new PdfDigitalSignature(doc, page, pdfCert, "Signature");
            
            signature.Bounds = new RectangleF(new PointF(5, 5), bmp.PhysicalDimension);
            signature.ContactInfo = Contact;
            signature.LocationInfo = Location;
            signature.Reason = Reason;


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

            return outputPath;
        }
    }
    catch (Exception ex)
    {
        ShowError("Error adding digital signature: " + ex.Message);
        return null;
    }
  • VB Version:
    Dim signature As PdfDigitalSignature
    Dim bmp As PdfBitmap

    If String.IsNullOrWhiteSpace(SourceFile) OrElse String.IsNullOrWhiteSpace(Cert) OrElse (Not SourceFile.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)) OrElse (Not Cert.EndsWith(".pfx", StringComparison.OrdinalIgnoreCase)) Then
        ShowError("Please select a PDF document to sign, along with the certificate and the password")
        Return Nothing
    End If

    Dim pdfCert As PdfCertificate
    Try
        pdfCert = New PdfCertificate(Cert, Password)
        Using doc As New PdfImportedDocument(SourceFile)
            bmp = New PdfBitmap(CommonDataPath & "\Logo.gif")

            Dim page As PdfPageBase = doc.Pages(0)
            signature = New PdfDigitalSignature(doc, page, pdfCert, "Signature")

            signature.Bounds = New RectangleF(New PointF(5, 5), bmp.PhysicalDimension)
            signature.ContactInfo = Contact
            signature.LocationInfo = Location
            signature.Reason = Reason


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

            Return outputPath
        End Using
    Catch ex As Exception
        ShowError("Error adding digital signature: " & ex.Message)
        Return Nothing
    End Try

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

A live demo for DigitalSignature Sign Existing 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