Introduction
: Pdf4me.Client
: Pdf4me.CoreClient
![]()
![]()
![]()
to run require curl
# .NET Framework 4.6.2
Install-Package Pdf4me.Client
# .NET Core
Install-Package Pdf4me.CoreClient
// Maven
<dependency>
<groupId>com.pdf4me</groupId>
<artifactId>pdf4me</artifactId>
<version>0.8.0</version>
</dependency>
// Apache Buildr
'com.pdf4me:pdf4me:jar:0.8.0'
// Apache Ivy
<dependency org="com.pdf4me" name="pdf4me" rev="0.8.0" />
// Groovy Grape
@Grapes(
@Grab(group='com.pdf4me', module='pdf4me', version='0.8.0')
)
// Gradle/Grails
compile 'com.pdf4me:pdf4me:0.8.0'
// Scala SBT
libraryDependencies += "com.pdf4me" % "pdf4me" % "0.8.0"
// Leiningen
[com.pdf4me/pdf4me "0.8.0"]
pip install pdf4me
## Getting Started
# Add this line to your application's Gemfile:
gem 'pdf4me'
# And then execute
bundle install
# OR If you don't use bundler
gem install pdf4me
## Build locally/for development
# To build the Ruby code into a gem:
gem build pdf4me.gemspec
# Then either install the gem locally:
gem install ./pdf4me-2.x.y.gem
# Or install from Git
You can also install from a git repository: https://github.com/pdf4me/pdf4me-clientapi-ruby.git, then add the following in the Gemfile:
gem 'pdf4me', :git => 'https://github.com/pdf4me/pdf4me-clientapi-ruby.git'
composer require pdf4me/pdf4me_api_client_php:"dev-master"
node install pdf4me
Pdf4me is an easy-to-use library which allows you to manipulate PDF sheets in diverse ways. Whether you only want to merge two PDF documents or wish to alter a document in a more complex way, e.g., add a stamp of your creation to some selected pages, Pdf4me is the tool for you. Pdf4me provides you the possibility to use simple, mostly predefined methods for fast and simple modifications as well as the chance to customize certain operations more thoroughly.
Features
<Extract>: is just a placeholder and can be replaced with any other Universal Function.
Extract builds a new PDF consisting of a page selection from an existing PDF.
// create extract object
var extract = new <Extract>()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("mypdf.pdf"),
Name = "mypdf.pdf",
},
// action
<ExtractAction> = new <ExtractAction>()
{
// list of pages to be extracted
ExtractPages = new System.Collections.ObjectModel.ObservableCollection<int>() { 1,4 },
}
};
// extract
var res = await Pdf4me.Instance.<ExtractClient>.<extract>(extract);
// new PDF
byte[] extractedPdf = res.Document.DocData;
// setup the extractClient
<ExtractClient> extractClient = new <ExtractClient>(pdf4meClient);
// create extract object
<Extract> extract = new <Extract>();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
extract.setDocument(document);
// action
<ExtractAction> extractAction = new <ExtractAction>();
extractAction.setExtractPages(Arrays.asList(1, 4));
extract.setExtractAction(extractAction);
// extraction
<ExtractRes> res = <extractClient>.<extract>(extract);
// extracting the generated PDF and writing it to disk
byte[] extractedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("extractedPdf.pdf"), extractedPdf);
# setup the extract_client
extract_client = <ExtractClient>(pdf4me_client)
# create the extract object
extract = <Extract>(
# document
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
# action
extract_action=<ExtractAction>(
extract_pages=[1,4]
)
)
# extraction
res = extract_client.<extract>(extract=extract)
# extracting the generated PDF
extracted_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('extracted_pdf.pdf', 'wb') as f:
f.write(extracted_pdf)
# create the OptimizeAtion model and call Optimize
file = '/path/to/file/4.pdf'
Pdf4me::Optimize.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(fi, 'rb', &:read))
),
optimize_action: Pdf4me::OptimizeAction.new(
use_profile: true,
profile: 'max'
)
)
<?php
// post pdfExtract
$createExtract = $client->pdf4me()-><extract>([
// document
"document" => [
"docData" => $client->getFileData('myPdf.pdf')
],
// action
<"extractAction"> => [
"extractPages" => [
1,
4
]
]
]);
// extracting the generated PDF
$extractedPdf = base64_decode($createExtract->document->docData);
// and writing it to file
file_put_contents('extractedPdf.pdf', $extractedPdf);
// setup the extractClient
let extractClient = new pdf4me.<ExtractClient>(pdf4meClient);
// create the Extract object
let <Extract> = {
// document
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64'),
},
// action
<extractAction>: {
extractPages: [1, 4]
},
};
// extraction
let responsePromise = <extractClient>.<extract>(Extract);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./extractedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
The Pdf4meClient offers numerous forms of PDF manipulations. Their functionality categorizes the provided methods. Below you find an overview of the different clients we provide.
Feature / Action | Intent | Universal Functions | Wrapper Functions |
---|---|---|---|
Convert ConvertAction | Converts a Non-PDF file, for example, a word document, to a PDF. | convertToPdf | convertFileToPdf |
Extract ExtractAction | Creates a new PDF enclosing extracted pages of an existing PDF. | extract | extractPages |
Image ImageAction | Creates a snapshot of a specific PDF page and saves it as a picture. This thumbnail can, for instance, be used as a preview on the web. | createImages | createThumbnail |
Merge MergeAction | Unites two or possibly multiple PDFs by concatenating them. | merge | merge2Pdfs |
Optimize OptimizeAction | Optimizes a given PDF w.r.t a particular profile. E.g., for printing by applying correct fonts, the right color scheme, and a suitable resolution. | optimize | optimizeByProfile |
PdfA PdfAAction | Converts PDF documents to the PDF/A format for long-term archiving. | pdfA | createPdfA |
Split SplitAction | Splits a PDF of multiple pages into a number of smaller PDF documents. | split | splitByPageNr |
Stamp StampAction | Creates textual or image stamps on PDF documents. | stamp | textStamp |
The provided functions are split into two different categories:
Universal Functions: These functions take a single object as an argument. We forward the object to our Web API. Though each universal function has its unique object, these objects share the same structure. A universal object consists of two parts:
- document(s): Embeds the document(s), which should be manipulated.
- action: Behavior definition of the client. The action's property variety and depth is client dependent.
Wrapper Functions: We present a variety of different wrapper functions for each client. Their purpose is to enable you to do simple customization easily. Each of them is a simplified and restricted version of the corresponding universal function.
Compared to the universal functions, the wrapper functions are more straightforward to use, and you need less time to familiarize yourself with them. However, if you are looking for a highly personalized PDF modification, the universal function is the way to go, as it allows you to define your operation more throughly.
Authorization
using Pdf4me.Client;
// You can provide a generated token to initialise authorization.
Pdf4meClient.Pdf4me.Instance.Init(token);
//By default, the client will connect to the url 'https://api-dev.pdf4me.com'.
//You can provide a different api url like this
Pdf4meClient.Pdf4me.Instance.Init(token, api);
// The above setting need to be done only once.
// Rest of the client will be authenticated when accessing
// them through 'Pdf4me.Instance' object as shown below
byte[] file1 = File.ReadAllBytes("myFirstPdf.pdf");
byte[] file2 = File.ReadAllBytes("mySecondPdf.pdf");
MergeRes mergeRes = Pdf4me.Instance.MergeClient.Merge2Pdfs(file1, file2);
byte[] mergedPdf = mergeRes.Document.DocData;
/*
Either you store them in the config.properties file with keys clientId and secret
Do not use any quotes:
Correct: clientId=sample-not-working-key-aaaaaaa
Incorrect: clientId="sample-not-working-key-aaaaaaa"
*/
import com.pdf4me.client.Pdf4meClient;
import com.pdf4me.client.MergeClient;
Pdf4meClient pdf4meClient = new Pdf4meClient();
/*
In case the location of your config.properties differs from the default
location, the source folder, provide the optional argument pathToConfigFile.
*/
Pdf4meClient pdf4meClient = new Pdf4meClient("resources/config.properties");
// or you pass them as arguments when constructing the Pdf4meClient object
Pdf4meClient pdf4meClient = new Pdf4meClient(clientId, secret);
/*
The pdf4meClient object delivers the necessary authentication when instantiating
the different pdf4meClients such as for instance Merge.
*/
MergeClient mergeClient = new MergeClient(pdf4meClient);
byte[] mergedPdf = mergeClient.merge2Pdfs(new File("myFirstPdf.pdf"), new File("mySecondPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("mergedPdf.pdf"), mergedPdf);
'''
Either you store them in the config.properties file with keys client_id and secret
Do not use any quotes:
Correct: client_id=sample-not-working-key-aaaaaaa
Incorrect: client_id="sample-not-working-key-aaaaaaa"
Be aware that the secret string might need to be escaped when providing it as an argument to the Pdf4meClient constructor.
In case the location of your config.properties differs from the default location ('../config.properties'), provide the optional argument path_to_config_file.
'''
from pdf4me.client.pdf4me_client import Pdf4meClient
from pdf4me.client.merge_client import MergeClient
from pdf4me.helper.file_reader import FileReader
pdf4me_client = Pdf4meClient(path_to_config_file='path_to_my_config_file/config.properties')
''' or you pass them as arguments when constructing the Pdf4meClient object '''
pdf4me_client = Pdf4meClient(client_id=client_id, secret=secret)
# The pdf4meClient object delivers the necessary authentication when instantiating the different pdf4meClients such as for instance Merge
merge_client = MergeClient(pdf4me_client)
merged_pdf = merge_client.merge_2_pdfs(
file1=FileReader().get_file_handler(path='my_first_pdf.pdf'),
file2=FileReader().get_file_handler(path='my_second_pdf.pdf')
)
# Pdf4me works with any Rack application or plain old ruby script. In any regular script the configuration of Pdf4me looks like
# - Require pdf4me
# - Configure pdf4me with API endpoints and credentials
# - Call appropriate methods
# - Require pdf4me
require 'pdf4me'
# - Configure pdf4me with API endpoints and credentials
Pdf4me.configure do |config|
# config.debugging = true
config.token = 'your-app-token'
end
# - Call appropriate methods, for instance merge 2 documents.
a = Pdf4me::MergeTwoPdfs.new(
file1: '/path/to/file/1.pdf',
file2: '/path/to/file/2.pdf',
save_path: 'merged.pdf'
)
a.run # safe returns true|false
<?php
use Pdf4me\API\HttpClient as pdf4meAPI;
// You can provide a generated token to initialise authorization.
$token = "a1b2c3***y25z26";
$client = new pdf4meAPI($token);
//By default, the client will connect to the url 'https://api-dev.pdf4me.com'.
//You can provide a different api url like this
$client = new pdf4meAPI($token,$api);
//uploading file and setting request
$mergedPdf = $client->pdf4me()->merge2Pdfs([
"file1" => 'pdf2.pdf',
"file2" => 'pdf2.pdf'
]);
//writing it to file
file_put_contents('mergedPdf.pdf', $mergedPdf);
/*
The authentication setup happens through the Pdf4meClient.
*/
const fs = require('fs');
const pdf4me = require('pdf4me');
let pdf4meClient = new pdf4me.Pdf4meClient(token);
// The pdf4meClient object delivers the necessary authentication when instantiating the different pdf4meClients such as for instance the mergeClient
let mergeClient = new pdf4me.MergeClient(pdf4meClient);
let responsePromise = mergeClient.merge2Pdfs(fs.createReadStream('./myFirstPdf.pdf'), fs.createReadStream('./mySecondPdf.pdf'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./mergedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
To use pdf4me, you need to authenticate with basic basic authentication. You can get a free trial Api Token from our website. When using the Pdf4meApi directly you can set the basic authentication in the Header as following:
- Authentication: basic YOUR-FREE-TOKEN
Please login with your social account or create an account here. Once logged in you have access to your free credentials. Authorization happens through the Pdf4meClient. The credential hand-over is language dependent. Please have a look at the code examples on the right.
Convert
Offers conversion of common work documents to PDF. The following Non-PDF files are supported:
- MS Word, Excel, PowerPoint, Visio
- Open Office, Libre Office
- Email (MSG, EML, MIME)
- Plain Text (ASCII, UNICODE), WordPerfect
- Image Formats: BMP, GIF, JPEG, PNG, TIFF, JB2, JP2, JPX, PBM
- Nestet Containers: ZIP, TAR, RAR
- Websites: URL
- HTML
- Custom specific extensions: e.g. CAD
convertToPdf
// setup convertToPdf object
var convertToPdf = new ConvertToPdf()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myWordDoc.docx"),
Name = "myWordDoc.docx",
},
// action
ConvertToPdfAction = new ConvertToPdfAction()
};
// conversion
var res = await Pdf4meClient.Pdf4me.Instance.ConvertClient.ConvertToPdfAsync(convertToPdf);
// extract the generated PDF and write it to disk
byte[] generatedPdf = res.Document.DocData;
File.WriteAllBytes("generatedPdf.pdf", generatedPdf);
// setup the convertClient
ConvertClient convertClient = new ConvertClient(pdf4meClient);
// setup convertToPdf object
ConvertToPdf convertToPdf = new ConvertToPdf();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myWordDoc.docx")));
document.setName("myWordDoc.docx");
convertToPdf.setDocument(document);
// action
convertToPdf.setConvertToPdfAction(new ConvertToPdfAction());
// conversion
ConvertToPdfRes res = convertClient.convertToPdf(convertToPdf);
// extracting the generated PDF and writing it to disk
byte[] generatedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("generatedPdf.pdf"), generatedPdf);
# setup the convert_client
convert_client = ConvertClient(pdf4me_client)
# create the convert_to_pdf object
convert_to_pdf = ConvertToPdf(
document=Document(
doc_data=FileReader().get_file_data('my_word_doc.docx'),
name='my_word_doc.docx'
),
convert_to_pdf_action=ConvertToPdfAction()
)
# conversion
res = convert_client.convert_to_pdf(convert_to_pdf=convert_to_pdf)
# extracting the generated PDF
generated_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('generated_pdf.pdf', 'wb') as f:
f.write(generated_pdf)
file = '/path/to/file/TestDocToConvert.docx'
a = Pdf4me::ConvertToPdf.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file, 'rb', &:read)),
name: "TestDocToConvert.docx"
),
convert_to_pdf_action: Pdf4me::ConvertToPdfAction.new
)
response = a.run
File.open('converted.pdf', 'wb') do |f|
f.write(Base64.decode64(response.document.doc_data))
end
<?php
// post CreateToPdf
$createToPdf = $client->pdf4me()->convertToPdf([
"document" => [
"name" => "picture.jpg",
"docData" => $client->getFileData('picture.jpg')
]
]);
// extracting the generated PDF
$generatedPdf = base64_decode($createToPdf->document->docData);
// and writing it to file
file_put_contents('generatedPdf.pdf', $generatedPdf);
// setup the convertClient
let convertClient = new pdf4me.ConvertClient(pdf4meClient);
// create the ConvertToPdf object
let ConvertToPdf = {
document: {
docData: fs.readFileSync('./myWordDoc.docx').toString('base64'),
name: 'myWordDoc.docx'
},
convertToPdfAction: {},
};
// conversion
let responsePromise = convertClient.convertToPdf(ConvertToPdf);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./generatedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
convertToPdf ConvertToPdf |
Conversion configuration. |
Response:
Type: ConvertToPdfRes
Description: Contains generated PDF.
convertFileToPdf
curl https://api.pdf4me.com/Convert/ConvertFileToPdf ^
-H "Authorization: Basic DEV-KEY" ^
-F "file=@./Docx_to_Convert.docx" ^
-o ./Converted_to.pdf
// conversion and writing the generated PDF to disk
byte[] generatedPdf = await Pdf4meClient.Pdf4me.Instance.ConvertClient.ConvertFileToPdfAsync("myWordDoc.docx", File.ReadAllBytes("myWordDoc.docx"));
// and writing the generated PDF to disk
File.WriteAllBytes("generatedPdf.pdf", generatedPdf);
// setup the convertClient
ConvertClient convertClient = new ConvertClient(pdf4meClient);
// conversion and writing the generated PDF to disk
byte[] generatedPdf = convertClient.convertFileToPdf("myWordDoc.docx", new File("myWordDoc.docx"));
FileUtils.writeByteArrayToFile(new File("generatedPdf.pdf"), generatedPdf);
# setup the convert_client
convert_client = ConvertClient(pdf4me_client)
# conversion
generated_pdf = convert_client.convert_file_to_pdf(
file_name='my_word_doc.docx',
file=FileReader().get_file_handler('my_word_doc.docx')
)
# writing the generated PDF to disk
with open('generated_pdf.pdf', 'wb') as f:
f.write(generated_pdf)
b = Pdf4me::ConvertFileToPdf.new(
file: '/path/to/file/3.pdf',
save_path: 'converted.pdf'
)
b.run # returns true|false
<?php
//uploading file stream and converting pdf
$convertFileToPdf = $client->pdf4me()->convertFileToPdf(
[
"fName" => "picture.jpg"
"file" => __DIR__.'/picture.jpg'
]
);
//writing it to file
file_put_contents('generatedPdf.pdf', convertFileToPdf);
// setup the convertClient
let convertClient = new pdf4me.ConvertClient(pdf4meClient);
// conversion
let responsePromise = convertClient.convertFileToPdf('myWordDoc.docx', fs.createReadStream('./myWordDoc.docx'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./generatedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Uses the provided Non-PDF file to generate a PDF.
Parameters
Name | Description |
---|---|
fileName string |
Name of the provided file (incl. file extension). |
file application/octet-stream |
Data file to be converted to a PDF. |
Response:
Type: application/octet-stream
Description: Generated PDF.
Extract
Forms a new PDF consisting of the pages, which have been extracted from an existing PDF document.
extract
// create extract object
Extract extract = new Extract()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
ExtractAction = new ExtractAction()
{
// list of pages to be extracted
ExtractPages = new System.Collections.ObjectModel.ObservableCollection<int>() { 1, 4 },
}
};
// extraction
ExtractRes res = await Pdf4meClient.Pdf4me.Instance.ExtractClient.ExtractAsync(extract);
// extraction and writing the generated PDF to disk
byte[] extractedPdf = res.Document.DocData;
File.WriteAllBytes("extractedPdf.pdf", extractedPdf);
// setup the extractClient
ExtractClient extractClient = new ExtractClient(pdf4meClient);
// create extract object
Extract extract = new Extract();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
extract.setDocument(document);
// action
ExtractAction extractAction = new ExtractAction();
extractAction.setExtractPages(Arrays.asList(1, 4));
extract.setExtractAction(extractAction);
// extraction
ExtractRes res = extractClient.extract(extract);
// extracting the generated PDF and writing it to disk
byte[] extractedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("extractedPdf.pdf"), extractedPdf);
# setup the extract_client
extract_client = ExtractClient(pdf4me_client)
# create the extract object
extract = Extract(
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
extract_action=ExtractAction(
extract_pages=[1,4]
)
)
# extraction
res = extract_client.extract(extract=extract)
# extracting the generated PDF
extracted_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('extracted_pdf.pdf', 'wb') as f:
f.write(extracted_pdf)
file_path = './in/GraphicsTest.pdf'
action = Pdf4me::Extract.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path, 'rb', &:read))
),
extract_action: Pdf4me::ExtractAction.new(
extract_pages: [1, 2, 5]
),
#notification: Pdf4me::Notification.new(get_notification: true) # async
)
response = action.run
# saving extracted pages
File.open('out/Extract.pdf', 'wb') do |f|
f.write(Base64.decode64(response.document.doc_data))
end
<?php
// post pdfExtract
$createExtract = $client->pdf4me()->extract([
"document" => [
"docData" => $client->getFileData('myPdf.pdf')
],
"extractAction" => [
"extractPages" => [
1,
4
]
]
]);
// extracting the generated PDF
$extractedPdf = base64_decode($createExtract->document->docData);
// and writing it to file
file_put_contents('extractedPdf.pdf', $extractedPdf);
// setup the extractClient
let extractClient = new pdf4me.ExtractClient(pdf4meClient);
// create the Extract object
let Extract = {
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64'),
},
extractAction: {
extractPages: [1, 4]
},
};
// extraction
let responsePromise = extractClient.extract(Extract);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./extractedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
extract Extract |
Extraction configuration. |
ExtractAction
Name | Description |
---|---|
extractPages [ integer ] |
List of the pages which will be extracted. Page number 1 corresponds to the first page. |
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
Response:
Type: ExtractRes
Description: Contains extracted pages in form of a PDF.
extractPages
curl https://api.pdf4me.com/Extract/ExtractPages ^
-H "Authorization: Basic DEV-KEY" ^
-F pageNrs=1,4 ^
-F "file=@./PDF_to_Extract.pdf" ^
-o ./Extracted.pdf
// extraction
byte[] extractedPdf = await Pdf4meClient.Pdf4me.Instance.ExtractClient.ExtractPagesAsync("1,4", File.ReadAllBytes("myPdf.pdf"));
// and writing the generated PDF to disk
File.WriteAllBytes("extractedPdf.pdf", extractedPdf);
// setup the extractClient
ExtractClient extractClient = new ExtractClient(pdf4meClient);
// extraction and writing the generated PDF to disk
byte[] extractedPdf = extractClient.extractPages("1,4", new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("extractedPdf.pdf"), extractedPdf);
# setup the extract_client
extract_client = ExtractClient(pdf4me_client)
# extraction
extracted_pdf = extract_client.extract_pages(
page_nrs='1,4',
file=FileReader().get_file_handler(path="my_pdf.pdf")
)
# writing the generated PDF to disk
with open('extracted_pdf.pdf', 'wb') as f:
f.write(extracted_pdf)
a = Pdf4me::ExtractPages.new(
file: '/path/to/file/1.pdf',
pages: [4],
save_path: 'extracted.pdf'
)
a.run
<?php
//uploading file and setting request
$extractPages = $client->pdf4me()->extractPages(
[
"pageNrs" => "1,4"
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('extractedPdf.pdf', $extractPages);
// setup the extractClient
let extractClient = new pdf4me.ExtractClient(pdf4meClient);
// extraction
let responsePromise = extractClient.extractPages('1,4', fs.createReadStream('./myPdf.pdf'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./extractedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Performs the extraction of the specified pages and returns the newly created PDF.
Parameters
Name | Description |
---|---|
pageNrs string |
The page numbers which should be extracted from the PDF. They are stored in a string as comma-separated values. The page numbers use one-based indexing, i.e. page number 1 corresponds to the first page. |
file application/octet-stream |
Pdf from which the pages should be extracted. |
Response:
Type: application/octet-stream
Description: The newly created PDF consisting of the extracted pages.
Image
Creates a snapshot of a specific PDF page and saves it as a picture. This thumbnail can for instance be used as a preview on the web.
createImages
// create createImages object
var createImages = new CreateImages()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
ImageAction = new ImageAction()
{
ImageExtension = ImageActionImageExtension.Jpeg,
WidthPixel = 4000,
PageSelection = new PageSelection()
{
PageNrs = new System.Collections.ObjectModel.ObservableCollection<int>() { 1 }
}
},
};
// create image
var res = await Pdf4meClient.Pdf4me.Instance.ImageClient.CreateImagesAsync(createImages);
// extract thumbnail and writing it to disk
byte[] thumbnail = res.Document.Pages[0].Thumbnail;
File.WriteAllBytes("thumbnail.jpg", thumbnail);
// setup the imageClient
ImageClient imageClient = new ImageClient(pdf4meClient);
// create createImages object
CreateImages createImages = new CreateImages();
// document
Document document = new Document();
byte[] file = Files.readAllBytes(Paths.get("myPdf.pdf"));
document.setDocData(file);
createImages.setDocument(document);
// action
ImageAction imageAction = new ImageAction();
imageAction.setWidthPixel(4000);
imageAction.setPageSelection(new PageSelection().addPageNrsItem(1));
imageAction.setImageExtension(ImageExtensionEnum.JPEG);
createImages.setImageAction(imageAction);
// create image
CreateImagesRes res = imageClient.createImages(createImages);
// extracting the generated picture and writing it to disk
byte[] thumbnail = res.getDocument().getPages().get(0).getThumbnail();
FileUtils.writeByteArrayToFile(new File("thumbnail.jpg"), thumbnail);
# setup the image_client
image_client = ImageClient(pdf4me_client)
# create the create_images object
create_images = CreateImages(
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
image_action=ImageAction(
width_pixel=4000,
page_selection=PageSelection(
page_nrs=[1]
),
image_extension='jpg'
)
)
# image creation
res = image_client.create_images(create_images=create_images)
# extracting the generated image
image = base64.b64decode(res['document']['pages'][0]['thumbnail'])
# writing it to disk
with open('image.jpg', 'wb') as f:
f.write(image)
file_path = './in/GraphicsTest.pdf'
action = Pdf4me::CreateImages.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path, 'rb', &:read))
),
image_action: Pdf4me::ImageAction.new(
page_selection: Pdf4me::PageSelection.new(
page_nrs: [1]
),
image_extension: 'png',
center: true,
fit_page: true,
bits_per_pixel: 24,
bilevel_threshold: 181,
render_options: %w(noAntialiasing),
rotate_mode: 'none',
preserve_aspect_ratio: true,
compression: 'raw'
)
)
response = action.run
# saving the extracted thumbnail
File.open('./out/CreateImages_tn4.png', 'wb') do |f|
f.write(Base64.decode64(response.document.pages.first.thumbnail))
end
<?php
// post createImages
$createImages = $client->pdf4me()->createImages([
"document" => [
'docData' => $client->getFileData('myPdf.pdf')
],
"imageAction" => [
"widthPixel" => 4000,
"pageSelection" => [
"pageNrs" => [
1
]
],
"imageExtension" => "jpg"
]
]);
// extracting the generated image
$image = base64_decode($createImages->document->pages[0]->thumbnail);
// and writing it to file
file_put_contents('image.jpg', $image);
// setup the imageClient
let imageClient = new pdf4me.ImageClient(pdf4meClient);
// create the CreateImages object
let CreateImages = {
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64'),
},
imageAction: {
widthPixel: 4000,
pageSelection: {
pageNrs: [1]
},
imageExtension: 'jpg'
}
};
// image creation
let responsePromise = imageClient.createImages(CreateImages);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['pages'][0]['thumbnail'], 'base64');
fs.writeFileSync('./image.jpg', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
createImages CreateImages |
Image Creation configuration. |
Response:
Type: CreateImagesRes
Description: Contains images.
createThumbnail
curl https://api.pdf4me.com/Image/CreateThumbnail ^
-H "Authorization: Basic DEV-KEY" ^
-F pageNr=4 ^
-F width=500 ^
-F imageFormat=jpeg ^
-F "file=@./PDF_for_Thumbnail.pdf" ^
-o ./Thumbnail_Generated.jpeg
// thumbnail creation
byte[] thumbnail = await ImageClient.CreateThumbnailAsync(
4000,
"1",
ImageActionImageExtension.Jpg,
File.ReadAllBytes("myPdf.pdf"));
// and writing the generated picture to disk
File.WriteAllBytes("thumbnail.jpg", thumbnail);
// setup the imageClient
ImageClient imageClient = new ImageClient(pdf4meClient);
// thumbnail creation and writing the generated picture to disk
byte[] thumbnail = imageClient.createThumbnail(4000, "1", ImageExtensionEnum.JPEG, new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("thumbnail.jpg"), thumbnail);
# setup the image_client
image_client = ImageClient(pdf4me_client)
# image creation
image = image_client.create_thumbnail(
width=4000,
page_nr='1',
image_format='jpg',
file=FileReader().get_file_handler(path='my_pdf.pdf')
)
# writing the generated image to disk
with open('image.jpg', 'wb') as f:
f.write(image)
a = Pdf4me::CreateThumbnail.new(
file: '/path/to/file/3.pdf',
page_number: 4,
width: 120,
save_path: 'thumbnail.png'
)
a.run
<?php
//uploading file and setting request
$createThumbnail = $client->pdf4me()->createThumbnail(
[
"width" => 4000,
"pageNr" => "1",
"imageFormat" => "jpg"
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('image.jpg', $createThumbnail);
// setup the imageClient
let imageClient = new pdf4me.ImageClient(pdf4meClient);
// image creation
let responsePromise = imageClient.createThumbnail(4000, '1', 'jpg', fs.createReadStream('./myPdf.pdf'));
responsePromise.then(function (thumbnail) {
fs.writeFileSync('./thumbnail.jpg', thumbnail);
}, function (err) {
console.log(err);
});
Produces a thumbnail of the page referenced by the pageNr. Be aware of the one-indexing of the page numbers.
Parameters
Name | Supported Values | Description |
---|---|---|
width integer |
Determines the size of the produced thumbnail. | |
pageNr string |
Number of the page which should be captured by the thumbnail. | |
imageFormat string |
"bmp", "gif", "jb2", "jpg", "jpeg", "jp2", "jpf", "jpx", "png", "tif", "tiff" | Picture format of thumbnail. |
file application/octet-stream |
PDF file. |
Response:
Type: application/octet-stream
Description: Thumbnail
Merge
Merge unites two or possibly multiple PDFs by concatenating them.
merge
// create merge object
var merge = new Merge()
{
// documents
Documents = new System.Collections.ObjectModel.ObservableCollection<Document>()
{
new Document()
{
DocData = File.ReadAllBytes("myFirstPdf.pdf"),
Name = "myFirstPdf.pdf",
},
new Document()
{
DocData = File.ReadAllBytes("mySecondPdf.pdf"),
Name = "mySecondPdf.pdf",
},
},
// action
MergeAction = new MergeAction()
};
// merge
var res = await Pdf4meClient.Pdf4me.Instance.MergeClient.MergeAsync(merge);
// extract the merged PDF and writing it to disk
byte[] mergedPdf = res.Document.DocData;
File.WriteAllBytes("mergedPdf.pdf", mergedPdf);
// setup the mergeClient
MergeClient mergeClient = new MergeClient(pdf4meClient);
// create merge object
Merge merge = new Merge();
// documents
List<Document> documents = new ArrayList<Document>();
Document doc1 = new Document();
doc1.setDocData(Files.readAllBytes(Paths.get("myFirstPdf.pdf")));
documents.add(doc1);
Document doc2 = new Document();
doc2.setDocData(Files.readAllBytes(Paths.get("mySecondPdf.pdf")));
documents.add(doc2);
merge.setDocuments(documents);
// action
merge.setMergeAction(new MergeAction());
// merge
MergeRes res = mergeClient.merge(merge);
// extracting the generated PDF and writing it to disk
byte[] mergedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("mergedPdf.pdf"), mergedPdf);
# setup the merge_client
merge_client = MergeClient(pdf4me_client)
# create the merge object
merge = Merge(
documents=[
Document(
doc_data=FileReader().get_file_data('my_first_pdf.pdf')
),
Document(
doc_data=FileReader().get_file_data('my_second_pdf.pdf')
)
],
merge_action=MergeAction()
)
# merge
res = merge_client.merge(merge=merge)
# extracting the generated PDF
merged_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('merged_pdf.pdf', 'wb') as f:
f.write(merged_pdf)
file_path_1 = './in/PDF_1Page.pdf'
file_path_2 = './in/PDF_10Pages.pdf'
file_path_3 = './in/PDF_100Pages.pdf'
action = Pdf4me::Merge.new(
documents: [
Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path_1, 'rb', &:read))
),
Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path_2, 'rb', &:read))
),
Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path_3, 'rb', &:read))
)
]
)
response = action.run
# saving the merged PDF
File.open('./out/merg_111Pages.pdf', 'wb') do |f|
f.write(Base64.decode64(response.document.doc_data))
end
<?php
// post pdfMerge
$createMerge = $client->pdf4me()->pdfMerge([
"documents" => [
[
'docData' => $client->getFileData('myPdf1.pdf')
],
[
'docData' => $client->getFileData('myPdf2.pdf')
]
]
]);
// extracting the generated PDF
$mergedPdf = base64_decode($createMerge->document->docData);
// and writing it to file
file_put_contents('mergedPdf.pdf', $mergedPdf);
// setup the mergeClient
let mergeClient = new pdf4me.MergeClient(pdf4meClient);
// create the Merge object
let Merge = {
documents: [
{ docData: fs.readFileSync('./myFirstPdf.pdf').toString('base64') },
{ docData: fs.readFileSync('./mySecondPdf.pdf').toString('base64') }
],
mergeAction: {}
};
// merge
let responsePromise = mergeClient.merge(Merge);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./mergedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
merge Merge |
Merge configuration. |
Response:
Type: MergeRes
Description: Contains merged PDF.
merge2Pdfs
curl https://api.pdf4me.com/Merge/Merge2Pdfs ^
-H "Authorization: Basic DEV-KEY" ^
-F "file1=@./Pdf_file1_to_Merge.pdf" ^
-F "file2=@./PDF_file2_to_Merge.pdf" ^
-o ./Merged.pdf
// merge
byte[] mergedPdf = await Pdf4meClient.Pdf4me.Instance.MergeClient.Merge2PdfsAsync(File.ReadAllBytes("myFirstPdf.pdf"), File.ReadAllBytes("mySecondPdf.pdf"));
// and writing the generated PDF to disk
File.WriteAllBytes("mergedPdf.pdf", mergedPdf);
// setup the mergeClient
MergeClient mergeClient = new MergeClient(pdf4meClient);
// merge and writing the generated PDF to disk
byte[] mergedPdf = mergeClient.merge2Pdfs(new File("myFirstPdf.pdf"), new File("mySecondPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("mergedPdf.pdf"), mergedPdf);
# setup the merge_client
merge_client = MergeClient(pdf4me_client)
# merge
merged_pdf = merge_client.merge_2_pdfs(
file1=FileReader().get_file_handler(path='my_first_pdf.pdf'),
file2=FileReader().get_file_handler(path='my_second_pdf.pdf')
)
# writing the generated PDF to disk
with open('merged_pdf.pdf', 'wb') as f:
f.write(merged_pdf)
a = Pdf4me::MergeTwoPdfs.new(
file1: '/path/to/file/1.pdf',
file2: '/path/to/file/2.pdf',
save_path: 'merged.pdf'
)
a.run
//uploading file and setting request
$mergedPdf = $client->pdf4me()->merge2Pdfs(
[
"file1" => __DIR__.'/myPdf1.pdf'
"file2" => __DIR__.'/myPdf2.pdf'
]
);
//writing it to file
file_put_contents('mergedPdf.pdf, $mergedPdf);
// setup the mergeClient
let mergeClient = new pdf4me.MergeClient(pdf4meClient);
// merge
let responsePromise = mergeClient.merge2Pdfs(fs.createReadStream('./myFirstPdf.pdf'), fs.createReadStream('./mySecondPdf.pdf'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./mergedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Merges the two provided PDF files.
Parameters
Name | Description |
---|---|
file1 application/octet-stream |
First Pdf. |
file2 application/octet-stream |
Second Pdf. |
Response:
Type: application/octet-stream
Description: Merged PDF.
Optimize
A PDF can be optimized w.r.t to one of the following four profiles:
Profile | Intent |
---|---|
default | Minimal optimization. |
web | Optimization for the Internet: small size, short download, fast display. |
Optimization for print: correct fonts, right color scheme, suitable resolution. | |
max | Optimization for maximal memory size reduction. |
For more customized optimization you can use the universal function optimize. It lets you configure the compression type, set the resolution, choose whether you would like to clip the invisible parts of the images in your PDF and much more.
optimize
// create optimize object
Optimize optimize = new Optimize()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
OptimizeAction = new OptimizeAction()
{
UseProfile = true,
Profile = OptimizeActionProfile.Max
},
};
// optimize
var res = await Pdf4meClient.Pdf4me.Instance.OptimizeClient.OptimizeAsync(optimize);
// extract the optimized PDF and writing it to disk
byte[] optimizedPdf = res.Document.DocData;
File.WriteAllBytes("optimizedPdf.pdf", optimizedPdf);
// setup the optimizeClient
OptimizeClient optimizeClient = new OptimizeClient(pdf4meClient);
// create optimize object
Optimize optimize = new Optimize();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
optimize.setDocument(document);
// action
OptimizeAction optimizeAction = new OptimizeAction();
optimizeAction.useProfile(true);
optimizeAction.profile(ProfileEnum.MAX);
optimize.setOptimizeAction(optimizeAction);
// optimization
OptimizeRes res = optimizeClient.optimize(optimize);
// extracting the generated PDF and writing it to disk
byte[] optimizedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("optimizedPdf.pdf"), optimizedPdf);
# setup the optimize_client
optimize_client = OptimizeClient(pdf4me_client)
# create the optimize object
optimize = Optimize(
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
optimize_action=OptimizeAction(
use_profile=True,
profile='max'
)
)
# optimization
res = optimize_client.optimize(optimize=optimize)
# extracting the generated PDF
optimized_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('optimized_pdf.pdf', 'wb') as f:
f.write(optimized_pdf)
file = '/path/to/file/1.pdf'
a = Pdf4me::Optimize.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file, 'rb', &:read))
),
optimize_action: Pdf4me::OptimizeAction.new(
use_profile: true,
profile: 'max'
)
)
response = a.run
File.open('optimized.pdf', 'wb') do |f|
f.write(Base64.decode64(response.document.doc_data))
end
<?php
// post pdfOptimize
$createOptimize = $client->pdf4me()->pdfOptimize([
'document' => [
'docData' => $client->getFileData('myPdf.pdf')
],
'optimizeAction' => [
'profile' => 'max',
'useProfile' => true
]
]);
// extracting the optimized PDF
$optimizedPdf = base64_decode($createOptimize->document->docData);
// and writing it to file
file_put_contents('optimizedPdf.pdf', $optimizedPdf);
// setup the optimizeClient
let optimizeClient = new pdf4me.OptimizeClient(pdf4meClient);
// create the Optimize object
let Optimize = {
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64')
},
optimizeAction: {
useProfile: true,
profile: 'max'
},
};
// optimization
let responsePromise = optimizeClient.optimize(Optimize);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./optimizedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
optimize Optimize |
Optimization configuration. |
Response:
Type: OptimizeRes
Description: Contains optimized PDF.
optimizeByProfile
curl https://api.pdf4me.com/Optimize/OptimizeByProfile ^
-H "Authorization: Basic DEV-KEY" ^
-F profile=max ^
-F "file=@./PDF_to_Optimise.pdf" ^
-o ./Optimized.pdf
// optimization for maximal memory size reduction (profile: max)
byte[] optimizedPdf = await Pdf4meClient.Pdf4me.Instance.
OptimizeClient.OptimizeByProfileAsync(
OptimizeActionProfile.Max,
File.ReadAllBytes("myPdf.pdf"));
// and writing the optimized PDF to disk
File.WriteAllBytes("optimizedPdf.pdf", optimizedPdf);
// setup the optimizeClient
OptimizeClient optimizeClient = new OptimizeClient(pdf4meClient);
// optimization for maximal memory size reduction (profile: max) and writing the optimized PDF to disk
byte[] optimizedPdf = optimizeClient.optimizeByProfile(ProfileEnum.MAX, new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("optimizedPdf.pdf"), optimizedPdf);
# setup the optimize_client
optimize_client = OptimizeClient(pdf4me_client)
# optimization
optimized_pdf = optimize_client.optimize_by_profile(
profile='default',
file=FileReader().get_file_handler(path='my_pdf.pdf')
)
# writing the generated PDF to disk
with open('optimized_pdf.pdf', 'wb') as f:
f.write(optimized_pdf)
a = Pdf4me::OptimizeByProfile.new(
file: '/path/to/file/1.pdf',
profile: 'max',
save_path: 'optimized.pdf'
)
a.run
<?php
//uploading file and setting request
$optimizePdfByProfile = $client->pdf4me()->optimizeByProfile(
[
"profile"=> "max",
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('optimizedPdf.pdf', $optimizePdfByProfile);
// setup the optimizeClient
let optimizeClient = new pdf4me.OptimizeClient(pdf4meClient);
// optimization
let responsePromise = optimizeClient.optimizeByProfile('max', fs.createReadStream('./myPdf.pdf'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./optimizedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameters
Name | Supported Values | Description |
---|---|---|
profile string |
"default", "web", "print", "max" | Optimization Profile. |
file application/octet-stream |
Pdf to be optimized. |
Response:
Type: application/octet-stream
Description: Optimized Pdf.
PdfA
Converts PDF documents to the PDF/A format for long-term archiving. There exist three different levels of conformance:
Level | Intent | Supported Compliances |
---|---|---|
B: Basic Conformance | Demands only standards needed for reliable reproduction of a PDFs visual representation. | PDFA1B, PDFA2B, PDFA3B |
A: Accessible Conformance | Basic Conformance and other features to improve the PDF's accessibility such as hierarchical document structure. | PDFA1A, PDFA2A, PDFA3A |
U: Unicode Mapping | All text must have unicode mapping. Guidelines have been replaced with more detailed technical specifications. | PDFA2U, PDFA3U |
Warning: It may well happen that it is not possible to convert a given PDF to the PDF/A format. The conversion to Compliance Level A is most critical, as it requires tagging. Tags provide a logical structure which allows the contents of an image to be described to the visually impaired. Adding tagging information without prior knowledge about the input file’s structure and content is impossible. In which case a Pdf4meBackendException is thrown.
pdfA
// create createPdfA object
var createPdfA = new CreatePdfA()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
PdfAAction = new PdfAAction()
{
Compliance = PdfAActionCompliance.PdfA2u,
}
};
// create PDF/A
var res = await Pdf4meClient.Pdf4me.Instance.PdfAClient.PdfAAsync(createPdfA);
// extract the PDF/A and writing it to disk
byte[] pdfA = res.Document.DocData;
File.WriteAllBytes("pdfA.pdf", pdfA);
// setup the pdfAClient
PdfAClient pdfAClient = new PdfAClient(pdf4meClient);
// create createPdfA object
CreatePdfA createPdfA = new CreatePdfA();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
createPdfA.setDocument(document);
// action
PdfAAction pdfAAction = new PdfAAction();
pdfAAction.setCompliance(ComplianceEnum.PDFA2U);
createPdfA.setPdfAAction(pdfAAction);
// create PDF/A
CreatePdfARes res = pdfAClient.pdfA(createPdfA);
// extracting the generated PDF and writing it to disk
byte[] pdfA = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("pdfA.pdf"), pdfA);
# setup the pdfA_client
pdfA_client = PdfAClient(pdf4me_client)
# create the create_pdfA object
create_pdfA = CreatePdfA(
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
pdf_a_action=PdfAAction(
compliance='pdfA2u'
)
)
# conversion to PDF/A
res = pdfA_client.pdfA(create_pdfA=create_pdfA)
# extracting the generated PDF/A
pdfA = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('pdfA.pdf', 'wb') as f:
f.write(pdfA)
file_path = './in/PDF_10Pages.pdf'
action = Pdf4me::PdfA.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path, 'rb', &:read))
),
pdf_a_action: Pdf4me::PdfAAction.new(
compliance: 'pdfA1a',
allowDowngrade: true,
allowUpgrade: true,
outputIntentProfile: 'sRGBColorSpace',
linearize: true
)
)
response = action.run
# saving the PDF/A document
File.open('./out/PdfA_1a.pdf', 'wb') do |f|
f.write(Base64.decode64(response.document.doc_data))
end
<?php
// post pdfA
$createPdfA = $client->pdf4me()->pdfA([
"document" => [
'name' => 'test.pdf',
'docData' => $client->getFileData('myPdf.pdf')
],
"pdfAAction" => [
"compliance" => "pdfa2u"
]
]);
// extracting the generated PDF
$pdfA = base64_decode($createPdfA->document->docData);
// and writing it to file
file_put_contents('pdfA.pdf', $pdfA);
// setup the pdfAClient
let pdfAClient = new pdf4me.PdfAClient(pdf4meClient);
// create the CreatePdfA object
let CreatePdfA = {
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64'),
},
pdfAAction: {
compliance: 'pdfA2b'
},
};
// conversion to PDF/A
let responsePromise = pdfAClient.pdfA(CreatePdfA);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./pdfA.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
createPdfA CreatePdfA |
PDF/A conversion configuration. |
Response:
Type: CreatePdfARes
Description: Contains generated PDF/A.
createPdfA
curl https://api.pdf4me.com/PdfA/CreatePdfA ^
-H "Authorization: Basic DEV-KEY" ^
-F pdfCompliance=pdfA1b ^
-F "file=@./PDF_10pages.pdf" ^
-o ./CreatePdfA.pdf
// creating PDF/A - only providing the file and writing it to disk
byte[] pdfA = await Pdf4meClient.Pdf4me.Instance.PdfAClient.CreatePdfAAsync(File.ReadAllBytes("myPdf.pdf"));
File.WriteAllBytes("pdfA.pdf", pdfA);
// creating PDF/A - providing the file and the desired pdfCompliance and writing it to disk
byte[] pdfA = await Pdf4meClient.Pdf4me.Instance.PdfAClient.CreatePdfAAsync(PdfAActionCompliance.PdfA2b, File.ReadAllBytes("myPdf.pdf"));
File.WriteAllBytes("pdfA.pdf", pdfA);
// setup the pdfAClient
PdfAClient pdfAClient = new PdfAClient(pdf4meClient);
// creating PDF/A - only providing the file and writing it to disk
byte[] pdfA = pdfAClient.createPdfA(new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("pdfA.pdf"), pdfA);
// creating PDF/A - providing the file and the desired pdfCompliance and writing it to disk
byte[] pdfA = pdfAClient.createPdfA(ComplianceEnum.PDFA2U, new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("pdfA.pdf"), pdfA);
# setup the pdfA_client
pdfA_client = PdfAClient(pdf4me_client)
# conversion to PDF/A with pdf_compliance specification
pdfA = pdfA_client.create_pdfA(
pdf_compliance='pdfA2u',
file=FileReader().get_file_handler(path='my_pdf.pdf')
)
# or conversion to PDF/A without pdf_compliance specification
pdfA = pdfA_client.create_pdfA(
file=FileReader().get_file_handler(path='my_pdf.pdf')
)
# writing the PDF/A to disk
with open('pdfA.pdf', 'wb') as f:
f.write(pdfA)
a = Pdf4me::CreatePdfA.new(
file: '/path/to/file/1.pdf',
compliance: 'pdfA1a',
save_path: 'to_pdfa.pdf'
)
a.run
<?php
//uploading file and setting request
$createPdfAFile = $client->pdf4me()->createPdfA(
[
"pdfCompliance"=> "pdfa2u",
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('pdfA.pdf', $createPdfAFile);
// setup the pdfAClient
let pdfAClient = new pdf4me.PdfAClient(pdf4meClient);
// conversion to PDF/A
let responsePromise = pdfAClient.createPdfA('pdfA2b', fs.createReadStream('./myPdf.pdf'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./pdfA.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Default | Supported Values | Description |
---|---|---|---|
pdfCompliance string optional |
"pdfA2b" | "pdfA1b", "pdfA2B", "pdfA3b", "pdfA1a", "pdfA2a", "pdfA3a", "pdfA2u", "pdfA3u" | PDF/A compliance level. |
file application/octet-stream |
PDF file. |
Response:
Type: application/octet-stream
Description: Generated PDF/A.
Split
Splits a PDF of multiple pages into a number of smaller PDF documents.
split
//create split object
var split = new Split()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
SplitAction = new SplitAction()
{
SplitAfterPage = 2
},
};
// split
var res = await Pdf4meClient.Pdf4me.Instance.SplitClient.SplitAsync(split);
// extract the resulting documents and writing them to disk
byte[] pdf1 = res.Documents[0].DocData;
byte[] pdf2 = res.Documents[1].DocData;
File.WriteAllBytes("pdf1.pdf", pdf1);
File.WriteAllBytes("pdf2.pdf", pdf2);
// setup the splitClient
SplitClient splitClient = new SplitClient(pdf4meClient);
//create split object
Split split = new Split();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
split.setDocument(document);
// action
SplitAction splitAction = new SplitAction();
splitAction.setSplitAfterPage(2);
split.setSplitAction(splitAction);
// split
SplitRes res = splitClient.split(split);
// extracting the generated PDFs and writing them to disk
List<Document> documents = res.getDocuments();
byte[] pdf1 = documents.get(0).getDocData();
FileUtils.writeByteArrayToFile(new File("pdf1.pdf"), pdf1);
byte[] pdf2 = documents.get(1).getDocData();
FileUtils.writeByteArrayToFile(new File("pdf2.pdf"), pdf2);
# setup the split_client
split_client = SplitClient(pdf4me_client)
# create the split object
split = Split(
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
split_action=SplitAction(
split_after_page=2
)
)
# splitting the PDF
res = split_client.split(split=split)
# extracting the generated PDFs
documents = res['documents']
pdf_1 = base64.b64decode(documents[0]['doc_data'])
pdf_2 = base64.b64decode(documents[1]['doc_data'])
# writing them to disk
with open('pdf_1.pdf', 'wb') as f:
f.write(pdf_1)
with open('pdf_2.pdf', 'wb') as f:
f.write(pdf_2)
file_path = './in/GraphicsTest.pdf'
action = Pdf4me::Split.new(
document: Pdf4me::Document.new(
doc_data: Base64.encode64(File.open(file_path, 'rb', &:read)),
),
split_action: Pdf4me::SplitAction.new(
split_after_page: 3
)
)
response = action.run
# save documents
response.documents.each_with_index do |document, index|
File.open("./out/Split_#{index}.pdf", 'wb') do |f|
f.write(Base64.decode64(document.doc_data))
end
end
<?php
// post pdfSplit
$createSplit = $client->pdf4me()->splitPdf([
"document" => [
'name' => 'test.pdf',
'docData' => $client->getFileData('myPdf.pdf')
],
"SplitAction" => [
"splitAfterPage" => 1
]
]);
// extracting the generated PDFs
$pdf1 = base64_decode($createSplit->documents[0]->docData);
$pdf2 = base64_decode($createSplit->documents[1]->docData);
// and writing them to file
file_put_contents('pdf1.pdf', $pdf1);
file_put_contents('pdf2.pdf', $pdf2);
// setup the splitClient
let splitClient = new pdf4me.SplitClient(pdf4meClient);
// create the Split object
let Split = {
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64')
},
splitAction: {
splitAfterPage: 2
}
};
// splitting the PDF
let responsePromise = splitClient.split(Split);
responsePromise.then(function (response) {
let pdf1 = new Buffer(response['documents'][0]['docData'], 'base64');
let pdf2 = new Buffer(response['documents'][1]['docData'], 'base64');
fs.writeFileSync('./pdf1.pdf', pdf1);
fs.writeFileSync('./pdf2.pdf', pdf2);
}, function (err) {
console.log(err);
});
Parameter
Name | Type | Description |
---|---|---|
split Split |
Split configuration. |
Response:
Type: SplitRes
Description: Contains the document splinters of the original PDF document.
splitByPageNr
curl https://api.pdf4me.com/Split/SplitByPageNr ^
-H "Authorization: Basic DEV-KEY" ^
-F pageNr=3 ^
-F "file=@./PDF_to_Split.pdf" ^
-o ./Splited.pdf
// split the PDF into two
List<byte[]> res = await Pdf4meClient.Pdf4me.Instance.SplitClient.SplitByPageNrAsync(2, File.ReadAllBytes("myPdf.pdf"));
// and writing the resulting PDFs to disk
File.WriteAllBytes("pdf1.pdf", res[0]);
File.WriteAllBytes("pdf2.pdf", res[1]);
// setup the splitClient
SplitClient splitClient = new SplitClient(pdf4meClient);
// split the PDF into two and writing the resulting PDFs to disk
List<byte[]> res = splitClient.splitByPageNr(2, new File("myPdf.pdf"));
byte[] pdf1 = res.get(0);
FileUtils.writeByteArrayToFile(new File("pdf1.pdf"), pdf1);
byte[] pdf2 = res.get(1);
FileUtils.writeByteArrayToFile(new File("pdf2.pdf"), pdf2);
# setup the split_client
split_client = SplitClient(pdf4me_client)
# splitting the PDF
pdf_1, pdf_2 = split_client.split_by_page_nr(
page_nr=2,
file=FileReader().get_file_handler(path='my_pdf.pdf')
)
# writing the generated PDFs to disk
with open('pdf_1.pdf', 'wb') as f:
f.write(pdf_1)
with open('pdf_2.pdf', 'wb') as f:
f.write(pdf_2)
a = Pdf4me::SplitByPageNr.new(
file: '/path/to/file/3.pdf',
page_number: 3,
first_pdf: 'first.pdf', # defaults to '/path/to/file/3-first.pdf'
second_pdf: 'second.pdf' # defaults to '/path/to/file/3-second.pdf'
)
a.run
<?php
//uploading file and setting request
$splitPdfByPageNr = $client->pdf4me()->splitByPageNr(
[
"pageNr"=> 1,
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('pdf1.pdf', $splitPdfByPageNr[0]);
file_put_contents('pdf2.pdf', $splitPdfByPageNr[1]);
// setup the splitClient
let splitClient = new pdf4me.SplitClient(pdf4meClient);
// splitting the PDF
let responsePromise = splitClient.splitByPageNr(2, fs.createReadStream('./myPdf.pdf'));
responsePromise.then(function (pdfs) {
fs.writeFileSync('./pdf1.pdf', pdfs[0]);
fs.writeFileSync('./pdf2.pdf', pdfs[1]);
}, function (err) {
console.log(err);
});
Splits the PDF after the pageNr, this results in two smaller PDF documents.
Parameters
Name | Description |
---|---|
pageNr integer |
Determines after which page the split takes place. |
file application/octet-stream |
PDF file. |
Response:
Type: application/octet-stream
Description: The two parts of the original PDF document.
Stamp
Creates textual or image stamps on PDF documents. This client allows you to highly personalize your stamp. The font, color, rendering mode and position of your stamp are only the start. For detailed information have a look at the StampAction. Furthermore, you may select the pages your stamp will be applied to.
stamp
// create stamp object
Stamp stamp = new Stamp()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
StampAction = new StampAction()
{
Text = new Text()
{
Value = "EXAMPLE TEXT"
},
PageSequence = "all",
Alpha = 1.0,// opacity of the stamp: 1.0 for fully opaque, 0.0 for fully transparent.
AlignX = StampActionAlignX.Center,
AlignY = StampActionAlignY.Middle
},
};
// stamp
var res = await Pdf4meClient.Pdf4me.Instance.StampClient.StampAsync(stamp);
// extract the stamped PDF and writing it to disk
byte[] stampedPdf = res.Document.DocData;
File.WriteAllBytes("stampedPdf.pdf", stampedPdf);
// setup the stampClient
StampClient stampClient = new StampClient(pdf4meClient);
// create stamp object
Stamp stamp = new Stamp();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
stamp.setDocument(document);
// action
StampAction stampAction = new StampAction();
Text textObj = new Text();
textObj.setValue("EXAMPLE TEXT");
stampAction.setText(textObj);
stampAction.setAlpha(1.0); // opacity of the stamp: 1.0 for fully opaque, 0.0 for fully transparent.
stampAction.setPageSequence("all");
stampAction.setAlignX(AlignXEnum.CENTER);
stampAction.setAlignY(AlignYEnum.MIDDLE);
stamp.setStampAction(stampAction);
// stamp
StampRes res = stampClient.stamp(stamp);
// extracting the generated PDF and writing it to disk
byte[] stampedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("stampedPdf.pdf"), stampedPdf);
# setup the stamp_client
stamp_client = StampClient(pdf4me_client)
# create the stamp object
stamp = Stamp(
document=Document(
doc_data=FileReader().get_file_data('my_pdf.pdf')
),
stamp_action=StampAction(
text=Text(
value='EXAMPLE TEXT'
),
alpha=1.0,
page_sequence='all',
align_x='center',
align_y='middle'
)
)
# applying the stamp to the PDF
res = stamp_client.stamp(stamp=stamp)
# extracting the generated PDF
stamped_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('stamped_pdf.pdf', 'wb') as f:
f.write(stamped_pdf)
rework sample...
<?php
$createStampPdf = $client->pdf4me()->stampPdf([
'document' => [
'docData' => $client->getFileData('myPdf.pdf')
],
'stampAction' => [
"pageSequence" => 'all',
"alpha" => 1.0,
"alignX" => 'center',
"alignY" => 'middle',
"text" => [
"value" => 'EXAMPLE'
]
]
]);
// extracting the generated PDFs
$stampedPdf = base64_decode($createStampPdf->document->docData);
// and writing them to file
file_put_contents('stampedPdf.pdf', $stampedPdf);
// setup the stampClient
let stampClient = new pdf4me.StampClient(pdf4meClient);
// create the Stamp object
let Stamp = {
document: {
docData: fs.readFileSync('./myPdf.pdf').toString('base64')
},
stampAction: {
text: { value: 'EXAMPLE TEXT' },
alpha: 1.0,
pageSequence: 'all',
alignX: 'center',
alignY: 'middle'
}
};
// applying the stamp to the PDF
let responsePromise = stampClient.stamp(Stamp);
responsePromise.then(function (response) {
let pdf = new Buffer(response['document']['docData'], 'base64');
fs.writeFileSync('./stampedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Parameter
Name | Description |
---|---|
stamp Stamp |
Stamp configuration. |
Response:
Type: StampRes
Description: Contains the stamped PDF.
textStamp
curl https://api.pdf4me.com/Stamp/TextStamp ^
-H "Authorization: Basic DEV-KEY" ^
-F text=STAMP ^
-F pages=3,4,5 ^
-F alignX=center ^
-F alignY=middle
-F "file=@./PDF_to_Stamp.pdf" ^
-o ./Stamped.pdf
// stamp
byte[] stampedPdf = await Pdf4meClient.Pdf4me.Instance.StampClient.TextStampAsync("EXAMPLE TEXT", "all", AlignX.Center, AlignY.Middle, File.ReadAllBytes("myPdf.pdf"));
// and writing the generated PDF to disk
File.WriteAllBytes("stampedPdf.pdf", stampedPdf);
// setup the stampClient
StampClient stampClient = new StampClient(pdf4meClient);
// stamp and writing the generated PDF to disk
byte[] stampedPdf = stampClient.textStamp("EXAMPLE TEXT", "all", AlignXEnum.CENTER,
AlignYEnum.MIDDLE, new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("stampedPdf.pdf"), stampedPdf);
# setup the stamp_client
stamp_client = StampClient(pdf4me_client)
# applying the stamp to the PDF
stamped_pdf = stamp_client.text_stamp(
text='EXAMPLE TEXT',
pages='all',
align_x='center',
align_y='middle',
file=FileReader().get_file_handler(path='my_pdf.pdf')
)
# writing the generated PDF to disk
with open('stamped_pdf.pdf', 'wb') as f:
f.write(stamped_pdf)
a = Pdf4me::TextStamp.new(
file: '/path/to/file/1.pdf',
pages: [1, 3],
position_x: 'left',
position_y: 'top',
text: 'Hello Pdf4me',
save_path: 'stamped.pdf'
)
a.run
<?php
//uploading file and setting request
$stampedPdf = $client->pdf4me()->textStamp(
[
"text" => 'EXAMPLE'
"pages" => 'all',
"alignX" => 'center',
"alignY" => 'middle',
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('pdf1.pdf', $stampedPdf);
// setup the stampClient
let stampClient = new pdf4me.StampClient(pdf4meClient);
// applying the stamp to the PDF
let responsePromise = stampClient.textStamp('EXAMPLE TEXT', 'all', 'center', 'middle', fs.createReadStream('./myPdf.pdf'));
responsePromise.then(function (pdf) {
fs.writeFileSync('./stampedPdf.pdf', pdf);
}, function (err) {
console.log(err);
});
Places a custom text stamp on the pages of your choice. The position of the stamp is specified by alignX and alignY.
Parameters
Name | Supported Values | Description |
---|---|---|
text string |
Custom text on stamp. | |
pages string |
"all", "first", "last", "odd", "even", "notFirst", "notLast" or a list of comma separated page numbers e.g. "1,4", if the first and fourth page need to be stamped. | Pages to be stamped. |
alignX string |
"left", "center", "right" | Horizontal position. |
alignY string |
"top", "middle", "bottom" | Vertical position. |
file application/octet-stream |
PDF file. |
Response:
Type: application/octet-stream
Description: Stamped PDF.
Model
ConvertToPdfReq
Name | Description |
---|---|
document Document |
Document |
convertToPdfAction ConvertToPdfAction |
Conversion configuration. |
notification Notification |
Notification |
ConvertToPdfAction
Name | Default | Supported Values | Description |
---|---|---|---|
pdfConformance string |
'pdf17' | 'pdf17', 'pdfA1', 'pdfA2', 'pdfA3' | Compliance level of the generated PDF. |
conversionMode string |
'fast' | 'detailed', 'fast' | Conversion mode. |
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
ConvertToPdfRes
Name | Description |
---|---|
document Document |
Generated PDF document. |
ExtractReq
Name | Description |
---|---|
document Document |
Document |
extractAction ExtractAction |
Extraction configuration. |
notification Notification |
Notification |
ExtractAction
Name | Description |
---|---|
extractPages [ integer ] |
List of the pages which will be extracted. Page number 1 corresponds to the first page. |
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
ExtractRes
Name | Description |
---|---|
document Document |
PDF consisting of the extracted pages. |
CreateImagesReq
Name | Description |
---|---|
document Document |
Document |
imageAction ImageAction |
Image Creation configuration. |
notification Notification |
Notification |
ImageAction
Name | Default | Supported Values | Description |
---|---|---|---|
pageSelection PageSelection |
Pages which will be converted to images. | ||
center boolean |
false | Center mode. - true: the document is horizontally and vertically centered on the page. - false: the document is printed to the upper left corner of the page. |
|
fitPage boolean |
true | Fit page mode. - true: the page is scaled to fit the image (in either width or height). - false: the page is rendered with its true size. |
|
bitsPerPixel integer |
24 | bi-tonal: 1, gray scale: 8, RGB true color: 24, CMYK: 32 |
Color depth. |
bilevelThreshold integer |
181 | [0, 255] | Threshold for converting from gray to bi-tonal when dithering is set to "none". |
widthPixel integer |
Width [pixel] | ||
heightPixel integer |
Height [pixel] | ||
widthPoint integer |
Width [points] | ||
heightPoint integer |
Height [points] | ||
renderOptions [string] |
"noAntialiasing", "noInterpolation", "noLowPassFilter", "noHinting", "printingMode", "noBPC", "fitPaths", "useBoxFilter" | Rendering options. | |
rotateMode string |
"attribute" | "none" "attribute" : set the rotation to the viewing rotation attribute of the PDF page, i.e. rendering the page with the same rotation as it is displayed in a PDF viewer. "portrait" "landscape" |
Rotation mode of the page. |
preserveAspectRatio boolean |
true | Aspect Ratio Preservation. - true: a uniform up- or down-scaling is applied, i.e. the output image has the same ratio of width to height as the input file and its size will fit into the defined dimensions. |
|
imageQuality integer |
80 | [1, 100] | Quality index of lossy compression types. It is applied to JPEG and JPEG2000 compression. For JPEG2000, a quality index of 100 means lossless compression. JPEG compression is always lossy. |
cmsEngine string |
"lcms" | "none": the algorithms specified in the PDF reference are used. This results in the maximum possible contrast. "neugebauer": efficiently converts CMYK to RGB. It does not need any color profiles. The results, however, look similar to conversion using color profiles. "lcms": uses ICC color profiles. "customCMS": a configurable version of the Neugebauer algorithm is applied. The coefficients can be defined in the customCMSConfig. |
Color Management System (CMS) Engine. |
customCMSConfig CustomCMSConfig |
Custom Management System (CMS) Engine for Neugebauer algorithm. In order for the customCMSConfig to be used, set the cmsEngine to "customCMS". | ||
dithering string |
"floydSteinberg" | "none", "floydSteinberg", "halftone", "pattern", "g3Optimized", "g4Optimized", "atkinson" | Dithering algorithm. Dithering refers to the procedure of simulating colors or grayscales. This is mainly useful for low color depth (e.g. black and white or indexed) images. |
dpi integer |
150 | Resolution of the image in DPI (dots per inch). The x- and y-axis are set to the same value. | |
fillOrder string |
"mSB" | "mSB": most significant bit. "lSB": least significant bit. |
Bit fill order. |
filterRatio integer |
1 | 1, 2, 3 | This property is used to enable and parameterize super-sampling, a technique to initially render the image at a higher resolution and then sample it down to the target resolution. As a result of that process the final image appears smoother, i.e. anti-aliased. Applying super-sampling improves the image quality when rendering at low target resolutions (72 DPI or less); the higher the target resolution the less the visual impact. This property requires memory and CPU time quadratically to the ratio, therefore only small values, such as 2 or 3 should be used. If a too high value (in combination with the original image size) is set, it is ignored. |
imageExtension string required |
"jpg", "jpeg", "bmp", "gif", "jb2", "jp2", "jpf", "jpx", "png", "tif", "tiff" | Output type for image file. | |
colorSpace string |
"RGB" | "RGB", "RGBA", "Gray", "GrayA", "CMYK", "YCbCr", "YCbCrK", "Palette", "LAB", "CMYK_Konly", "CMYKA" | Color space of the output image. For black white bi-tonal images, a gray color space must be selected. |
compression string |
"LZW" | "raw", "jPEG", "flate", "LZW", "group3", "group3_2D", "group4", "jBIG2", "jPEG2000", "tIFFJPEG" | Get or set the compression type of TIFF images. For any other image format, the compression is automatically defined by the file extension. |
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
CreateImagesRes
Name | Description |
---|---|
document Document |
PDF with embedded images. |
MergeReq
Name | Description |
---|---|
documents [Document] |
Documents |
mergeAction MergeAction |
Merge configuration. |
notification Notification |
Notification |
MergeAction
Name | Description |
---|---|
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
MergeRes
Name | Description |
---|---|
document Document |
Document composed of the merged files. |
OptimizeReq
Name | Description |
---|---|
document Document |
Document |
optimizeAction OptimizeAction |
Optimization conifguration. |
notification Notification |
Notification |
OptimizeAction
Name | Default | Supported Values | Description |
---|---|---|---|
profile string |
"default" | "default": minimal optimization. "web": optimization for the Internet: small size, short download, fast display. "print": optimization for print: correct fonts, right color scheme, suitable resolution. "max": optimization for the Internet: small size, short download, fast display. |
Predefined optimization profile. |
useProfile boolean |
false | Whether or not the chosen profile is applied or the default optimization setting comes into play. | |
removeRedundantObjects boolean |
false | Removal of redundant objects. - true: duplicate objects are removed in order to reduce the file size. |
|
subsetFonts boolean |
false | Subsetting and merging of fonts. - true: subsets embedded fonts and merges embedded font programs of different subsets of the same font, granted they can be merged. Sub-setting refers to removing those glyphs in a font that are not actually used in any text contained in the PDF. If for any reason, e.g. postprocessing, fonts shall not be subset, set the property subsetFonts to false. |
|
optimizeResources boolean |
false | Optimization of resources. - true: unused resources such as images, fonts, and color spaces are removed. Also content streams are re-built. |
|
forceCompressionTypes boolean |
false | Enforcement of specific compression types. - true: re-compression of images is forced if an image in the input PDF has a compression type that differs from the compression types given in continuousCompressions, bitonalCompressions, or indexedCompressions. Use this option if you want to allow only the given compression types for images in the output PDF. |
|
forceRecompression boolean |
false | Recompression of images. - true: all images are always recompressed. - false: images are only recompressed if the resulting image is smaller than the original, i.e. requires less bytes to store in the file. |
|
reduceColorComplexity boolean |
false | Color complexity reduction of images. - true: an image with DeviceRGB or DeviceCMYK color space in which all pixels are gray is converted to a grayscale image with DeviceGray color space. An image that contains only black and white pixels is converted into a bitonal image. An image in which all the pixels have the same color is down-sampled to one pixel. A soft mask that contains only black and white pixels is converted to a mask and opaque (soft) masks are removed. |
|
mergeEmbeddedFonts boolean |
false | Merge embedded font programs. - true: font programs are merged, if they originate from the same font, e.g. they are of the same type, have the same name and encoding. Merging of Type1 (PostScript) and TrueType fonts is supported. |
|
bitonalCompressions [string] |
["none"] | "none": exclude from processing. "raw": no compression. "jPEG", "flate", "lZW", "group3", "group3_2D", "group4", "jBIG2": supported in PDF1.4 or later. "jPEG2000": supported in PDF1.5 or later, not supported in PDF/A-1. "mRC", "source": not a single compression format. Instead, uses the same compression as the original input image. |
Compression types for bi-tonal images. Several values can be combined. During optimization, all set compression types are tried and the one resulting in the least memory footprint is taken. Typically, CCITT Group 4 or JBIG2 is used for bi-tonal compression. Due to the simpler algorithm CCITT Group 4 has the advantage of being faster. JBIG2 can achieve compression ratios that are up to twice as high as CCITT Group 4 at the cost of longer computation time. |
bitonalResolutionDPI double |
200 | Target resolution in dots per inch (DPI) after re-sampling images for bi-tonal images. Only bi-tonal images with a resolution above the threshold DPI will be re-sampled. See also resolutionDPI, another optimize parameter. | |
bitonalThresholdDPI double |
-1 | Threshold resolution in dots per inch (DPI) to selectively activate re-sampling for bi-tonal images. The value -1 deactivates re-sampling for bitonal images. See also thresholdDPI, another optimize parameter. | |
clipImages boolean |
false | Option to clip images. - true: invisible parts of images are clipped (cropped). While this does not affect visual parts of images, it may have a minor visual impact because clipped images are re-compressed. Pre-blended images are not clipped. Enabling this property will also enable the optimizeResources property. |
|
continuousCompressions [string] |
["none"] | "none": exclude from processing. "raw": no compression. "jPEG", "flate", "lZW", "group3", "group3_2D", "group4", "jBIG2": supported in PDF1.4 or later. "jPEG2000": supported in PDF1.5 or later, not supported in PDF/A-1. "mRC", "source": not a single compression format. Instead, uses the same compression as the original input image. |
Compression types to be tried for continuous images, i.e. RGB, CMYK, and grayscale images. Several values can be combined. During optimization, all set compression types are tried and the one resulting in the least memory footprint is taken. |
linearize boolean |
false | Linearization of the PDF output file i.e. optimize file for fast web access. A linearized document has a slightly larger file size than a non-linearized file and provides the following main features: When a document is opened in a PDF viewer of a web browser, the first page can be viewed without downloading the entire PDF file. In contrast, a non-linearized PDF file must be downloaded completely before the first page can be displayed. When another page is requested by the user, that page is displayed as quickly as possible and incrementally as data arrives, without downloading the entire PDF file. Signed files cannot be linearized. So this property must be set to false if a digital signature is applied. | |
imageQuality integer |
75 | [1, 100] | Quality index of lossy compression types. It is applied to JPEG and JPEG2000 compression. For JPEG2000, a quality index of 100 means lossless compression. JPEG compression is always lossy. |
indexedCompressions [string] |
["flate"] | "none": exclude from processing. "raw": no compression. "jPEG", "flate", "lZW", "group3", "group3_2D", "group4", "jBIG2": supported in PDF1.4 or later. "jPEG2000": supported in PDF1.5 or later, not supported in PDF/A-1. "mRC", "source": not a single compression format. Instead, uses the same compression as the original input image. |
Compression types for images that have an indexed (“palette”) color space. Several values can be combined. During optimization, all set compression types are tried and the one resulting in the least memory footprint is taken. |
ditheringMode string |
"none" | "none", "floydSteinberg", "halftone", "pattern", "g3Optimized", "g4Optimized", "atkinson" | Dithering algorithm when down-sampling bi-tonal images (creates an illusion of color depth by diffusing colors of the available palette). Some bi-tonal images try to evoke the impression of different levels of gray by randomly setting pixels to black. If dithering is applied during downsampling then the gray levels of such images are preserved better. If dithering is switched off then lines (e.g. text glyphs) are preserved better. |
colorResolutionDPI double |
150 | Target resolution in dots per inch (DPI) after re-sampling images for color images. See also resolutionDPI. | |
colorThresholdDPI double |
-1 | Threshold resolution in dots per inch (DPI) to selectively activate re-sampling for color images. Only color images with a resolution above the threshold DPI will be re-sampled. The value -1 deactivates re-sampling for color images. See also thresholdDPI. | |
monochromeResolutionDPI double |
150 | Target resolution in dots per inch (DPI) after re-sampling images for monochrome images. See also resolutionDPI. | |
monochromeThresholdDPI double |
-1 | Threshold resolution in dots per inch (DPI) to selectively activate re-sampling for monochrome images. Only monochrome images with a resolution above the threshold DPI will be re-sampled. The value -1 deactivates re-sampling for monochrome images. See also thresholdDPI. | |
resolutionDPI integer |
different defaults apply to different image types | Resolution in DPI (dots per inch) after re-sampling images. This property affects all three image compression types (bitonalResolutionDPI, colorResolutionDPI, monochromeResolutionDPI). A typical value for the resolution when optimizing for the web is 150 DPI. For printing typically no re-sampling is applied. Pre-blended images, images with a color key mask, mask, and soft mask images are not re-sampled. | |
thresholdDPI integer |
-1 | Threshold in DPI (dots per inch) to selectively activate re-sampling. Only images with a resolution above the threshold DPI will be re-sampled. This property affects all three image compression types (bitonalThresholdDPI, colorThresholdDPI, monochromeThresholdDPI). The value -1 deactivates re-sampling. | |
strip [string] |
["threads"] | "threads": strip article threads. "metadata": strip meta data. "pieceInfo": strip page piece info (private application data). "structTree": strip document structure tree (incl. Mark-up). "thumb": strip thumbnails. "spider": strip spider (web capture) info. "alternates": strip alternate images. "forms": strip and flatten form fields. "links": strip and flatten link annotations. "annots": strip and flatten annotations except form fields and links. "formsAnnots": strip and flatten form fields, links, and annotations. This implies "forms", "links", "annots". "outputIntents": strip the document output intents. "all": strip everything (all of the above). |
Stripping mode. This mode can be configured to remove unneeded data of a PDF document. Multiple values can be combined. |
infoEntries [KeyValuePair[String, String]] |
Key-value pair in the document info dictionary. Values of predefined keys are also stored in the XMP metadata. Popular entries specified in the PDF Reference 1.7 and accepted by most PDF viewers are: "Title", "Author", "Subject", "Creator" (sometimes referred to as Application), and "Producer" (sometimes referred to as PDF Creator). | ||
flattenSignatureFields boolean |
false | A signature in a PDF consist of two parts: A) The invisible digital signature in the PDF. B) The visual appearance that was attributed to the signature. Part A can be used by a viewing application, to verify that a document has not changed since it has been signed and report this to the user. Part B is merely a “decorative” element on the page without further significance. When optimizing a PDF, the PDF is altered and hence the digital signature is broken. Therefore, all signatures are removed, including parts A and B. - true: the digital signatures (parts A) are still removed, but their visual appearances (parts B) are flattened. I.e. the latter are retained and drawn as non-editable graphic onto the page. Note: The resulting PDF can be misleading as it visually appears to be signed, but it has no digital signature and hence, a viewer application does not report any broken signature. In most cases, such a behavior is undesirable. |
|
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
OptimizeRes
Name | Type |
---|---|
document Document |
Optimized Document. |
notification Notification |
Notification |
CreatePdfAReq
Name | Description |
---|---|
document Document |
Document |
pdfAAction PdfAAction |
PDF/A conversion configuration. |
notification Notification |
Notification |
PdfAAction
Name | Default | Supported Values | Description |
---|---|---|---|
fontsToSubset [PdfFont] |
By default, fonts that are embedded are automatically subset to minimize the file size. Whether fonts are subset or not is irrelevant with respect to the compliance with PDF/A. (Relevant is only that all used glyphs are contained in the font program.) Additionals fonts can be given in this FontsToSubset List. | ||
compliance string |
"pdfA2b" | "pdfA1b", "pdfA2B", "pdfA3b", "pdfA1a", "pdfA2a", "pdfA3a", "pdfA2u", "pdfA3u" | PDF compliance. Some files cannot be converted to the compliance requested. This will be detected and, if possible, an up- (allowUpgrade) or downgrade (allowDowngrade) of the compliance will be applied automatically. |
allowDowngrade boolean |
false | Automatic downgrade of the PDF/A conformance level. - true: the level is downgraded under the following conditions: A) Downgrade to level B: If a file contains text that is not extractable (i.e. missing ToUnicode information). Example: Downgrade PDF/A-2u to PDF/A-2b. B) Downgrade to level U (PDF/A-2 and PDF/A-3) or B(PDF/A-1): Level A requires logical structure information and “tagging” information, so if a file contains no such information, its level is downgraded. Logical structure information in a PDF defines the structure of content, such as titles, paragraphs, figures, reading order, tables or articles. Logical structure elements can be “tagged” with descriptions or alternative text. “Tagging” allows the contents of an image to be described to the visually impaired. It is not possible for Pdf/A converter to add meaningful tagging information. Adding tagging information without prior knowledge about the input file’s structure and content is neither possible nor allowed by the PDF/A standard. For that reason, the conformance level is automatically downgraded to level B or U. - false: and an input file cannot be converted to the requested standard, e.g. because of missing “tagging” information, the conversion is aborted and the ErrorCode set to PDF_E_DOWNGRADE. |
|
allowUpgrade boolean |
false | Automatic upgrade of the PDF/A version. - true: automatic upgrade of the PDF/A version is allowed. If the target standard is PDF/A-1 and a file contains elements that cannot be converted to PDF/A-1, the target standard is upgraded to PDF/A-2. This avoids significant visual differences in the output file. For example, the following elements may lead to an automatic upgrade: A) Transparency B) Optional content groups (OCG, layers). C) Real values that exceed the implementation limit of PDF/A-1. D) Embedded OpenType font files. E) Predefined CMap encodings in Type0 fonts. - false: the compliance is not upgraded. And in case of: A) occurance of visual differences in output file B) removal of optional content groups (layers) (PDF/A-1 only) C) removal of transparency (PDF/A-1 only) D) removal of embedded files E) removal of non convertible XMP metadata F) the input document is corrupt and should be repaired the conversion will fail with a conversion error PDF_E_CONVERSION. |
|
outputIntentProfile string |
"notSet" | "notSet", "sRGBColorSpace" | Output Intent Profile. The given profile is embedded only if the input file does not contain a PDF/A output intent already. |
linearize boolean |
false | Linearization of the PDF output file i.e. optimize file for fast web access. A linearized document has a slightly larger file size than a non-linearized file and provides the following main features: When a document is opened in a PDF viewer of a web browser, the first page can be viewed without downloading the entire PDF file. In contrast, a non-linearized PDF file must be downloaded completely before the first page can be displayed. When another page is requested by the user, that page is displayed as quickly as possible and incrementally as data arrives, without downloading the entire PDF file. Signed files cannot be linearized. So this property must be set to false if a digital signature is applied. | |
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
CreatePdfARes
Name | Description |
---|---|
document Document |
PDF/A Document. |
SplitReq
Name | Description |
---|---|
document Document |
Document |
SplitAction SplitAction |
Split configuration. |
notification Notification |
Notification |
SplitAction
Name | Description |
---|---|
splitAfterPage integer |
Page after which the split takes place. |
splitSequence [integer] |
A list of page number after which a split occurs. |
recurringSplitAfterPage integer |
Split every xth page. |
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
SplitRes
Name | Description |
---|---|
documents [Document] |
Document splinters of the original document. |
StampReq
Name | Description |
---|---|
document Document |
Document |
stampAction StampAction |
Stamp configuration. |
notification Notification |
Notification |
StampAction
Name | Default | Supported Values | Description |
---|---|---|---|
pageSequence string |
"1" | "all", "first", "last", "odd", "even", "notFirst", "notLast" or a list of comma separated page numbers e.g. "1,4", if the first and fourth page need to be stamped. | Pages the action is applied to. |
relativePosX integer |
Relative position of the stamp with regards to the page. Positive values define the distances from the stamp to the left page border, negative values to the right page boundary respectively. The units of the values are PDF units of 1/72 inch. | ||
relativePosY integer |
Relative position of the stamp with regards to the page. Positive values define the distances from the stamp to the lower, negative values to the upper page boundary respectively. The units of the values are PDF units of 1/72 inch. | ||
sizeX integer |
The width of the stamp. The stamp’s content will be clipped to this rectangle (width, height). If this is not specified or either the width or the height are zero, the respective size is calculated to fit content. | ||
sizeY integer |
The height of the stamp. The stamp’s content will be clipped to this rectangle (width, height). If this is not specified or either the width or the height are zero, the respective size is calculated to fit content. | ||
rotate double |
Clockwise rotation of the stamp [degree]. | ||
autoorientation boolean |
false | Orientation of Stamp. - true: detects orientation (portrait and landscape) of page automatically and treats landscape page as a 90° rotated portrait. Useful to apply stamps to “long” or “short” edge of page. - false: always positions stamps as defined by stamp attributes. |
|
alpha double |
1.0 | The opacity of the entire stamp. 1.0 for fully opaque, 0.0 for fully transparent. The PDF/A-1 standard does not allow transparency. Therefore, for PDF/A-1 conforming input files you must not set alpha to a value other than 1.0. | |
scale string |
"relToA4" | "relToA4eft" | Scale of stamp. Scales the stamp relative to the page size. For example, make stamp half as large on a A5 and twice as large on a A3 page as specified. |
alignX string |
"left" | "left", "center", "right" | Align the stamp with the page. Overrules relativePosX. |
alignY string |
"bottom" | "top", "middle", "bottom" | Align the stamp with the page. Overrules relativePosY. |
stampType string |
"annotation" | "annotation": The stamp is added to the page as a stamp annotation. Creating or modifying stamps of this type will not invalidate existing signatures of the input document. While it is not easy to remove stamps of this type, it is possible to print a document without annotations. "foreground": The stamp is added to the foreground of the page content. Creating or modifying stamps of this type will invalidate all existing signatures of the input document. It is not easy to remove stamps of this type nor can the document be printed without them. "background": The stamp is added to the background of the page content. Creating or modifying stamps of this type will invalidate all existing signatures of the input document. It is not easy to remove stamps of this type nor can the document be printed without them. Note that stamps placed this way can be hidden when pages contain a non-transparent background. In these cases, you may rather want to put the stamps in the foreground, but apply alpha transparency to achieve a result with existing content not covered completely. |
The type of the stamp. |
text Text |
Text stamp. | ||
image Image |
Image stamp. | ||
customProperties [ KeyValuePair[String, String] ] |
List of additional key-value pairs of properties. (Found in the Pdf-Tools documentation v4.8.) |
StampRes
Name | Description |
---|---|
document Document |
Stamped Document. |
Document
Name | Description |
---|---|
jobId string |
JobId of Documents WorkingSet. |
documentId string |
DocumentId |
name string |
Filename inlcuding filetype. |
docStatus string |
Status of the Document, e.g. Stamped. |
pages [ Page ] |
Description of pages. |
docData [ byte ] |
Document bytes. |
docMetadata DocMetadata |
Document metadata such as title, pageCount et al. |
docLogs DocLog |
Logging information about the request, e.g. timestamp. |
notification Notification |
Notification through Online WebHook. |
Page
Name | Description |
---|---|
documentId string |
Globally unique Id. |
pageId string |
Globally unique Id. |
pageNumber integer |
PageNumber, starting with 1. |
rotate double |
By how much the page was rotated from its original orientation. |
thumbnail byte |
Thumbnail representing this particular page. |
sourceDocumentId string |
Id of the document it was created from, e.g. in case of an extraction, the result's sourceDocumentId is the Id of the PDF the pages have been extracted from. |
sourcePageNumber integer |
Page number of the original page in the original document, e.g. let's assume document B consists of page number 4 of document A (extraction). Thus, document B's only page's sourcePageNumber is number 4. |
DocMetadata
Name | Description |
---|---|
title string |
Title of document. |
subject string |
Subject of document. |
pageCount long required |
Number of pages. |
size long required |
Number bytes of the document. |
isEncrypted boolean required |
IsEncrypted |
pdfCompliance string |
PdcCompliance, e.g. PDF/A. |
isSigned boolean required |
IsSigned |
uploadedMimeType string |
UploadedMimeType, e.g. application/bson. |
uploadedFileSize long required |
UploadedFileSize |
DocLog
Name | Supported Values | Description |
---|---|---|
messageType string |
MessageType, e.g. PdfALog. | |
message string |
Message itself, e.g. a warning. | |
timestamp dateTime |
Timestamp | |
docLogLevel string |
"verbose", "info", "warning", "error", "timing" | Type of message. |
durationMilliseconds long |
Timing for requested log information [ms]. |
Notification
Name | Description |
---|---|
getNotification boolean |
Run execution asynchronously, get notified over Online WebHook. |
connectionId string |
Will be used for Online WebHook. |
PdfFont
Name | Description |
---|---|
name string |
Name of font. |
fontContent [ byte ] |
Font Description. |
PageSelection
Name | Default | Supported Values | Description |
---|---|---|---|
pageNrs [integer] |
The numbers of the pages the action is applied to. PageNrs overruels PageIds and PageSequence. | ||
pageIds [string] |
The Ids of the pages the action is applied to. PageIds overrules the PageSequence. | ||
pageSequence string |
"all" | "all", "first", "last", "odd", "even", "notFirst", "notLast" | Specifies what pages the action is applied to. |
CustomCMSConfig
Name | Default |
---|---|
white RGBSet |
0.996078, 0.996078, 0.996078 |
c RGBSet |
0.000000, 0.686275, 0.937255 |
m RGBSet |
0.925490, 0.149020, 0.560784 |
y RGBSet |
1.000000, 0.949020, 0.066667 |
k RGBSet |
0.215686, 0.203922, 0.207843 |
cm RGBSet |
0.243137, 0.247059, 0.584314 |
cy RGBSet |
0.000000, 0.658824, 0.349020 |
ck RGBSet |
0.066667, 0.176471, 0.215686 |
my RGBSet |
0.929412, 0.196078, 0.215686 |
mk RGBSet |
0.215686, 0.101961, 0.141176 |
yk RGBSet |
0.200000, 0.196078, 0.125490 |
cmy RGBSet |
0.266667, 0.266667, 0.274510 |
cmk RGBSet |
0.133333, 0.098039, 0.160784 |
cyk RGBSet |
0.074510, 0.180392, 0.133333 |
myk RGBSet |
0.215686, 0.121569, 0.113725 |
cmyk RGBSet |
0.125490, 0.121569, 0.121569 |
RGBSet
Name |
---|
red integer |
green integer |
blue integer |
Text
Name | Default | Supported Values | Description |
---|---|---|---|
format boolean |
false | Whether or not to enable formatting of variable text, such as the current date or the number of pages. | |
size integer |
The font size in points, e.g. 12. If set to 0, the size is chosen such that text fits stamp size. | ||
font string |
The TrueType name of the font, e.g. "Arial" or "Times New Roman,Bold", or a complete path to the font, e.g. C:/Windows/Fonts/Arial.ttf. If the name is used, the respective font must be available in any of the font directories. | ||
color Color |
The color as RGB value, where all values must be in the range from 0 to 1. | ||
fontEncoding string |
"unicode" | "unicode": Only the glyphs used by the stamp are embedded. If the stamp is modified, a new font that includes the new glyph set has to be re-embedded. This setting is recommended for stamps that will not be modified later. "winAnsi": All glyphs required for WinAnsiEncoding are embedded. Hence the text’s characters are limited to this character set. If the content of the stamp is updated, fonts using WinAnsi will be reused. |
This attribute is relevant only, if the stamp will be modified later. The PDF/A standard demands that all used fonts must be embedded in the PDF. Since fonts with many glyphs can be very large in size (>20MB), unused glyphs are removed prior to embedding. This process is called subsetting. The attribute fontencoding controls the subsetting. |
value string required |
Text to be displayed. The text can have embedded HTML. | ||
mode string |
"fill" | "fill": the text is filled. "stroke": the text’s outlines are stroked. |
Rendering mode of the text. |
rotate Rotate |
Text rotation. | ||
translate Translate |
Text translation. | ||
transform Transform |
Text transformation. |
Image
Name | Default | Supported Values | Description |
---|---|---|---|
rectangle Rectangle |
Image position. | ||
imageData byte |
Image data. | ||
imageType string |
Image type. | ||
fileName string |
Image file name. | ||
compression string |
bi-tonal images: "cCITTFax", continuous tone images: "dCT", indexed images: "flate" |
"cCITTFax", "flate", "dCT" | Compression type. |
rotate Rotate |
Image rotation. | ||
translate Translate |
Image translation. | ||
transform Transform |
Image transformation. |
Color
Name |
---|
red integer |
green integer |
blue integer |
Rotate
Name | Description |
---|---|
angle double required |
Counter-clockwise rotation by n degrees, e.g 90. |
originX integer required |
Origin (x-coordinate) of rotation [point]. |
originY integer required |
Origin (y-coordinate) of rotation [point]. |
Translate
Name | Description |
---|---|
offsetX integer required |
Horizontal offset [point]. |
offsetY integer required |
Vertical offset [point]. |
Transform
Name | Description |
---|---|
a integer required |
Scaling of x-Axis. TODO: define all parameters proparly |
b integer required |
Rotation e.g. by x: cos(x) sin(x) -sin(x) cos(x) 0 0. |
c integer required |
Scaling of y-Axis. |
d integer required |
Rotation |
x integer required |
Horizontal offset to the left [point]. |
y integer required |
Vertical offset from the bottom [point]. |
Rectangle
Name | Description |
---|---|
x integer |
Offset to the left page border. |
y integer |
Offset to the bottom of the page. |
width integer |
Width |
height integer |
Height |
KeyValuePair[String, String]
Name |
---|
key string |
value string |
KeyValuePair[String, Object]
Name |
---|
key string |
value object |
Pdf4meClientException
Name | Description |
---|---|
errorMessage string |
Human readable message of the error. |
Pdf4meBackendException
Name | Description |
---|---|
errorMessage string |
Human readable message of the error. |