Ninja style API documentation
PUT request. Adds bleed to a PDF file.
{ "file": "your_file.pdf", "bleed_width": 0.5, }
PUT request. Imposes a PDF file.
{ "input_pdf": "your_input_file.pdf", "template_pdf": "your_template_file.pdf", "is_front": boolean, "params": "your_params" }
PUT request. Imposes a PDF file with glue.
{ "input_front_pdf": "your_input_file.pdf", "input_back_pdf": "your_back_file.pdf", "template_pdf": "your_template_file.pdf", "params": "your_params" }
PUT request. Imposes a PDF file with a laser cut.
{ "shape": "rectangular" | "square" | "circle" | "oval" | "custom", "round_corners": "1/16" | "1/8" | "1/4" | "1/2", "size": [width, height], "input_pdf": "your_input_file.pdf", "template_pdf": "your_template_file.pdf", }
PUT request. Converts HTML to a PDF file.
{ "html_url": "your_html_url", "html_string": "your_html_string", "html_file": "your_html_file", }
PUT request. Adds a white support spot to a PDF file.
{ "background": "your_background.pdf", "spot": "your_spot.pdf", }
This is the documentation for the PicasSoft API. Below you will find the endpoints and the required parameters for each endpoint.
This project is a Python-based PDF processing service. It listens for new PDF files in a specified directory, processes them, and saves the output to the local file system. The project uses several Python libraries such as asyncio
, os
, pathlib
, click
, dotenv
, fitz
, and PIL
.
Clone the repository:
git clone git@github.com:ivangoranov/PicasSoft.git
Install the dependencies:
pip install -r requirements.txt
sandbox.exe
and PicasSoft.exe
file to your local machine.sandbox.exe
file to create the sandbox folder structure..env
file points to the sandbox_root_dir folder.PicasSoft.exe
file within the directory where your .env
file is placed in order to start the service.Clone the repository:
git clone git@github.com:ivangoranov/PicasSoft.git
This project currently supports the following service types:
The bleed
service type adds a bleed to a PDF file. It takes a PDF file and a bleed width as input, and outputs a new PDF file with the bleed added. The bleed width is specified in inches.
The impose
service type imposes a PDF file onto a template. It takes an input PDF, a template PDF, and an output PDF file path as input, and outputs a new PDF file with the input PDF imposed onto the template.
Our application can also be run as a REST API, allowing other applications to interact with it over the network. Here are the steps to run our application as a REST API:
Ensure you have installed all the necessary dependencies listed in the requirements.txt
file. You can install them using pip:
pip install -r requirements.txt
Start the application with the following command:
python app.py
This will start the Flask server, and the application will start listening for HTTP requests on localhost
port 5000
.
The application provides the following endpoints:
/add-bleed
(PUT): Accepts a PDF file and a bleed width as part of the request data, adds bleed to the PDF, and returns the output PDF as part of the response.
/impose
(PUT): Accepts two PDF files (input and template) and some parameters as part of the request data, imposes the input PDF onto the template PDF, and returns the output PDF as part of the response.
/convert-html-to-pdf
(PUT): Accepts an HTML URL as part of the request data, converts the HTML to a PDF, and returns the output PDF as part of the response.
Here are examples of how to make requests to each of the endpoints in Python, cURL, and PHP:
This endpoint is used to add a bleed to a PDF file. The input PDF file is modified by adding a bleed of the specified width to each edge of the document. The output PDF file is returned as the response. The bleed width is specified in inches.
URL: /add-bleed
Method: PUT
Data Params:
file
: The PDF file to which the bleed will be added. This should be sent as a file in the request body.bleed_width
: The width of the bleed to add to the PDF file.Success Response:
Example:
/add-bleed
endpoint:Python:
import requests
url = 'http://localhost:5000/add-bleed'
file_path = '/path/to/your/file.pdf'
bleed_width = 0.25
files = {'file': open(file_path, 'rb')}
data = {'bleed_width': bleed_width}
response = requests.put(url, data=data, files=files)
pdf_data = response.content
with open('output.pdf', 'wb') as f:
f.write(pdf_data)
cURL:
curl -X PUT -F "file=@/path/to/your/file.pdf" -F "bleed_width=0.25" http://localhost:5000/add-bleed > output.pdf
PHP:
<?php
$url = "http://localhost:5000/add-bleed";
$file_path = "/path/to/your/file.pdf";
$bleed_width = 0.25;
$cfile = new CURLFile($file_path);
$data = array("file" => $cfile, "bleed_width" => $bleed_width);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>
This endpoint is used to impose a PDF file onto a template PDF file. The input PDF file is imposed onto the template PDF file according to the specified parameters. The output PDF file is returned as the response.
URL: /impose
Method: PUT
Data Params:
input_pdf
: The PDF file to impose onto the template PDF. This should be sent as a file in the request body.template_pdf
: The template PDF file onto which the input PDF will be imposed. This should also be sent as a file in the request body.params
: A JSON object containing the imposition parameters. The parameters are as follows:canvas
: The size of the canvas on which to impose the input PDF. This should be a tuple of the form (width, height)
.horizontal-repeat
: A list of horizontal repeat values. Each value represents the number of times to repeat the input PDF horizontally at the corresponding position on the canvas.vertical-repeat
: A list of vertical repeat values. Each value represents the number of times to repeat the input PDF vertically at the corresponding position on the canvas.h-align
: A list of horizontal alignment values. Each value is a tuple of the form ("left"|"center"|"right", offset)
, where offset
is the horizontal offset from the corresponding position on the canvas.v-align
: A list of vertical alignment values. Each value is a tuple of the form ("top"|"center"|"bottom", offset)
, where offset
is the vertical offset from the corresponding position on the canvas.mark-offset
: The amount of bleed to add to the input PDF before imposing it onto the template PDF.mark-length
: The length of the bleed to add to the input PDF before imposing it onto the template PDF.product
: A dictionary containing the product information. This is required and should contain at least {"width": <float>, "height": <float>, "bleed": <float>}
.masksize
: The size of the mask to apply to the imposed PDF. This should be a list of strings Example: ["width + bleed", "height + bleed"]
.Success Response:
Example:
/impose
endpoint:Python:
import requests
import json
url = "http://localhost:5000/impose"
input_pdf_path = "/path/to/your/input.pdf"
template_pdf_path = "/path/to/your/template.pdf"
output_pdf = "/path/to/output/file.pdf"
params = {
"canvas": (13, 19),
"horizontal-repeat": [0, 0],
"vertical-repeat": [0, 0, 0, 0.50, 0, 0, 0],
"h-align": ["center", 0],
"v-align": ["center", 0],
"mark-offset": 0.125,
"mark-length": 0.25,
"product": {"width": 8.5, "height": 11, "bleed": 0.125},
"masksize": ["width + bleed", "height + bleed"]
}
with open(input_pdf_path, 'rb') as f1, open(template_pdf_path, 'rb') as f2:
files = {'input_pdf': f1, 'template_pdf': f2}
data = {'params': json.dumps(params)}
response = requests.put(url, files=files, data=data)
print(response.status_code)
This is the same as Impose, but require an additional parameter `input_back_pdf' which is the back side of the input_pdf. And the back is imposed upside down.
URL: /impose-glue
Method: PUT
Data Params:
input_pdf
: The PDF file to impose onto the template PDF. This should be sent as a file in the request body.input_back_pdf
: The back side of the PDF file to impose onto the template PDF. This should be sent as a file in the request body.template_pdf
: The template PDF file onto which the input PDF will be imposed. This should also be sent as a file in the request body.params
: A JSON object containing the imposition parameters. The parameters are as follows:canvas
: The size of the canvas on which to impose the input PDF. This should be a tuple of the form (width, height)
.horizontal-repeat
: A list of horizontal repeat values. Each value represents the number of times to repeat the input PDF horizontally at the corresponding position on the canvas.vertical-repeat
: A list of vertical repeat values. Each value represents the number of times to repeat the input PDF vertically at the corresponding position on the canvas.h-align
: A list of horizontal alignment values. Each value is a tuple of the form ("left"|"center"|"right", offset)
, where offset
is the horizontal offset from the corresponding position on the canvas.v-align
: A list of vertical alignment values. Each value is a tuple of the form ("top"|"center"|"bottom", offset)
, where offset
is the vertical offset from the corresponding position on the canvas.mark-offset
: The amount of bleed to add to the input PDF before imposing it onto the template PDF.mark-length
: The length of the bleed to add to the input PDF before imposing it onto the template PDF.product
: A dictionary containing the product information. This is required and should contain at least {"width": <float>, "height": <float>, "bleed": <float>}
.masksize
: The size of the mask to apply to the imposed PDF. This should be a list of strings Example: ["width + bleed", "height + bleed"]
.Success Response:
Example:
/impose-glue
endpoint:Python:
import requests
import json
url = "http://localhost:5000/impose-glue"
input_pdf_path = "/path/to/your/input.pdf"
input_back_pdf_path = "/path/to/your/input_back.pdf"
template_pdf_path = "/path/to/your/template.pdf"
params = {
"canvas": (13, 19),
"horizontal-repeat": [0, 0],
"vertical-repeat": [0, 0, 0, 0.50, 0, 0, 0],
"h-align": ["center", 0],
"v-align": ["center", 0],
"mark-offset": 0.125,
"mark-length": 0.25,
"product": {"width": 8.5, "height": 11, "bleed": 0.125},
"masksize": ["width + bleed", "height + bleed"]
}
with open(input_pdf_path, 'rb') as f1, open(input_back_pdf_path, 'rb') as f2, open(template_pdf_path, 'rb') as f3:
files = {'input_pdf': f1, 'input_back_pdf': f2, 'template_pdf': f3}
data = {'params': json.dumps(params)}
response = requests.put(url, files=files, data=data)
print(response.status_code)
This endpoint is used to convert an HTML string to a PDF file.
URL: /convert-html-to-pdf
Method: PUT
Data Params:
html_string
: The HTML string to convert to a PDF.html_url
: The URL to convert webpage to PDF.html_file
: The .html file to convert to PDF.options
: Dict with wkhtmltopdf optionsSuccess Response:
Example:
/convert-html-to-pdf
endpoint:Python:
import requests
url = "http://localhost:5000/convert-html-to-pdf"
html_string = "<html><body><h1>Hello, World!</h1></body></html>"
options = {
'page-size': 'Letter', # Letter, A4, etc. (default 'Letter')
'margin-top': '0.0in',
'margin-right': '0.0in',
'margin-bottom': '0.0in',
'margin-left': '0.0in',
}
data = {'html_string': html_string, 'options':options}
response = requests.put(url, data=data)
# The PDF data is in the content attribute of the response
pdf_data = response.content
# Write the PDF data to a file
with open('output.pdf', 'wb') as f:
f.write(pdf_data)
cURL:
curl -X PUT -d "html_string=<html><body><h1>Hello, World!</h1></body></html>" -d "output_pdf=/path/to/output/file.pdf" http://localhost:5000/convert-html-to-pdf
PHP:
<?php
$url = "http://localhost:5000/convert-html-to-pdf";
$html_string = "<html><body><h1>Hello, World!</h1></body></html>";
$output_pdf = "/path/to/output/file.pdf";
$data = array("html_string" => $html_string, "output_pdf" => $output_pdf);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>
This endpoint is used to add a white support spot to a PDF file.
URL: /white-support-spot
Method: PUT
Data Params:
background_pdf
: The PDF file to which the white support spot will be added. This should be sent as a file in the request body.spot_pdf
: The PDF file that contains the white support spot. This should also be sent as a file in the request body.Success Response:
Example:
/white-support-spot
endpoint:Python:
import requests
url = "http://localhost:5000/white-support-spot"
background_pdf_path = "/path/to/your/background.pdf"
spot_pdf_path = "/path/to/your/spot.pdf"
with open(background_pdf_path, 'rb') as f1, open(spot_pdf_path, 'rb') as f2:
files = {'background_pdf': f1, 'spot_pdf': f2}
response = requests.put(url, files=files)
print(response.status_code)
cURL:
curl -X PUT -F "background_pdf=@path_to_background.pdf" -F "spot_pdf=@path_to_spot.pdf" http://localhost:5000/white-support-spot > output.pdf
PHP:
<?php
$url = "http://localhost:5000/white-support-spot";
$background_pdf_path = "/path/to/your/background.pdf";
$spot_pdf_path = "/path/to/your/spot.pdf";
$cfile1 = new CURLFile($background_pdf_path);
$cfile2 = new CURLFile($spot_pdf_path);
$data = array("background_pdf" => $cfile1, "spot_pdf" => $cfile2);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>