Dokumentation

Prinzip von PDFrePRO

PDFrePRO stellt einen Online-Service (RESTful-API) zur Verfügung, der es Ihnen ermöglicht, dynamisch zu generierende PDFs zunächst im Browser zu entwerfen und als s. g. "Vorlage" zu speichern. Diese Vorlagen können feststehende Texte, Ihr Firmenlogo, grafische Elemente, etc., aber natürlich auch "Platzhalter" für Ihre Daten enthalten. Nach Anbindung Ihrer eigenen Anwendung mittels RESTful-API an PDFrePRO, erzeugen Sie PDFs 'on-the-fly' für Ihre Kunden. Anpassungen an einer Vorlage können Sie dann jederzeit online selbst erledigen.

 

Schnelleinstieg

Wenn Sie ohne viel Dokumentation sofort loslegen wollen, geht das ganz leicht nach der kostenlosen Registrierung bei PDFrePRO! Danach steht Ihnen im persönlichen Portal-Zugang mindestens eine Beispielvorlage inklusive Platzhalter und Testdaten zum Ausprobieren und Ändern zur Verfügung. Wenn dann noch Fragen offen sind, gibt es weiter unten bestimmt die fehlenden Infos.

Registrieren

Wo fange ich an ?

Nach der Registrierung verwalten Sie im PDFrePRO-PORTAL alle eigenen Vorlagen und Platzhalter für Daten sowie Ihre Benutzer-Einstellungen und den Umfang Ihrer PDFrePRO-Lizenz. Wir haben Ihnen eine Beispiel-Vorlage und einen Beispiel-Platzhalter mit Testdaten angelegt, die Sie jederzeit anpassen können.

Mit dem PDFrePRO-EDITOR, den Sie vom Portal aus direkt aufrufen können, werden Sie schnell kreativ und gestalten zukünftige Printouts. Platzieren Sie Platzhalter für Daten und feststehende Texte nach eigenen Wünschen.

Die PDFrePRO-API schließlich stellt die technische Kommunikations-Schnittstelle für Ihre eigene Anwendung in Form eines RESTful-Webservice zur Verfügung. Ihre eigene Anwendung produziert PDFs dann 'on-the-fly' mittels der PDFrePRO-API. Auch den PDFrePRO-EDITOR können Sie über die PDFrePRO-API problemlos in Ihre eigene Anwendung integrieren!

WYSIWYG-Editor

Der PDFrePRO Vorlagen-Editor ist Ihr neues Werkzeug zum gestalten von PDF-Printouts. Sie benötigen dazu nur einen aktuellen Desktop-Browser (ab 2017) und arbeiten sich mit Hilfe der Doku sehr schnell ein:

zum Handbuch

RESTful-API

PDFrePRO ganz einfach in die eigene Anwendung integrieren! Dazu stellen wir neben Beispiel-Sourcecode auch eine API-Doku zur Verfügung:

zur API Dokumentation

Code-Beispiele

Anbei Code-Beispiele für PHP, JAVA, etc., die als Grundlage für die eigene Implementierung der PDFrePRO-RESTful-API verwendet und verändert werden dürfen. Der bereitgestellte Sourcecode ist jedoch nicht Bestandteil des Nutzungsvertrags sondern soll Sie bei der Integration bestmöglich unterstützen:

 

PHP  JAVA  C#  Python  Node.js 

 

 

PHP

Download unserer PHP-Library, inkl. der Code-Beispiele (für PHP ab Version 5.6): PDFrePRO-PHP-Library.zip

Schritt 1: Setzen der Parameter

                        
// 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 'Verwalten --> Lizenzschlüssel'.
// Klick then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Schritt 2: Zu druckende Daten als Array aufbereiten

                        
// 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 'Gestalten --> Vorlagen'.
// 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';
                        
                    

 

Schritt 3: Die Methoden unserer Library rufen

                        
// 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 unserer JAVA-Library, inkl. der Code-Beispiele: PDFrePRO-JAVA-Library.zip

Schritt 1: Setzen der Parameter

                        
// 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 'Verwalten --> Lizenzschlüssel'.
// Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Schritt 2: Zu druckende Daten aufbereiten

                        
// 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);
}
                        
                    

 

Schritt 3: Die Methoden unserer Library rufen

                        
// 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 unserer C#-Beispiele (für .NET ab Version 4.5): PDFrePRO-C#-Examples.zip

Schritt 1: Setzen der Parameter

                        
// 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 'Verwalten --> Lizenzschlüssel'.
// Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Schritt 2: Template ID eintragen (und ggf. zu druckende Daten aufbereiten)

                        
// 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;
}
                        
                    

 

Schritt 3: Anfrage an PDFrePRO senden

                        
// 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 unserer Python-Beispiele: PDFrePRO-Python-Examples.zip

Schritt 1: Setzen der Parameter

                        
# 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 'Verwalten --> Lizenzschlüssel'.
# Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Schritt 2: Template ID eintragen (und ggf. zu druckende Daten aufbereiten)

                        
# 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)
                        
                    

 

Schritt 3: Anfrage an PDFrePRO senden

                        
# 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 unserer Node.js-Beispiele: PDFrePRO-Nodejs-Examples.zip

Schritt 1: Setzen der Parameter

                        
// 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 'Verwalten --> Lizenzschlüssel'.
// Click then on the 'eye symbol' of the license key you want to use.
                        
                    

 

Schritt 2: Template ID eintragen (und ggf. zu druckende Daten aufbereiten)

                        
// 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)
}
                        
                    

 

Schritt 3: Anfrage an PDFrePRO senden

                        
// 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>")
}