Find PDF Information Using PDF.co and Node.js
Use PDF.co’s PDF Information API to retrieve a document’s page count, metadata, encryption status, and security permissions.
Step 1: Prepare Your PDF and API Key
You’ll need:
- Node.js 22 or later.
- A PDF.co account and API key.
- An accessible download URL for your PDF.
For a local PDF, upload it to PDF.co’s file storage and copy its file link.
Step 2: Create the Code Sample
Save the following code as pdf-information.cjs. No additional packages are required.
const API_KEY = "YOUR_PDFCO_API_KEY";
const SOURCE_URL = "YOUR_PDF_FILE_URL";
const PDF_PASSWORD = "";
async function main() {
const response = await fetch("https://api.pdf.co/v1/pdf/info", {
method: "POST",
headers: {
"x-api-key": API_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify({
url: SOURCE_URL,
password: PDF_PASSWORD,
async: false
}),
signal: AbortSignal.timeout(60000)
});
const data = await response.json();
if (!response.ok || data.error) {
throw new Error(
data.message || `Request failed: HTTP ${response.status}`
);
}
if (!data.info) {
throw new Error("The response did not contain PDF information");
}
console.log(JSON.stringify(data.info, null, 2));
}
main().catch(error => {
console.error(error.message);
process.exitCode = 1;
});Replace YOUR_PDFCO_API_KEY and YOUR_PDF_FILE_URL with your values. If the PDF requires a password, enter it in PDF_PASSWORD; otherwise, leave it empty.
The script sends a POST request to /v1/pdf/info and prints the returned info object. See the PDF Information API documentation.
Step 3: Run the Program
Open a terminal in the script’s folder and run:
node pdf-information.cjs
The terminal displays the PDF information as formatted JSON.
Step 4: Review the Results
The response includes fields such as:
PageCount: Number of pages.Author,Title,Subject, andKeywords: Document metadata.CreatorandProducer: Software used to create the PDF.CreationDateandModificationDate: Stored document dates.Encrypted: Whether the PDF is encrypted.PermissionPrintingandPermissionContentExtraction: Document permission settings.
Metadata fields may be empty if they were not set when the PDF was created. The request reads the document’s information without modifying the source PDF.
Related Tutorials

