How to Create a Blank PDF with cURL
Why Create Blank PDF with cURL?
The pdfRest Create Blank PDF API Tool is a convenient solution for developers looking to generate blank PDF documents programmatically. This tool allows users to specify the size, number of pages, and orientation of the PDF, making it highly customizable for various needs. In this tutorial, we will demonstrate how to send an API call to Create Blank PDF using cURL, a command-line tool for transferring data with URLs.
Imagine a scenario where a company needs to generate multiple blank PDF templates for internal documentation or client forms. By using the Create Blank PDF tool, they can automate this process, ensuring consistency and saving time. This is particularly useful for businesses that require a large volume of standardized documents, such as legal firms or educational institutions.
Create Blank PDF with cURL Code Example
# By default, we use the US-based API service. This is the primary endpoint for global use. API_URL="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 # API_URL="https://eu-api.pdfrest.com" curl -X POST "$API_URL/blank-pdf" \ -H "Accept: application/json" \ -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -F "page_size=letter" \ -F "page_count=3" \ -F "page_orientation=portrait"
Source: GitHub Repository
Breaking Down the Code
The provided script begins by defining the API_URL variable, which points to the US-based API service at https://api.pdfrest.com. This is the primary endpoint for global users. For European users requiring GDPR compliance, an alternative EU-based service URL is available, which can be uncommented if needed.
The curl command is used to send an HTTP POST request to the $API_URL/blank-pdf endpoint. The -X POST option specifies the request method.
The -H "Accept: application/json" header indicates that the client expects a JSON response from the server. The -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" header includes the API key, which is necessary for authenticating the request. Replace the placeholder with your actual API key.
The -F options are used to specify form data for the request:
page_size=letter: Sets the size of the PDF pages to "letter".page_count=3: Specifies that the PDF should contain three pages.page_orientation=portrait: Sets the orientation of the pages to "portrait".
Beyond the Tutorial
In this tutorial, we learned how to use cURL to make an API call to the pdfRest Create Blank PDF endpoint, allowing us to generate a customizable blank PDF document. This process can be easily integrated into larger workflows to automate document creation.
For more experimentation, you can try out all of the pdfRest API Tools in the API Lab. Additionally, the API Reference Guide provides comprehensive information on all available endpoints and parameters.
Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at GitHub Repository.