Documentation

Principle of PDFrePRO

PPDFrePRO provides an online service (RESTful-API) that allows you to design dynamically generated PDFs first in the browser and to store it afterwards as "templates". These templates can contain fixed texts, your company logo, graphic elements, etc., but of course also "placeholders" for your data. After integrating your own application with RESTful-API to PDFrePRO, you create PDF 'on-the-fly' for your customers. Adjustments to a template can then be done online at any time.

 

Getting started

If you want to get started without a lot of documentation, it's easy to register for PDFrePRO for free! Immediately afterwards at least one example template including placeholders and test data for trial and error is available in the personal portal access. If any questions are still open, there is definitely the missing information below.

Register

Where do I begin ?

After registration, you manage all your own templates and placeholders for data in the PDFrePRO PORTAL, as well as your user settings and the scope of your PDFrePRO license. We have created an example template and an example placeholder with test data that you can adapt at any time.

With the PDFrePRO-EDITOR, which you can call directly from the portal, you quickly get creative and design future printouts. Place placeholders for data and fixed texts according to your own wishes.

Finally, the PDFrePRO API provides the technical communication interface for your own application in the form of a RESTful web service. Your own application produces PDFs on-the-fly using the PDFrePRO API. You can also easily integrate PDFrePRO-EDITOR into your own application using the PDFrePRO API!

WYSIWYG editor

The PDFrePRO template editor is your new tool for designing PDF printouts. All you need is an up-to-date desktop browser (from 2017) and work very fast with the help of the documentation:

go to manual

RESTful-API

Easily integrate PDFrePRO into your own application! For this purpose, we provide an example of source code as well as an API docu:

go to API documentation

Code samples

Enclosed code examples for PHP, JAVA, etc., which may be used and modified as a basis for the implementation of the PDFrePRO RESTful API. However, the provided source code is not part of the user agreement but should support you in the integration as best as possible:

 

PHP  JAVA  C#  Python  Node.js 

 

 

PHP

Download our PHP library, including the code samples (for PHP from version 5.6): PDFrePRO-PHP-Library.zip

Step 1: Set the parameters

                        
// Extract the PHP class 'PDFrePRO.class.php' and 'PDFrePROException.class.php' from the downloaded ZIP and put it into
// your class's Directory.

// Set the PDFrePRO-API URL in 'PDFrePRO.class.php' if you want to use a different one than the default:

protected $host = 'https://api.pdfrepro.de';    // Keep it as it is, if you are not 100% sure!

// Now set your personal 'apiKey' and 'sharedKey' in 'my_credentials.inc':

private $apiKey    = '<your-apiKey>';

private $sharedKey = '<your-sharedKey>';

// You'll find these credentials in the PDFrePRO portal in menu 'Manage -> License Key'.
// Klick then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Step 2: Prepare the data to be printed as an array

                        
// Open 'my_first_print.php' and adapt it according to your template-id and data you want to merge into the template:

$templateId = "<your-template-ID>";

// You'll find the 'templateId' in the PDFrePRO portal in menu 'Design -> Templates'.
// Click then on the 'eye symbol' of the template you want to use for print.

// The data to print in this example is located in a JSON file which we now read in
// directly from the filesystem:

$myData=json_decode(file_get_contents("./my_example_data_to_print.json"), true);

// The next variable "printLanguage" defines the language which will be used for templates defined for multiple languages.
// Please use only the languages defined in the corresponding API-KEY. When left empty the first language of the template is used.
// Only language codes in ISO 638-1 are supported.
$printLanguage = 'de';
                        
                    

 

Step 3: Call the methods of our library

                        
// And now produce the PDF with a simple API call using our PHP library:

try
{
    $pdfrepro = new PDFrePRO($apiKey, $sharedKey);

    $pdf = $pdfrepro->getPDF($templateId, $myData, $printLanguage);

    // Finally enable one of the two output methods in this PHP script:

    // Version 1: Forward the PDF as output to your browser.
    //    header('Content-type: application/pdf;base64');
    //    header('Content-Disposition: inline;filename="my_first_print_result.pdf"');
    //    echo $pdf;

    // Version 2: If you want to use the PHP CLI to produce the PDF directly to your filesystem,
    // do it base64-decoded like this:
    //    file_put_contents("/tmp/my_first_print_result.pdf", base64_decode($pdf));
}
catch(Exception $exception)
{
    echo $exception->getMessage();
}
                        
                    

 

 


JAVA

