How to Apply TDM Reservations to PDF with cURL
Why Use TDM Reserve PDF with cURL?
The pdfRest TDM Reserve PDF API tool equips users with the ability to secure their PDF documents against unauthorized data extraction and AI scraping. This tutorial offers a step-by-step guide on how to send a request to the TDM Reserve PDF endpoint using cURL, a highly versatile command-line utility for transferring data. By executing this API call, you can rapidly inject standardized W3C TDMRep metadata into your files, formally asserting your right to opt out of automated text and data mining.
For instance, a system administrator managing a large public archive of legal records or historical documents may need to ensure these files aren't harvested by AI companies to train language models. By incorporating the TDM Reserve PDF API into a simple bash script via cURL, they can easily batch process thousands of documents. This embeds a strict "No-AI" policy URL directly into the metadata of the entire repository, legally safeguarding the content before it is synced to a public-facing web server.
TDM Reserve 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" # This request applies metadata declaring Text and Data Mining (TDM) rights. curl -X POST "$API_URL/tdm-reserved-pdf" \ -H "Accept: application/json" \ -H "Content-Type: multipart/form-data" \ -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -F "file=@/path/to/file" \ -F "output=example_tdm_reserved_pdf_out" \ -F "policy=https://example.com/tdm-policy" \
Source: GitHub
Breaking Down the Code
The code begins by setting the API_URL variable to the US-based API service endpoint:
API_URL="https://api.pdfrest.com"
This is the default endpoint for global use. If you are located in Europe and require GDPR compliance, you can switch to the EU-based service by uncommenting the alternative URL:
# API_URL="https://eu-api.pdfrest.com"
The cURL command is used to make a POST request to the /tdm-reserved-pdf endpoint:
curl -X POST "$API_URL/tdm-reserved-pdf"
The headers specify that the request accepts JSON responses and uses multipart/form-data for the content type:
-H "Accept: application/json" -H "Content-Type: multipart/form-data"
The Api-Key header is crucial for authentication. Replace xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx with your actual API key:
-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
The -F options specify the form data to be sent in the request. The file parameter uploads the PDF file from your local system:
-F "file=@/path/to/file"
The output parameter defines the name of the output file:
-F "output=example_tdm_reserved_pdf_out"
The policy parameter specifies the URL of the TDM policy:
-F "policy=https://example.com/tdm-policy"
Beyond the Tutorial
In this tutorial, you learned how to make an API call to the TDM Reserve PDF endpoint using cURL. This example demonstrated how to apply TDM rights metadata to a PDF document. To explore more functionalities, try out all the pdfRest API Tools in the API Lab. For further reading, refer to the API Reference Guide.
Note: This is an example of a multipart API call. Code samples using JSON payloads can be found here.