PDF Document Security


PDF Document Security

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

PDF's history

  • PDF - Portable Document Format, is a mobile document format. Adobe first released it in the early 90s as a way to store documents entirely in a file. Because at the time, the site was still in its infancy when PDFs were in development, their primary uses are for publishing desktop print documents. Companies use PDFs to store posters, leaflets, and other similar files for physical printing.
  • It takes a long time for PDF to continue. PDF didn't have all of the built-in features available today, and using dial-up access to download a large PDF file was extremely slow. After a few years, Adobe released Adobe Reader for free for all, and PDF eventually defeated some competitors to become the standard file for fixed documents. More interestingly, PDF was originally a proprietary format, meaning Adobe controls the PDF and how it works. But in 2008, they abandoned this ownership, and PDF became an open standard. Now PDF files still have a set of essential properties, but they are independent of Adobe. Indeed, you can find dozens of other PDF readers and editors.

How PDF?

  • To know why PDF was so revolutionary when it came out, we had to understand what the standard was at the time. In the early 90's, professional software used to design graphics and documents led to large files being unbearable, especially when we embed them with images, fonts, and text. Remember that computers during this time only have a fraction of the processing power of the computer you are using today, meaning that every bit of performance is essential.
  • To overcome this problem, software developers started using links to other resources on the computer. Let's say you used unique fonts in your document. Instead of saving all the data for this font inside your document, it will pull the necessary information from the font settings folder on your computer. This method will reduce the load on the document file, making it lighter.
  • Everything will work fine as long as you do not move the font on the computer. However, if you take the file to another computer without installing your particular font, it will not look like it anymore. You can imagine the pain of spending all the time creating an important document and then having it look awful because you didn't keep links to graphic elements exist. PDF files have changed this. Adobe has found a way to assemble all the parts of a file and make it smaller. This new method is a far more effective way than the solution developers used before PDF was available on the market. That's why PDF has become a standard.

Why PDF?

  • The portability of PDF is crucial. The PDF files look the same no matter which device do we open it. Whether you're using Windows 10, Mac, Chrome OS, Android, Windows Phone, iPad or Windows XP - for any software and hardware, PDF files are always suitable. Information in PDF does not depend on the device of the creator or the viewer. Include fonts, images, charts, and it doesn't seem to be a problem.
  • Compare when you send a Microsoft Word document to someone. What happens if the recipient doesn't have Microsoft Word on his/her computer? Sure, they can open it with Google Docs, but the document might look very different because Docs displays files differently. If you spend a dozen of time creating tables, images, and other elements and it may not be as original. And what if they try to open a Word document on their phone?
  • As a general rule, PDF files are for viewing. What you see when you click Save is what other recipients see. And you don't even need to install a reader - most modern browsers can open PDFs without a problem. While you can edit PDFs, you are limited to a few free options unless you have to pay for premium software like Adobe Acrobat, Foxit PhantomPDF, or Nitro Reader.

Why is PDF still so popular?

  • Besides the portability described above, PDF files carry several other features that have contributed to their popularity.
  • PDF files allow fine-tuned security settings. When creating a PDF, you can turn off the ability to print, leave comments, or copy the text of the viewer. Therefore, when governments and businesses place forms online, they can significantly restrict them to prevent abuse. For added security, you can also protect it with a PDF password.
  • You may have noticed that PDFs also work with fill fields. PDF creators can place highlighted blocks anywhere in the document to show where they want the recipient to add information. Even if they have restricted editing, viewers can still enter names, addresses, and other pertinent information into these fields. PDFs support digital signing, so you can add your approval to a document without having to print it out.
  • Small features like adding comments, bookmarks, stamps, hyperlinks, and other live content have kept PDF files relevant for up to the current decade. Optical recognition software can capture documents and quickly turn them into PDF files, and some independent publishers even offer books as PDF files. Ease of use, rich feature set, and popularity have kept PDF necessary in everyday computing life.
  • So, you have learned about how PDF started, how it works, and what makes it so famous and popular. In a world of different operating systems, screen sizes, browsers, and hardware components, PDFs remain firm and unchanged. They let you know for sure that the document you created will not undergo any strange changes when the recipient sees it. That's what PDF offers, and that's why it has been the standard for more than two decades.