Download our JAVA library, including the code examples: PDFrePRO-JAVA-Library.zip

Step 1: Set the parameters

                        
// Extract the JAVA class 'PDFrePRO.java' and 'PDFrePROException.java' from the downloaded ZIP and put it into your
// class's Directory.

// Set the PDFrePRO-API URL in 'PDFrePRO.java' if you want to use a different one than the default:

private static final String HOST = "https://api.pdfrepro.de";

// Now set your personal 'apiKey' and 'sharedKey' in 'my_first_print.java':

public static String apiKey     = "<your-api-key>";

public static String sharedKey  = "<your-shared-key>";

// You'll find these credentials in the PDFrePRO portal in menu 'Manage -> License Key'.
// Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Step 2: Prepare the data to be printed

                        
// Open 'my_first_print.java' and adapt it according to your template id and data you want to merge into the template:

// One of your prepared templates, into which you want to merge data to produce a PDF.
public static String templateId = "<your-template-ID>";

// Please, refer to the placeholder structure, which you've uploaded, using the PDFrePRO portal, and used in your chosen
// template.
public static JsonValue myData()
{
    // Get content of JSON file.
    Scanner scanner = new Scanner(my_first_print.class.getResourceAsStream("/resources/my_example_data_to_print.json"),
                                  "UTF-8");
    String  json    = "";

    while(scanner.hasNext())
    {
        json += scanner.next();
    }

    // Close scanner.
    scanner.close();

    // Return decoded JSON.
    return Json.JsonDecode(json);
}
                        
                    

 

Step 3: Call the methods of our library

                        
// The "magic" part of PDFrePRO: merge template and (placeholder-)data and get returned a ready-to-use PDF:
try
{
    // Initialize a new instance of the PDFrePRO class with your API key and its associated shared key.
    PDFrePRO pdfrepro = new PDFrePRO(my_first_print.apiKey,
                                     my_first_print.sharedKey);

    // Produce the PDF by merging (placeholder-)data to your prepared template.
    JsonValue pdf = pdfrepro.getPDF(my_first_print.templateId,
                                    my_first_print.myData());

    // Store the PDF as file on your desktop.
    Path path = Files.write(FileSystems.getDefault().getPath(System.getProperty("user.home") + "/Desktop/my_first_print.PDF"),
                            Base64.getDecoder().decode(pdf.getStringValue()));

    // Open the PDF file, if possible.
    if(Desktop.isDesktopSupported())
    {
        Desktop desktop = Desktop.getDesktop();

        if(desktop.isSupported(Desktop.Action.OPEN))
        {
            desktop.open(path.toFile());
        }
    }
}
catch(Exception exception)
{
    // Print any occurring exception.
    System.out.println(exception.toString());
}
                        
                    

 

 


C#

Download our C # examples: PDFrePRO-C#-Examples.zip

Step 1: Set the parameters

                        
// Currently, there is no C# class for using PDFrePRO. Instead, we provide you some code snippets, which show you, how
// you could send requests to PDFrePRO, using C#. There are currently two examples available: one on how to retrieve the
// editor URL of one of your templates; and one on how to print a PDF of one of your templates.

// Set the PDFrePRO-API URL in 'Retrieve_Editor_Url.cs' or 'Print_PDF.cs' if you want to use a different one than the
// default:

private static string host = "https://api.pdfrepro.de";

// Now set your personal 'apiKey' and 'sharedKey' in 'Retrieve_Editor_Url.cs' or 'Print_PDF.cs':

public static string apiKey     = "<your-api-key>";

public static string sharedKey  = "<your-shared-key>";

// You'll find these credentials in the PDFrePRO portal in menu 'Manage -> License Key'.
// Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Step 2: Enter Template ID (and prepare any data to be printed)

                        
// Open 'Retrieve_Editor_Url.cs' or 'Print_PDF.cs' and adapt it according to your template id and data you want to merge
// into the template. In case of 'Retrieve_Editor_Url.cs', you need only to adapt your template id:

// One of your prepared templates, for which you want to print a PDF.
public static string templateId = "<your-template-ID>";

// Please, refer to the placeholder structure, which you've uploaded, using the PDFrePRO portal, and used in your chosen
// template.
public static JObject MyData()
{
    // Get content of JSON file.
    StreamReader   st   = File.OpenText("my_example_data_to_print.json");
    JsonTextReader jtr  = new JsonTextReader(st);
    JObject        json = (JObject)JToken.ReadFrom(jtr);

    // Close streams.
    jtr.Close();
    st.Close();

    // Return decoded JSON.
    return json;
}
                        
                    

 

