How to Refry a PDF with cURL
This cURL walkthrough uses the public pdfRest API directly from a shell script. It completes a PDF -> PostScript -> PDF roundtrip by passing a resource ID from /postscript into /pdf. The complete sample is included below so cURL developers can see the file handling, request construction, and response path together.
Why Refry a PDF with cURL?
PDF refrying converts a PDF to PostScript and then converts that PostScript into a new PDF. It can support print and prepress workflows that need a PostScript-based derivative or rebuilt page content for a downstream system.
The cURL example makes that roundtrip explicit in a portable script: the first request creates the PostScript resource, and the second uses its returned ID to create the final PDF. A prepress handoff can apply fixed production settings and a checked-in .joboptions profile without an operator manually opening or re-saving files.
The roundtrip is deliberately lossy. Keep the original PDF as the system-of-record file whenever its tags, forms, layers, annotations, or other PDF-specific features may be needed later.
cURL Code Example for PDF Refrying
#!/bin/sh # Refry a PDF by converting it to PostScript and back to PDF. # # PDF refrying is the common name for a PDF -> PostScript -> PDF roundtrip. # Some print, prepress, and legacy production workflows use it to rebuild or # normalize page content, flatten certain PDF constructs, or prepare a file # for downstream systems. The process is intentionally lossy and may remove # tags, forms, layers, annotations, transparency, metadata, and editability. # Use this workflow when a downstream system requires rebuilt page content or # a PostScript-based interchange file. # # The PostScript-to-PDF step uses a custom .joboptions profile in this sample. # A .joboptions file contains Adobe Distiller-compatible conversion settings; # it is optional, and default settings are used when omitted. pdfRest applies # the profile with Datalogics PDF Converter SDK. Datalogics maintains the SDK # in partnership with Adobe, using the same Adobe technology that powers # Distiller. # # Run: sh refry-pdf.sh[outputPdf] set -eu SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) API_URL="${PDFREST_URL:-https://api.pdfrest.com}" API_KEY="${PDFREST_API_KEY:-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" INPUT_PATH="${1:-/path/to/sample.pdf}" JOB_OPTIONS_PATH="${2:-/path/to/custom.joboptions}" OUTPUT_PATH="${3:-$SCRIPT_DIR/refried.pdf}" POSTSCRIPT_RESPONSE=$(curl --fail-with-body --silent --show-error --location "$API_URL/postscript" \ --header 'Accept: application/json' \ --header 'Content-Type: multipart/form-data' \ --header "Api-Key: $API_KEY" \ --form "file=@$INPUT_PATH;type=application/pdf" \ --form 'ps_level=3' \ --form 'page_range=all' \ --form 'binary_output=true' \ --form 'scale=1' \ --form 'rotate=false' \ --form 'shrink_to_fit=true' \ --form 'print_annotations=true' \ --form 'output=refry_intermediate') POSTSCRIPT_ID=$(printf '%s' "$POSTSCRIPT_RESPONSE" | jq -r '.outputId') FINAL_RESPONSE=$(curl --fail-with-body --silent --show-error --location "$API_URL/pdf" \ --header 'Accept: application/json' \ --header 'Content-Type: multipart/form-data' \ --header "Api-Key: $API_KEY" \ --form "id=$POSTSCRIPT_ID" \ --form "job_options=@$JOB_OPTIONS_PATH;type=application/octet-stream" \ --form 'output=refried') FINAL_ID=$(printf '%s' "$FINAL_RESPONSE" | jq -r '.outputId') curl --fail-with-body --silent --show-error --location \ "$API_URL/resource/$FINAL_ID?format=file" \ --header "Api-Key: $API_KEY" \ --output "$OUTPUT_PATH" printf '%s\n' "$FINAL_RESPONSE" | jq . echo "Created $OUTPUT_PATH"
Source: View the sample on GitHub
Breaking Down the Code
Configure the service and input
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
API_URL="${PDFREST_URL:-https://api.pdfrest.com}"
API_KEY="${PDFREST_API_KEY:-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
INPUT_PATH="${1:-/path/to/sample.pdf}"
JOB_OPTIONS_PATH="${2:-/path/to/custom.joboptions}"
OUTPUT_PATH="${3:-$SCRIPT_DIR/refried.pdf}"
For this PDF Refrying example, cURL coordinates the two dependent API calls. cURL needs no language package installation. The sample keeps the service URL, API key, input path, and output name together near the top of the shell script so those values can be replaced before the request is sent. 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.
Pass the Intermediate Resource to the Next Step
--form 'shrink_to_fit=true' \ --form 'print_annotations=true' \ --form 'output=refry_intermediate') POSTSCRIPT_ID=$(printf '%s' "$POSTSCRIPT_RESPONSE" | jq -r '.outputId') FINAL_RESPONSE=$(curl --fail-with-body --silent --show-error --location "$API_URL/pdf" \ --header 'Accept: application/json' \ --header 'Content-Type: multipart/form-data' \ --header "Api-Key: $API_KEY" \ --form "id=$POSTSCRIPT_ID" \ --form "job_options=@$JOB_OPTIONS_PATH;type=application/octet-stream" \
In the cURL workflow, outputId from /postscript becomes the id passed to /pdf. The second request also supplies a custom .joboptions file so the return conversion has an explicit Adobe Distiller-compatible profile, even though default settings are available when the profile is omitted.
Build the multipart request
--header 'Content-Type: multipart/form-data' \ --header "Api-Key: $API_KEY" \ --form "file=@$INPUT_PATH;type=application/pdf" \ --form 'ps_level=3' \ --form 'page_range=all' \ --form 'binary_output=true' \ --form 'scale=1' \ --form 'rotate=false' \ --form 'shrink_to_fit=true' \ --form 'print_annotations=true' \ --form 'output=refry_intermediate')
For the PDF Refrying form, each --form option creates one multipart field. cURL reads file fields from disk when their value begins with @, while ordinary quoted values become text fields.
Read the output resource
#!/bin/sh # Refry a PDF by converting it to PostScript and back to PDF. # # PDF refrying is the common name for a PDF -> PostScript -> PDF roundtrip. # Some print, prepress, and legacy production workflows use it to rebuild or # normalize page content, flatten certain PDF constructs, or prepare a file # for downstream systems. The process is intentionally lossy and may remove # tags, forms, layers, annotations, transparency, metadata, and editability.
After the PDF Refrying call, the command prints the JSON response. Read outputId to retain the generated resource for a later call or download it from the returned URL before the service retention period ends.
Beyond the Tutorial
You completed the two-stage refry process in cURL and saved the final PDF after both calls succeeded. The intermediate response ID is the important handoff between conversion stages, not merely a status value to print and discard.
Try representative pdf refrying inputs in API Lab. For the authoritative request fields, accepted values, and response contract, consult the pdfRest API Reference Guide. The same request pattern can then be adapted to your cURL application’s error handling, retention policy, and delivery workflow.