download (GET)
{server}/api/v1/printPdf/download/{jobToken}
Description
(requires v2.8 or later)
Use this request to download the output PDF document from a preceding /PrintPdf/print POST request, as identified by the job token returned as data.jobIdentifier.
When a call to /PrintPdf/print returns a status value of 2 (QueuedToFile) use /PrintPdf/status to poll ScriptX.Services. Subsequently when a call to /PrintPdf/status returns 6 (completed) use /PrintPdf/download to download the finished PDF.
See also the OpenAPI (Swagger) definition.
Applies to:
- ScriptX.Services for Cloud
- ScriptX.Services for On-Premise Devices (Authorisation header is ignored)*
- ScriptX.Services for Windows PC*
* Applies only when printing to a default or specified PDF printer driver
Request parameters
jobToken (string, required)
- jobToken (string, required)
- The job identifier for the job to be downloaded, as returned by a preceding POST to /PrintPdf/print.
Example usage
...
...
// previous code to submit print job omitted and assumed a monitor function
// on status has determined the job status is 6
//
// supplies job identifier as 8c72a9871ba64c4ba507b4392c1ce0b9
...
...
async function checkStatusAndDownload(jobToken) {
const headers = new Headers({
"Authorization": "Basic " + btoa("13598d2f-8724-467b-ae64-6e53e9e9f644" + ":")
});
try {
const response = await fetch("https://scriptxservices.meadroid.com/api/v1/printPdf/status/" + jobToken, {
method: "GET",
headers: headers
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
if (data.status === 6) {
await downloadFile(data.jobIdentifier);
}
} catch (error) {
console.error('There has been a problem with your fetch operation:', error);
// handle failure
}
}
async function downloadFile(jobIdentifier) {
const headers = new Headers({
"Authorization": "Basic " + btoa("13598d2f-8724-467b-ae64-6e53e9e9f644" + ":")
});
try {
const response = await fetch("https://scriptxservices.meadroid.com/api/v1/printPdf/download/" + jobIdentifier, {
method: "GET",
headers: headers
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
// Assuming the file is a PDF, adjust the MIME type as needed
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
// Provide a filename for the download
a.download = "downloadedFile.pdf";
document.body.appendChild(a); // Append the anchor to the body
a.click(); // Trigger the download - prompts the user to save it directly.
// Cleanup: remove the anchor from the body and revoke the Blob URL
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
} catch (error) {
console.error('There has been a problem with your fetch operation:', error);
// handle failure
}
}