Step 3: Send request to PDFrePRO

                        
// The "magic" part of PDFrePRO: merge template and (placeholder-)data and get returned a ready-to-use PDF:
try
{
    // Send the request to PDFrePRO-API and get the response.
    JObject response = SendRequest("/v3/templates/" + templateId + "/pdf",
                                   MyData()).Result;

    // Get the PDF.
    string pdf = response.GetValue("data").Value<string>("pdf");

    // Store the PDF as file on your desktop.
    Byte[]     pdfContent = Convert.FromBase64String(pdf);
    string     filePath   = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Path.DirectorySeparatorChar + "my_first_print_result.pdf";
    FileStream fs         = File.Create(filePath);

    fs.Write(pdfContent,
             0,
             pdfContent.Length);
    fs.Close();

    // Open the PDF file, which got just created.
    Process.Start(filePath);
}
catch (Exception exception)
{
    // Print any occurring exception.
    Console.WriteLine("<pre>" + exception.ToString() + "</pre>");
}

// Or retrieve an URL to open your template in the WYSIWYG editor of PDFrePRO:
try
{
    // Send the request to PDFrePRO-API and get the response.
    JObject response = SendRequest("/v3/templates/" + templateId + "/editor-url").Result;

    // Get the editor-url.
    string editorUrl = response.GetValue("data").Value<string>("url");

    // Open the PDFrePRO editor by using the URL.
    Process.Start(editorUrl);
}
catch (Exception exception)
{
    // Print any occurring exception.
    Console.WriteLine("<pre>" + exception.ToString() + "</pre>");
}
                        
                    

 

 


Python

Download our Python examples: PDFrePRO-Python-Examples.zip

Step 1: Set the parameters

                        
# Currently, there is no Python class for using PDFrePRO. Instead, we provide you some code snippets, which show you,
# how you could send requests to PDFrePRO, using Python. There are currently two examples available: one on how to
# retrieve the editor URL of one of your templates; and one on how to print a PDF of one of your templates.

# Note, that these examples have been written in and tested with Python version 3.6.4. Some functionalities may not be
# available in earlier versions; causing them - very probably - to throw some errors. Just adapt the examples to your
# Python version.

# Set the PDFrePRO-API URL in '__init__.py' if you want to use a different one than the default:

host = "https://api.pdfrepro.de"

# Now set your personal 'api_key' and 'shared_key' in 'retrieve_editor_url.py' or 'print_pdf.py':

api_key     = "<your-api-key>"

shared_key  = "<your-shared-key>"

# You'll find these credentials in the PDFrePRO portal in menu 'Manage -> License Key'.
# Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Step 2: Enter Template ID (and prepare any data to be printed)

                        
# Open 'retrieve_editor_url.py' or 'print_pdf.py' and adapt it according to your template id and data you want to merge
# into the template. In case of 'retrieve_editor_url.py', you need only to adapt your template id:

# One of your prepared templates, for which you want to retrieve the editor-url or print a PDF.
template_id = "<your-template-id>"

# Please, refer to the placeholder structure, which you've uploaded, using the PDFrePRO portal, and used in your chosen
# template.
def my_data():
    """The following structure "my_data" represents the data array you want to merge into your PDF document.
    It's normally populated based on your users input or a SQL result.

    The data to print in this example is located in a JSON file which we now read in directly from the
    filesystem:"""

    # Get content of JSON file.
    with open("my_example_data_to_print.json") as file:
        file_content = file.read()

    # Return decoded JSON.
    return json.loads(file_content)
                        
                    

 

Step 3: Send request to PDFrePRO

                        
# The "magic" part of PDFrePRO: merge template and (placeholder-)data and get returned a ready-to-use PDF:
try:
    # Send the request to PDFrePRO-API and get the response.
    response = send_request("/v3/templates/" + template_id + "/pdf", my_data())

    # Get the PDF.
    pdf = response["data"]["pdf"]

    # Store the PDF as file on your desktop.

    # Note, that you may need to set or change "HOMEPATH" variable and / or Desktop directory name, dependent on your
    # operating system.
    file_path = os.path.join(os.environ["HOMEPATH"], "Desktop", "my_first_print_result.pdf")

    with open(file_path, "w+b") as file:
        file.write(b64decode(pdf))

    #Open the PDF file, which got just created.
    os.startfile(file_path)
