This page describes how to use the Pdfcrowd online API to join multiple PDF files or update PDF attributes
in Node.js.
The API is user-friendly and can be integrated into your application with just a few lines of code.
Here are Node.js examples for quickly getting started with the API.
See more examples.
varpdfcrowd=require("pdfcrowd");// create the API client instancevarclient=newpdfcrowd.PdfToPdfClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// configure the conversiontry{client.addPdfFile("/path/to/cover.pdf");client.addPdfFile("/path/to/proposal.pdf");client.addPdfFile("/path/to/price.pdf");client.addPdfFile("/path/to/contact.pdf");}catch(why){// report the errorconsole.error("Pdfcrowd Error: "+why);process.exit(1);}// run the conversion and write the result to a fileclient.convertToFile("offer.pdf",function(err,fileName){if(err)returnconsole.error("Pdfcrowd Error: "+err);console.log("Success: the file was created "+fileName);});
varpdfcrowd=require("pdfcrowd");varfs=require("fs");// create the API client instancevarclient=newpdfcrowd.PdfToPdfClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// configure the conversiontry{client.addPdfRawData(fs.readFileSync("/path/to/cover.pdf"));client.addPdfRawData(fs.readFileSync("/path/to/proposal.pdf"));client.addPdfRawData(fs.readFileSync("/path/to/price.pdf"));client.addPdfRawData(fs.readFileSync("/path/to/contact.pdf"));}catch(why){// report the errorconsole.error("Pdfcrowd Error: "+why);process.exit(1);}// run the conversion and write the result to a fileclient.convertToFile("offer.pdf",function(err,fileName){if(err)returnconsole.error("Pdfcrowd Error: "+err);console.log("Success: the file was created "+fileName);});
varpdfcrowd=require("pdfcrowd");// create the API client instancevarclient=newpdfcrowd.PdfToPdfClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// configure the conversiontry{client.addPdfFile("/path/to/proposal.pdf");client.setPageWatermark("/path/to/watermark.pdf");}catch(why){// report the errorconsole.error("Pdfcrowd Error: "+why);process.exit(1);}// run the conversion and write the result to a fileclient.convertToFile("company_offer.pdf",function(err,fileName){if(err)returnconsole.error("Pdfcrowd Error: "+err);console.log("Success: the file was created "+fileName);});
Authentication
The credentials to access the API are your Pdfcrowd username and the API key.
You can try out the API without registering using the following demo
credentials:
It is recommended that you implement error handling to catch errors
that the API may return, see the example code below. A list of status
codes and their description can be found
here.
try{// call the API }catch(why){// print the errorconsole.error("Pdfcrowd Error: "+why);// print the error codeconsole.error("Pdfcrowd Error Code: "+why.getCode());// print the error messageconsole.error("Pdfcrowd Error Message: "+why.getMessage());}