Preparing your print...
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_front_file.pdf", "input_back_pdf": "your_input_back_file.pdf", "template_glue_pdf": "your_template_file.pdf", "params": "your_params" }
PUT request. Imposes a PDF file with fit.
{ "input_pdf": "your_input_file.pdf", "template_pdf": "your_template_file.pdf", "is_front": boolean, "params": "your_params" }
PUT request. Imposes a PDF file ona roll.
{ "unwind": "Not Important" | 1 | 2 | 3 | 4, "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", "params": {"canvas-width": [6.5, 8.5, 13],"h-align": ["left",0.125],"CutName": "Cut"} }
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.
{ "input_pdf_id": "google drive id" }
PUT request. Adds support for background cut.
{ "input_pdf_id": "google drive id", "texture_img_id": "google drive id of the texture jpg", "texture_color_code": "hex color code of the texture instead of texture image", "params": {"product": {"bleed": 0.25}, "background-color": "#FFFFFF"} # Change as per requirements }
PUT request. Adds support for spot UV effect.
{ "input_pdf_id": "google drive id", "params": { "uv-angle": 90, # 0 to 180 degrees (0 is horizontal) Controls the angle of the light source "uv-scale": 1, # 0 to 5 (0 is no effect) Controls the intensity of the effect (0 is no effect, 1 is maximum effect and 5 is a very soft effect) "uv-offset": 0, # 0 to 128 (0 is no effect) Controls the transparency of the effect (0 is fully transparent and 128 is fully opaque) "uv-soften": 5 # 0 to 10 (0 is no effect) Controls the softness of the effect (0 is no effect, 5 is medium softness and 10 is very soft) } }
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
The application provides the following endpoints:
/add-bleed
: Add a bleed to a PDF file./impose
: Impose a PDF file onto a template PDF file./impose-glue
: Impose a PDF file onto a template PDF file with back side./convert-html-to-pdf
: Convert an HTML string to a PDF file./white-spot-separate
: Add a white support spot to a PDF file./background-cut
: Apply clipping mask and background color to a PDF file.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-spot-separate
Method: PUT
Data Params:
input_pdf_id
: The google drive id of pdf file with whithe separation applied.Success Response:
spot.pdf
and process.pdf
.Example:
/white-spot-separate
endpoint:Python:
import requests
url = "http://127.0.0.1:5000/white-support-spot"
null = False
response = requests.put(url, data={
"input_pdf_id": "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ"
})
print(response.status_code)
with open("test_separation.zip", "wb") as f:
f.write(response.content)
cURL:
curl -X PUT -F "background_pdf=@path_to_background.pdf" -F "spot_pdf=@path_to_spot.pdf" http://localhost:5000white-spot-separate > output.pdf
PHP:
<?php
$url = "http://localhost:5000white-spot-separate";
$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);
?>
This endpoint is used to apply clipping mask and background color to a PDF file.
URL: background-cut
Method: PUT
Data Params:
input_pdf_id
: The google drive id of pdf file.texture_img_id
: The google drive id of texture image.texture_color_code
: The color code of texture image.params
: A JSON object containing the imposition parameters. The parameters are as follows:{"product": {"bleed": 0.25}, "background-color": "#FFFFFF"} # Change as per requirements
Success Response:
Example:
/background-cut
endpoint:Python:
import requests
import json
url = "http://localhost:5000/background-cut"
response = requests.put(url, data={
"input_pdf_id": "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ",
"texture_img_id": "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ",
"texture_color_code": "#FFFFFF",
"params": json.dumps({"product": {"bleed": 0.25}, "background-color": "#FFFFFF"})
})
print(response.status_code)
with open("test_separation.zip", "wb") as f:
f.write(response.content)
cURL:
curl -X PUT -F "input_pdf_id=1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ" -F "texture_img_id=1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ" -F "texture_color_code=#FFFFFF" -F "params={'product': {'bleed': 0.25}, 'background-color': '#FFFFFF'}" http://localhost:5000/background-cut > output.pdf
PHP:
<?php
$url = "http://localhost:5000/background-cut";
$input_pdf_id = "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ";
$texture_img_id = "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ";
$texture_color_code = "#FFFFFF";
$params = array("product" => array("bleed" => 0.25), "background-color" => "#FFFFFF");
$data = array("input_pdf_id" => $input_pdf_id, "texture_img_id" => $texture_img_id, "texture_color_code" => $texture_color_code, "params" => json_encode($params));
$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 apply spot UV to a PDF file.
URL: spot-uv-effect
Method: PUT
Data Params:
input_pdf_id
: The google drive id of pdf file.params
: A JSON object containing the imposition parameters. The parameters are as follows:{
"uv-angle": 0, # 0 to 180 degrees (0 is horizontal) Controls the angle of the light source
"uv-scale": 1, # 0 to 5 (0 is no effect) Controls the intensity of the effect (0 is no effect, 1 is maximum effect and 5 is a very soft effect)
"uv-offset": 0, # 0 to 128 (0 is no effect) Controls the transparency of the effect (0 is fully transparent and 128 is fully opaque)
"uv-soften": 5 # 0 to 10 (0 is no effect) Controls the softness of the effect (0 is no effect, 5 is medium softness and 10 is very soft)
}
Success Response:
Example:
/spot-uv-effect
endpoint:Python:
import requests
import json
url = "http://localhost:5000/spot-uv-effect"
response = requests.put(url, data={
"input_pdf_id": "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ",
"params": json.dumps({
"uv-angle": 0,
"uv-scale": 1,
"uv-offset": 0,
"uv-soften": 5
})
})
print(response.status_code)
with open("test_spot_uv.png", "wb") as f:
f.write(response.content)
cURL:
curl -X PUT -F "input_pdf_id=1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ" -F "params={'uv-angle': 0, 'uv-scale': 1, 'uv-offset': 0, 'uv-soften': 5}" http://localhost:5000/spot-uv-effect > output.png
PHP:
<?php
$url = "http://localhost:5000/spot-uv-effect";
$input_pdf_id = "1p2SsjXKwNjmj1wfXr5ka2y4aPZdqTwaJ";
$params = array(
"uv-angle" => 0,
"uv-scale" => 1,
"uv-offset" => 0,
"uv-soften" => 5
);
$data = array("input_pdf_id" => $input_pdf_id, "params" => json_encode($params));
$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);
?>