ZUGFERD via PHP and JS API
Are you interested in integrating our AI-powered online service 7-PDF Invoice Extractor into your web application? Then this page might be of interest!
Use our API to convert simple PDF invoices to the PDF ZUGFeRD format (PDF/A-3 with XML). Ideal for automated invoice processing in ERP, DMS, or web systems.
📦 Sample: PHP-Integration (CLI)
<?php $token = 'YOUR_TOKEN'; // API-Token $apiUrl = 'https://konverter.zugferd-rechnungen.de/api/pdf2zugferd.php'; $inputFile = 'invoice.pdf'; $outputFile = 'ZUGFeRD_invoice.pdf'; // Check input file if (!file_exists($inputFile)) { exit("❌ Error: The input file '{$inputFile}' was not found.\n"); } $cfile = new CURLFile(realpath($inputFile), 'application/pdf', basename($inputFile)); $postFields = [ 'file' => $cfile, 'token' => $token, 'dscheck' => 'yes', //Agree to transfer and data protection 'desiredFilename' => $outputFile ]; $ch = curl_init($apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); $response = curl_exec($ch); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $body = substr($response, $headerSize); $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); curl_close($ch); if (str_contains($contentType, 'application/pdf')) { file_put_contents($outputFile, $body); echo "✅ Stored: {$outputFile}\\n"; } else { echo "❌ Error:\\n" . $body; } ?>
🌐 Example: JavaScript (HTML form with Fetch)
<form id="uploadForm"> <input type="file" name="file" accept="application/pdf" required> <input type="text" name="desiredFilename" value="ZUGFeRD_invoice.pdf"> <button type="submit">Upload</button> </form> <script> document.getElementById('uploadForm').addEventListener('submit', async function(e) { e.preventDefault(); const form = e.target; const fileInput = form.file; const file = fileInput.files[0]; if (!file) { alert('❌ Please select a pdf invoice.'); return; } if (file.type !== 'application/pdf') { alert('❌ Only pdf files are allowed.'); return; } const filename = form.desiredFilename.value || 'ZUGFeRD_invoice.pdf'; const formData = new FormData(); formData.append('file', file); formData.append('token', 'YOUR TOKEN'); formData.append('dscheck', 'yes'); //Agree to transfer and data protection formData.append('desiredFilename', filename); try { const res = await fetch('https://konverter.zugferd-rechnungen.de/api/pdf2zugferd.php', { method: 'POST', body: formData }); if (!res.ok || !res.headers.get('Content-Type')?.includes('application/pdf')) { const text = await res.text(); throw new Error(text); } const blob = await res.blob(); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; a.click(); URL.revokeObjectURL(url); } catch (err) { alert('❌ Error during upload or conversion:\n' + err.message); } }); </script>
Important note: A token in the JS source code is a security risk, especially with publicly accessible JavaScript in the browser. Any user can view the token, so secure the token server-side, for example, with PHP.