except Exception as exception:
    # Print any occurring exception.
    print("<pre>" + str(exception) + "</pre>")

# Or retrieve an URL to open your template in the WYSIWYG editor of PDFrePRO:
try:
    # Send the request to PDFrePRO-API and get the response.
    response = send_request("/v3/templates/" + template_id + "/editor-url")

    # Get the editor-url.
    editor_url = response["data"]["url"]

    # Open the PDFrePRO editor by using the URL.
    webbrowser.open(editor_url)
except Exception as exception:
    # Print any occurring exception.
    print("<pre>" + str(exception) + "</pre>")
                        
                    

 

 


Node.js

Download our Python examples: PDFrePRO-Nodejs-Examples.zip

Step 1: Set the parameters

                        
// Currently, there is no Node.js class for using PDFrePRO. Instead, we provide you some code snippets, which show you,
// how you could send requests to PDFrePRO, using Node.js. There are currently two examples available: one on how to
// retrieve the editor URL of one of your templates; and one on how to print a PDF of one of your templates.

// Note, that these examples have been written in and tested with Node.js version v9.11.1. Some functionalities may not
// be available in earlier versions; causing them - very probably - to throw some errors. Just adapt the examples to
// your Node.js version.

// Set the PDFrePRO-API URL in 'my_credentials.js' if you want to use a different one than the default:

global.host = "https://api.pdfrepro.de";

// Now set your personal 'api_key' and 'shared_key' (also in 'my_credentials.js'):

global.api_key     = "<your-api-key>";

global.shared_key  = "<your-shared-key>";

// You'll find these credentials in the PDFrePRO portal in menu 'Manage -> License Key'.
// Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Step 2: Enter Template ID (and prepare any data to be printed)

                        
// Open 'my_credentials.js' and adapt it according to your template id. In case of printing a PDF, you also have to
// adapt your data you want to merge into the template.

// One of your prepared templates, for which you want to retrieve the editor-url or print a PDF.
global.template_id = "<your-template-id>";

// Please, refer to the placeholder structure, which you've uploaded, using the PDFrePRO portal, and used in your chosen
// template.
function my_data() {
    // Get the content of your JSON file.
    var file_content = fs.readFileSync("./my_example_data_to_print.json");

    // Return the decoded JSON.
    return JSON.parse(file_content)
}
                        
                    

 

Step 3: Send request to PDFrePRO

                        
// The "magic" part of PDFrePRO: merge template and (placeholder-)data and get returned a ready-to-use PDF:
try {
    // Send the request to PDFrePRO-API and get the response.
    send_request("/v3/templates/" + template_id + "/pdf", my_data(), function(response) {
        try {
            // Get the PDF.
            var pdf = response["data"]["pdf"];

            // Store the PDF as file on your desktop.
            var buffer    = new Buffer(pdf, "base64");
            var file_path = os.homedir() + path.sep + "Desktop" + path.sep + "my_first_print_result.pdf";

            fs.writeFileSync(file_path, buffer);

            // Get the command for your platform, which opens the PDF in your default PDF viewer. (This example doesn't
            // cover all platforms.)
            var start = ((process.platform === "darwin") ? "open" : ((process.platform === "win32") ? "start" : "xdg-open"));

            // Open the PDF file, which got just created.
            child_process.exec(start + " " + file_path);
        } catch(error) {
            // Print any occurring error.
            console.log("<pre>" + error.toString() + "</pre>")
        }
    });
} catch(error) {
    // Print any occurring error.
    console.log("<pre>" + error.toString() + "</pre>")
}

// Or retrieve an URL to open your template in the WYSIWYG editor of PDFrePRO:
try {
    // Send the request to PDFrePRO-API and get the response.
    send_request("/v3/templates/" + template_id + "/editor-url", function(response) {
        try {
            // Get the editor-url.
            var editor_url = response["data"]["url"];

            // Get the command for your platform, which opens the URL in your default browser. (This example doesn't
            // cover all platforms.)
            var start = ((process.platform === "darwin") ? "open" : ((process.platform === "win32") ? "start" : "xdg-open"));

            // Open the PDFrePRO editor by using the URL.
            child_process.exec(start + " " + editor_url);
        } catch(error) {
            // Print any occurring error.
            console.log("<pre>" + error.toString() + "</pre>")
        }
    });
} catch(error) {
    // Print any occurring error.
    console.log("<pre>" + error.toString() + "</pre>")
}