Use the pdf endpoint to create pages, PDF reports from DLEX files, convert images to PDF, and merge PDFs into a combined PDF.
Use the pdf
endpoint to create simple one-page 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.
The pdf endpoint is much more complex than the other Cloud 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.
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
pdf
endpoint 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 |
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 |
The processing steps and syntax is the same for all four languages.
- Create a new
Pdf
instance and create a new page as aPageInput
instance. - Add page numbers using the
PageNumberingElement
class. - Format the
PageNumberingElement
instance and add them to thePageInput
instance. - Call the
Pdf
instance'sProcess
method and get the returned PDF.
- C# (.NET)
- Java
- Node.js
- PHP
Available on NuGet:
Install-Package DynamicPDF.API
using DynamicPDF.Api;
using DynamicPDF.Api.Elements;
using System;
using System.IO;
namespace PdfExample
{
class Program
{
static void Main(string[] args)
{
Run("DP.xxxx--api-key--xxxx", "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);
}
}
}
Available on NPM:
npm i @dynamicpdf/api
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.xxxx-api-key-xxxx";
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.xxxx--api-key--xxxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
}
}
Available as a Composer package:
composer require dynamicpdf/api
<?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();