Use the pdf endpoint to create pages, PDF reports from DLEX files, convert images to PDF, convert Word documents to PDFs, and merge PDFs into a combined PDF.Use the pdf endpoint to create PDF documents (cover pages for example), create documents/reports using DLEX files, convert images to PDFs, and to merge PDFs into a combined PDF. You can also combined the results from these tasks to merge into a single PDF document.
| PDF Instructions |
|---|
| Instructions Using Client Libraries |
| pdf.instructions - JSON Schema |
The pdf endpoint is much more complex than the other API endpoints. You must understand the pdf endpoint's schema for creating instructions. pdf.instructions - JSON Schema. Understanding the pdf endpoint requires understanding an instructions document, even if you plan on only using one of the client libraries and not calling the REST endpoint directly (Instructions Using Client Libraries).

Figure 1. The pdf endpoint uses an instructions.json document to process one or more input types.
Refer to the following Users Guide page if you need more information illustrating how to call the endpoint directly as a REST call.
- Calling the
pdfendpoint using REST (pdf REST API).
| Language | GitHub Users Guide Project | Class | Location/Namespace/Package |
|---|---|---|---|
| C# | https://github.com/dynamicpdf-api/dotnet-client-examples | Program.cs | namespace PdfExample |
| Go | https://github.com/dynamicpdf-api/go-client-examples | pdf-example.go | go-client-examples |
| Java | https://github.com/dynamicpdf-api/java-client-examples | PdfExample.java | com.dynamicpdf.client.usersguide |
| Node.js | https://github.com/dynamicpdf-api/nodejs-client-examples | PdfExample.js | nodejs-users-guide |
| PHP | https://github.com/dynamicpdf-api/php-client-examples | PdfExample.js | php-client-examples |
| Python | https://github.com/dynamicpdf-api/python-client-examples | PdfExample.py | python-client-examples |
| Ruby | https://github.com/dynamicpdf-api/ruby-client-examples | PdfExample.rb | ruby-client-examples |
Simple Example (page Input)
The following code is a simple example illustrating the pdf endpoint with the page input type. The processing steps and syntax for the page input is the same for all five languages.
- Create a new
Pdfinstance and create a new page as aPageInputinstance. - Add page numbers using the
PageNumberingElementclass. - Format the
PageNumberingElementinstance and add them to thePageInputinstance. - Call the
Pdfinstance'sProcessmethod and get the returned PDF.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
- Ruby
using DynamicPDF.Api;
using DynamicPDF.Api.Elements;
using System;
using System.IO;
namespace PdfExample
{
class Program
{
static void Main(string[] args)
{
Run("DP---api-key---", "C:/temp/dynamicpdf-api-usersguide-examples/");
}
public static void Run(String apiKey, String basePath)
{
Pdf pdf = new Pdf();
pdf.ApiKey = apiKey;
pdf.Author = "John Doe";
pdf.Title = "My Blank PDF Page";
PageInput pageInput = pdf.AddPage(1008, 612);
PageNumberingElement pageNumberingElement = new PageNumberingElement("1", ElementPlacement.TopRight);
pageNumberingElement.Color = RgbColor.Red;
pageNumberingElement.Font = Font.Courier;
pageNumberingElement.FontSize = 24;
pageInput.Elements.Add(pageNumberingElement);
PdfResponse pdfResponse = pdf.Process();
File.WriteAllBytes(basePath + "pdf-example-output.pdf", pdfResponse.Content);
}
}
}
import fs from 'fs';
import {
Pdf,
PageNumberingElement,
ElementPlacement,
RgbColor,
Font
} from "@dynamicpdf/api"
export class PdfExample {
static async Run() {
var basePath = "C:/temp/dynamicpdf-api-usersguide-examples/";
var apiKey = "DP.xxx-api-key-xxx";
var pdf = new Pdf();
pdf.apiKey = apiKey;
var pageInput = pdf.addPage(1008, 612);
var pageNumberingElement = new PageNumberingElement("1", ElementPlacement.TopRight);
pageNumberingElement.color = RgbColor.Red;
pageNumberingElement.font = Font.Courier;
pageNumberingElement.fontSize = 24;
pageInput.elements.push(pageNumberingElement);
var res = await pdf.process();
if (res.isSuccessful) {
var outFile = "nodejs-pdf-example-output.pdf";
var outStream = fs.createWriteStream(outFile);
outStream.write(res.content);
outStream.close();
}
}
}
await PdfExample.Run();
package com.dynamicpdf.api.examples;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.dynamicpdf.api.Font;
import com.dynamicpdf.api.PageInput;
import com.dynamicpdf.api.Pdf;
import com.dynamicpdf.api.PdfResponse;
import com.dynamicpdf.api.RgbColor;
import com.dynamicpdf.api.elements.ElementPlacement;
import com.dynamicpdf.api.elements.PageNumberingElement;
public class PdfExample {
public static void Run(String apiKey, String basePath)
{
Pdf pdf = new Pdf();
pdf.setApiKey(apiKey);
pdf.setAuthor("John Doe");
pdf.setTitle("My Blank PDF Page");
PageInput pageInput = pdf.addPage(1008, 612);
PageNumberingElement pageNumberingElement =
new PageNumberingElement("1", ElementPlacement.TOPRIGHT);
pageNumberingElement.setColor(RgbColor.getRed());
pageNumberingElement.setFont(Font.getCourier());
pageNumberingElement.setFontSize(24);
pageInput.getElements().add(pageNumberingElement);
PdfResponse pdfResponse = pdf.process();
try {
FileUtils.writeByteArrayToFile(new File(basePath + "java-pdf-page-example-output.pdf"), pdfResponse.getContent());
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
PdfExample.Run("DP.xxx-api-key-xxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
}
}
<?php
use DynamicPDF\Api\Elements\PageNumberingElement;
use DynamicPDF\Api\Elements\ElementPlacement;
use DynamicPDF\Api\RgbColor;
use DynamicPDF\Api\Pdf;
use DynamicPDF\Api\Font;
require __DIR__ . '/vendor/autoload.php';
class PdfExample
{
private static string $BasePath = "C:/temp/dynamicpdf-api-samples/extract-text/";
private static string $ApiKey = "DP.xxx-api-key-xxx";
public static function Run()
{
$pdf = new Pdf();
$pdf->ApiKey = PdfExample::$ApiKey;
$pdf->Author = "John Doe";
$pdf->Title = "My Blank PDF Page";
$pageInput = $pdf->AddPage(1008, 612);
$pageNumberingElement = new PageNumberingElement("1", ElementPlacement::TopRight);
$pageNumberingElement->Color = RgbColor::Red();
$pageNumberingElement->Font = Font::Courier();
$pageNumberingElement->FontSize = 24;
array_push($pageInput->Elements, $pageNumberingElement);
$pdfResponse = $pdf->Process();
file_put_contents(PdfExample::$BasePath . "php-pdf-example-output.pdf", $pdfResponse->Content);
}
}
PdfExample::Run();
func main() {
pdfExample := endpoint.NewPdf()
pdfExample.Endpoint.BaseUrl = "https://api.dpdf.io/"
pdfExample.Endpoint.ApiKey = "DP.xxx-api-key-xxx"
pageInput := input.NewPage()
pdfExample.Author = "John Doe"
pdfExample.Title = "My Blank PDF Page"
pageInput.PageHeight = 612
pageInput.PageWidth = 1008
pageNumber := element.NewPageNumberingElement("1", "TopRight", 0, 0 )
pageNumber.SetFontSize(24)
pageNumber.SetFont(font.Courier())
pageColor := color.NewRgbColorDefault().Red()
pageNumber.SetColor(pageColor.Color)
pageInput.Elements = append(pageInput.Elements, pageNumber)
pdfExample.Inputs = append(pdfExample.Inputs, pageInput)
resp := pdfExample.Process()
res := <-resp
if res.IsSuccessful() == true {
os.WriteFile("C:/temp/dynamicpdf-api-samples/pdf-page-example-output.pdf",
res.Content().Bytes(), os.ModeType)
}else {
fmt.Print(res.ErrorJson())
}
}
from dynamicpdf_api.pdf import Pdf
from dynamicpdf_api.rgb_color import RgbColor
from dynamicpdf_api.font import Font
from dynamicpdf_api.elements.element_placement import ElementPlacement
from dynamicpdf_api.elements.page_numbering_element import PageNumberingElement
from Shared import *
def pdf_example(apikey, full_path):
pdf=Pdf()
pdf.api_key=apikey
pdf.author = "John Doe"
pdf.title = "My Blank PDF Page"
inputPage = pdf.add_page(1008, 612)
pageNumberingElement = PageNumberingElement("1", ElementPlacement.TopRight)
pageNumberingElement.color = RgbColor.red()
pageNumberingElement.font = Font.courier()
pageNumberingElement.font_size = 72
inputPage.elements.append(pageNumberingElement)
response = pdf.process()
if response.is_successful:
with open(full_path + "pdf-output-python.pdf", "wb") as output_file:
output_file.write(response.content)
else:
print(response.error_id)
if __name__ == "__main__":
pdf_example(api_key, base_path + "/pdf-example/")
def self.run(apikey, output_path)
pdf = Pdf.new
pdf.api_key = apikey
pdf.author = "John Doe"
pdf.title = "My Blank PDF Page"
page_input = pdf.add_page(1008, 612)
page_numbering = PageNumberingElement.new(
"1",
ElementPlacement::TOP_RIGHT
)
page_numbering.color = RgbColor.red
page_numbering.font(Font.courier)
page_numbering.font_size = 24
page_input.elements.push(page_numbering)
pdf_response = pdf.process
if pdf_response.is_successful
File.open("#{output_path}ruby-pdf-example-output.pdf", "wb") { |file| file.write(pdf_response.content) }
else
puts pdf_response.error_json
end
end
Note the above is a very simple example of using the pdf endpoint with the page input type. Be certain to review the other input types available with the pdf endpoint (Instructions Using Client Libraries).