In this tutorial, we will show you how to extract Doc to Protected PDF in JavaScript using PDF.co Web API. Below is the image of the sample Doc and the Protected PDF output.

  1. JavaScript Sample Code
  2. PDF.co API Key
  3. Source URL, Result, and Password
  4. Setup PDF Security
  5. Run Program
  6. Protected PDF Demo
Sample Doc and Protected PDF Output
Sample Doc and Protected PDF Output

Step 1: JavaScript Sample Code

To begin, open your Visual Studio app and save the source code.

Step 2: PDF.co API Key

In line 21, add your API Key. You can get the PDF.co API Key in your dashboard here.

PDF.co API Key

Step 3: Source URL, Result, and Password

  • In line 26, enter your source file URL. If you don’t have one, you can use the built-in source URL in the sample code.
  • In line 28, type in your desired protected output file name.
  • In line 31, add your document password.

Source URL, Result, and Password

Step 4: Setup PDF Security

Now, let’s set up PDF Security.

  • For the EncryptionAlgorithm, enter your usable bit values.
  • In the AllowAccessibilitySupport, set to true to allow content extraction for accessibility.
  • For the AllowAssemblyDocument, set to true to allow assembling of the document.
  • In the AllowPrintDocument, set to true to allow printing documents.
  • For the AllowFillForms, set to true to allow filling to interactive form fields.
  • In the AllowModifyDocument, set to true to allow modification of PDF documents.
  • For the AllowContentExtaction, set to true to allow copying content from PDF documents.
  • In the AllowModifyAnnotations, set to true to allow interaction with text annotations.
  • For the PrintQuality, choose the HighResolution document printing quality.

Setup PDF Security

Step 5: Run Program

To run the program, type in node app.js in the terminal.

Protected PDF Demo

Here’s a quick demo to convert Doc to protected PDF.

Protected PDF Demo
Protected PDF Demo

In this tutorial, you learned how to convert Doc to protected PDF in Javascript. You learned how to use the /pdf/convert/from/doc endpoint to convert a Doc to PDF. You also learned how to add security details to a PDF document.