How to Convert PostScript to PDF with JavaScript in NodeJS
This NodeJS walkthrough uses JavaScript, Axios, and multipart form data. It converts a PostScript (.ps) file into PDF through the pdfRest Convert to PDF API Tool and includes a custom .joboptions profile. The complete sample is included below so JavaScript in NodeJS developers can see the file handling, request construction, and response path together.
Why PostScript to PDF with JavaScript in NodeJS?
Node-based publishing and web-to-print services often need to turn a PostScript artifact into a PDF that browsers and document portals can readily handle. The multipart form keeps that conversion close to the rest of the service’s HTTP work.
A browser-facing proof service might accept a .ps export from a legacy renderer, send an approved .joboptions profile with it, and return a PDF resource to the front end for controlled download. The profile can be selected per workflow rather than embedded in the service.
When no specialized settings are needed, the same endpoint can be called without the profile part. The input file and optional profile remain separate, which makes that choice visible in code review.
JavaScript in NodeJS Code Example for PostScript to PDF
var axios = require("axios");
var fs = require("fs");
var FormData = require("form-data");
// By default, we use the US-based API service. This is the primary endpoint for global use.
var apiUrl = "https://api.pdfrest.com";
/* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
* For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
*/
//var apiUrl = "https://eu-api.pdfrest.com";
/* This sample converts a PostScript (.ps) file to PDF with a custom .joboptions profile.
* A .joboptions file contains Adobe Distiller-compatible conversion settings. The
* profile is optional; omit job_options to use default settings. pdfRest applies a
* supplied profile with Datalogics PDF Converter SDK. Datalogics maintains the SDK
* in partnership with Adobe, using the same Adobe technology that powers Distiller.
* Pairing this /pdf call with /postscript creates a PDF -> PostScript -> PDF workflow
* commonly called PDF refrying. Some print and prepress workflows use it to rebuild or
* normalize page content, but the lossy roundtrip can discard PDF-specific features.
*/
var inputPath = "/path/to/sample.ps";
var jobOptionsPath = "/path/to/custom.joboptions";
var form = new FormData();
form.append("file", fs.createReadStream(inputPath), { contentType: "application/postscript" });
form.append("job_options", fs.createReadStream(jobOptionsPath), { contentType: "application/octet-stream" });
form.append("output", "pdf_from_postscript");
axios.post(apiUrl + "/pdf", form, { headers: { "Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", ...form.getHeaders() }, maxBodyLength: Infinity })
.then((response) => { console.log(JSON.stringify(response.data, null, 2)); })
.catch((error) => { console.error(error.response ? error.response.data : error.message); process.exitCode = 1; });
Source: View the sample on GitHub
Breaking Down the Code
Configure the service and input
// By default, we use the US-based API service. This is the primary endpoint for global use. var apiUrl = "https://api.pdfrest.com"; /* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. * For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work */ //var apiUrl = "https://eu-api.pdfrest.com";
For this PostScript to PDF example, JavaScript in NodeJS sends the multipart request to /pdf. The NodeJS samples use axios for HTTP, form-data for multipart encoding, and Node’s file-system module for local inputs. Install the packages listed in the repository’s JavaScript package manifest when adapting the example. The sample’s placeholder path and API key make the moving pieces visible; replace them with a real local path and protected runtime credential before using the request.
Apply the PostScript Conversion Profile
var jobOptionsPath = "/path/to/custom.joboptions";
var form = new FormData();
form.append("file", fs.createReadStream(inputPath), { contentType: "application/postscript" });
form.append("job_options", fs.createReadStream(jobOptionsPath), { contentType: "application/octet-stream" });
form.append("output", "pdf_from_postscript");
axios.post(apiUrl + "/pdf", form, { headers: { "Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", ...form.getHeaders() }, maxBodyLength: Infinity })
.then((response) => { console.log(JSON.stringify(response.data, null, 2)); })
.catch((error) => { console.error(error.response ? error.response.data : error.message); process.exitCode = 1; });
Here, JavaScript in NodeJS sends the PostScript source and the optional profile as separate files. A .joboptions file contains Adobe Distiller-compatible conversion settings; pdfRest applies a supplied profile with Datalogics PDF Converter SDK, maintained in partnership with Adobe and using the same Adobe technology that powers Distiller. Omitting job_options uses default settings.
Build the multipart request
var axios = require("axios");
var fs = require("fs");
var FormData = require("form-data");
// By default, we use the US-based API service. This is the primary endpoint for global use.
var apiUrl = "https://api.pdfrest.com";
/* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
* For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
*/
//var apiUrl = "https://eu-api.pdfrest.com";
For the PostScript to PDF form, FormData appends a readable file stream and the text options. Its generated headers include the multipart boundary, so the request combines form.getHeaders() with the Api-Key header rather than setting a boundary by hand.
Read the output resource
var axios = require("axios");
var fs = require("fs");
var FormData = require("form-data");
// By default, we use the US-based API service. This is the primary endpoint for global use.
var apiUrl = "https://api.pdfrest.com";
/* For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
* For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
After the PostScript to PDF call, axios resolves successful responses to a JSON object and sends API failures to the catch block. The sample prints either the output-resource details or the returned error payload, which is a useful starting point for production logging.
Beyond the Tutorial
You have now used JavaScript in NodeJS to turn a PostScript source into a managed PDF and make its conversion profile explicit. That gives the surrounding application a deliberate choice between a team-maintained .joboptions file and the service defaults.
Try representative postscript to pdf inputs in API Lab. For the authoritative request fields, accepted values, and response contract, consult the Convert to PDF API Tool documentation. The same request pattern can then be adapted to your JavaScript in NodeJS application’s error handling, retention policy, and delivery workflow.
A JSON-payload PostScript-to-PDF example is available for JavaScript in NodeJS as well. That form uploads the .ps and optional .joboptions files first, then passes their resource IDs to /pdf. View the JSON-payload sample on GitHub.