Security Problem

  • A problem that we always encounter with any text format is copyright and security. An undeniable fact is that we want to, but we can not control but also prevent intentional corrections and unauthorized copying of our documents.
  • Whatever the purpose of these actions is, more or less, they will leave us with an undesirable consequence. Although the PDF format is designed to be ideal for high-security, these security options are useless in some cases. Sometimes the greatest strength of the PDF format makes it difficult, especially the convenience of converting to other formats accidentally makes it more vulnerable than ever.
  • Surely, after having considered the above, you will want a solution to protect your documents from unauthorized editing and copying. There are many possible alternatives; you might think of data encryption to optimize document security. However, it would be even better if we leave this topic for a more in-depth article. For now, let's come up with the most ideal yet effective solution that is undeniable - Password Protection.

About this demo

  • This example will demonstrate how to protect a PDF Document with passwords. You can open the output PDF with password 'owner' or 'user '. The purpose of this example is to prevent others from illegal copying, editing, and printing the information in your PDF documents with just a password.
  • Here, we offer many different security options, and they are:
  • KeySize
  • Permissions
  • User Password
  • To use the features mentioned in this article, first make sure that you have installed the PDF Office Component library.
  • For the first step, let's import the library we will use. We have fully installed these security methods in our OfficeComponent.Pdf.Security
  • C# Version: using OfficeComponent.Pdf.Security;
  • VB Version: Imports OfficeComponent.Pdf.Security
  • Next, create yourself a PDF document set with PdfDocument class
  • C# Version: PdfDocument doc = new PdfDocument();
  • VB Version: Dim doc As New PdfDocument()

Create some new pages to add to the newly created PDF document. You can also define some of your own Graphic conventions:

  • C# Version:
    PdfPage page = doc.Pages.Add();
    PdfGraphics graphics = page.Graphics;
  • VB Version:
    Dim page As PdfPage = doc.Pages.Add()
    Dim graphics As PdfGraphics = page.Graphics
  • Initialize security variable
  • C# Version: PdfDocumentSecurity security = doc.Security;
  • VB Version: Dim security As PdfDocumentSecurity = doc.Security

And for the final step in the security setup process, set some other properties for the document's security key.

  • C# Version:
    security.KeySize = PdfEncryptionKeySize.Key128Bit;
    security.OwnerPassword = "owner";
    security.Permissions = PdfDocumentPermissions.Print | PdfDocumentPermissions.FullQualityPrint;
    security.UserPassword = "user";
  • VB Version:
    security.KeySize = PdfEncryptionKeySize.Key128Bit
    security.OwnerPassword = "owner"
    security.Permissions = PdfDocumentPermissions.Print
    security.UserPassword = "user"

A complete example of PDF document security will be presented below with leveraging the PDF Office Component library.

  • C# Version:
    // Create a new instance of PdfDocument class.
    PdfDocument doc = new PdfDocument();

    PdfPage page = doc.Pages.Add();
    PdfGraphics graphics = page.Graphics;

    PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
    PdfBrush brush = PdfBrushes.Black;

    //Document security
    PdfDocumentSecurity security = doc.Security;

    //use 128 bits key
    security.KeySize = PdfEncryptionKeySize.Key128Bit;
    security.OwnerPassword = "owner";
    security.Permissions = PdfDocumentPermissions.Print | PdfDocumentPermissions.FullQualityPrint;
    security.UserPassword = "user";

    string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
        "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword);

    graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
    font = new PdfStandardFont(PdfFontFamily.Courier, 16f, PdfFontStyle.Bold);
    graphics.DrawString(text, font, brush, new PointF(0, 40));

    // Save and close the document.
    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 page As PdfPage = doc.Pages.Add()
    Dim graphics As PdfGraphics = page.Graphics

    Dim font As New PdfStandardFont(PdfFontFamily.TimesRoman, 20F, PdfFontStyle.Bold)
    Dim brush As PdfBrush = PdfBrushes.Black

    'Document security
    Dim security As PdfDocumentSecurity = doc.Security

    'use 128 bits key
    security.KeySize = PdfEncryptionKeySize.Key128Bit
    security.OwnerPassword = "owner"
    security.Permissions = PdfDocumentPermissions.Print Or PdfDocumentPermissions.FullQualityPrint
    security.UserPassword = "user"

    Dim text As String = "Security options:" & vbLf & vbLf & String.Format("KeySize: {0}" & vbLf & vbLf & "Owner Password: {1}" & vbLf & vbLf & "Permissions: {2}" & vbLf & vbLf & "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword)

    graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty)
    font = New PdfStandardFont(PdfFontFamily.Courier, 16F, PdfFontStyle.Bold)
    graphics.DrawString(text, font, brush, New PointF(0, 40))

    ' Save and close the document.
    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 PDF Document Security 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