API Response to PDF

Fetch API output when allowed, or upload a response file, then export it as a readable PDF.

Back to all tools on ToolForge

More in PDF & Export

API URL:

Upload Response File

Browser fetch may fail because of CORS. In that case, upload a saved response file instead.

About API Response to PDF

This API Response to PDF tool converts fetched or saved API responses into a shareable, archived PDF document. It works with JSON, text, XML, CSV, and log files - any text-based response format that can be displayed as plain text.

How PDF Generation Works

  1. Input: API response is fetched via browser fetch() or uploaded as a file
  2. Parse: JSON is automatically pretty-printed with 2-space indentation
  3. Render: jsPDF library renders text onto A4 pages with proper margins
  4. Format: Title in 14pt bold Helvetica, content in 9pt Courier monospace
  5. Export: PDF is downloaded directly to your browser's download folder
PDF Structure:

Page 1:
┌─────────────────────────────────────┐
│ API Response                        │ ← 14pt bold header
├─────────────────────────────────────┤
│ {                                   │
│   "status": "ok",                   │ ← 9pt Courier
│   "message": "Ready for export",    │   (monospace font)
│   "items": [1, 2, 3]                │
│ }                                   │
│                                     │
│ (content continues, wraps, splits)  │
└─────────────────────────────────────┘

Margins: 36pt on all sides
Line height: 12pt
Auto page breaks when content exceeds page

CORS and API Fetching Limitations

Browser-based API fetching is limited by CORS (Cross-Origin Resource Sharing) policies:

Issue Explanation Solution
CORS Block Browser blocks cross-origin requests Upload saved response file
No CORS Header API doesn't send Access-Control-Allow-Origin Use curl/Postman, then upload
Preflight Failure Complex requests trigger OPTIONS preflight Simple GET requests work best
Authentication API requires tokens/cookies Export authenticated response, upload

Supported Response Formats

Format Content-Type Handling
JSON application/json Parsed, pretty-printed
Plain Text text/plain Displayed as-is
XML application/xml Displayed as text
CSV text/csv Displayed as text
Log Files text/plain, .log Displayed as text

Common Use Cases

PDF Export Tips

Why File Upload is More Reliable

Due to CORS restrictions, fetching APIs directly from the browser often fails. The file upload workflow is more reliable:

  1. Use curl, Postman, or Insomnia to fetch the API response
  2. Save the response as a .json or .txt file
  3. Upload the file using the "Upload Response File" button
  4. Download the generated PDF
# Example: Save API response with curl
curl https://api.example.com/data -o response.json

# Then upload response.json in this tool

How to Convert API Response to PDF

  1. Fetch or upload: Enter an API URL and click "Fetch Response", or upload a saved response file.
  2. Review content: The response appears in the text area - edit if needed.
  3. Download PDF: Click "Download PDF" to generate and save the PDF document.
  4. Use the PDF: Share, archive, or print the generated PDF as needed.

Tips

Frequently Asked Questions

Why can't I fetch API responses directly from the browser?
Most browsers block cross-origin API requests due to CORS (Cross-Origin Resource Sharing) policies. An API must explicitly allow requests from your domain via Access-Control-Allow-Origin headers. When CORS blocks a request, use the file upload feature instead - save the API response locally and upload it.
What response formats can be converted to PDF?
This tool supports JSON (automatically pretty-printed), plain text, XML, CSV, and log files. JSON responses are parsed and formatted with proper indentation for readability. Binary responses (images, blobs) are not supported.
How is the PDF formatted?
The PDF uses A4 page size with 36pt margins. The title 'API Response' appears at the top in 14pt bold Helvetica. Content is rendered in 9pt Courier (monospace) for code alignment. Long lines wrap to fit the page width. Pages split automatically.
What happens if my JSON is invalid?
Invalid JSON is still exported as plain text. The tool attempts to parse and pretty-print JSON, but if parsing fails, the raw text is used. This means malformed JSON still produces a PDF, just without formatting.
How do I work around CORS to fetch API responses?
Options: 1) Use a CORS proxy server, 2) Configure the API server to allow your origin, 3) Use browser extensions that disable CORS (development only), 4) Save the API response using curl/Postman and upload the file. File upload is the most reliable approach.
What are common use cases for API response PDFs?
Common uses: API documentation with example responses, compliance/audit records of API data, sharing response schemas with teams, archiving API state at a point in time, creating test fixtures, and generating reports from API data for non-technical stakeholders.