PDF Generation API Dokumentation

Diese API wandelt eine angegebene URL in ein PDF um. Sende einen POST-Request an / mit einem JSON-Body.

Erforderliche Parameter

Parameter Beschreibung Typ
apiKey * Dein API-Schlüssel zur Authentifizierung. String
url * Die URL, die in ein PDF umgewandelt werden soll. String

CallbackUrl Variante

Wenn im Request der optionale Parameter callbackUrl angegeben wird, ändert sich das Verhalten der API wie folgt:

CallbackUrl Parameter

Parameter Beschreibung Default Typ Erlaubte Werte
callbackUrl Optional: URL, an die nach PDF-Erstellung (asynchron) eine 20-stellige ID gesendet wird. Wird callbackUrl angegeben, erfolgt keine direkte PDF-Rückgabe. String (URI)

Pagination Variante

Mit der Option substitutePageNumbers wird der PDF-Export in zwei Durchgängen durchgeführt, um ein interaktives Inhaltsverzeichnis zu erzeugen:

Dieses Verfahren ermöglicht eine exakte, formatunabhängige Bestimmung der Seitenzahlen, da die Analyse direkt auf dem generierten PDF basiert. So wird sichergestellt, dass selbst bei wechselnden Formaten oder Orientierungen das Inhaltsverzeichnis korrekt und interaktiv ist.

Sollte kein marker gefunden werden, wird dieser Vorgang in Millisekunden übersprungen und kann üblicherweise deshalb aktiv bleiben.

Pagination Parameter

Parameter Beschreibung Default Typ Erlaubte Werte
substitutePageNumbers Optional: Mit der Option substitutePageNumbers wird der PDF-Export in zwei Durchgängen durchgeführt, um ein interaktives Inhaltsverzeichnis zu erzeugen. Dabei können folgende Modi verwendet werden:

"none": Es erfolgt keine Ersetzung der Seitenzahlen (keine weitere Verarbeitung).
"substitute": Die Seitenzahlen werden in den data-pagetarget-Elementen ersetzt.
"navigatePageOnly": Die Seitenzahlen werden ersetzt und das data-pagetarget-Element wird direkt in einen klickbaren Link umgewandelt.
"navigate": Neben der Ersetzung wird zusätzlich rekursiv nach einem übergeordneten Element gesucht, das das Attribut data-navigation besitzt. Falls vorhanden, wird dieses Element als klickbarer Navigationslink verwendet, während der ursprüngliche Inhalt erhalten bleibt.
"substitute" String none, substitute, navigatePageOnly, navigate

Background Parameter

Parameter Beschreibung Default Typ Erlaubte Werte
backgroundPdfFirst Hintergrund-PDF für die erste Seite. PDF als Base64 encoded oder Download-URL
backgroundPdfLast Hintergrund-PDF für die letzte Seite. Wenn es nur eine Seite gibt und backgroundPdfFirst gesetzt ist, wird diese Option ignoriert. PDF als Base64 encoded oder Download-URL
backgroundPdfDefault Hintergrund-PDF alle Seiten. backgroundPdfFirst und backgroundPdfLast überschreiben dennoch die jeweils erste bzw. letzte Seite, wenn angegeben. PDF als Base64 encoded oder Download-URL

Attachment Parameter

Parameter Beschreibung Default Typ Erlaubte Werte
attachmentPdfs Optional: Ein Array mit den Attachment-PDFs als Base64 encoded oder Download-URL, die in das PDF eingefügt werden sollen. Array

Puppeteer-Parameter

Parameter Beschreibung Default Typ Erlaubte Werte
landscape PDF-Ausrichtung (true = Querformat, false = Hochformat). false Boolean true, false
waitUntil Wann die Navigation als erfolgreich gilt. Mögliche Werte: networkidle0, load, domcontentloaded, networkidle2. networkidle0 String networkidle0, load, domcontentloaded, networkidle2
emulatedMediaType Emulierte Media-Type. Mögliche Werte: screen, print, null. screen String screen, print, null
format Papierformat. Mögliche Werte: letter, legal, tabloid, ledger, a0, a1, a2, a3, a4, a5, a6. - String letter, legal, tabloid, ledger, a0, a1, a2, a3, a4, a5, a6
scale Maßstabfaktor für die PDF-Erzeugung. Number
displayHeaderFooter Ob Kopf- und Fußzeile angezeigt werden sollen. Boolean true, false
headerTemplate HTML-Template für die Kopfzeile. String
footerTemplate HTML-Template für die Fußzeile. String
printBackground Ob Hintergrundgrafiken enthalten sein sollen. false Boolean true, false
omitBackground Ob der weiße Standardhintergrund versteckt werden soll (was transparentes Drucken ermöglicht). false Boolean true, false
pageRanges Bereich der einzubindenden Seiten (z.B. "1-2"). String
width Seitenbreite (z.B. "800mm", 800 (="800px")). String, Int
height Seitenhöhe (z.B. "600mm", 600 (="600px")). String, Int
preferCSSPageSize Ob die im CSS definierte Seitengröße bevorzugt wird. false Boolean true, false
marginTop Oberer Seitenrand (z.B. "10mm"). String
marginRight Rechter Seitenrand (z.B. "15mm"). String
marginBottom Unterer Seitenrand (z.B. "10mm"). String
marginLeft Linker Seitenrand (z.B. "15mm"). String
filename Dateiname für das PDF (Timestamp-basiert, falls nicht angegeben). timestamp-basiert String
args Command Line Argumente für Chrome (Puppeteer). ['--no-sandbox', '--disable-setuid-sandbox'] Array von Strings

Ghostscript-Parameter

Parameter Notizen Default screen printer prepress Typ Erlaubte Werte
gs_option_set Bestimmt die Standardeinstellungen für Ghostscript im Allgemeinen. "screen" macht backgroundPdf Optionen nichtig. String default, screen, printer, prepress
gs_resolution Setzt die Auflösung für Musterfüllungen und Bitmap-Konvertierung von Schriften. Number z.B. 300
gs_ProcessColorModel Setzt den Farbraum für device-dependent Farben im Output. Erlaubte Werte: /DeviceGray, /DeviceRGB, /DeviceCMYK. /DeviceRGB /DeviceRGB /DeviceRGB /DeviceRGB String /DeviceGray, /DeviceRGB, /DeviceCMYK
gs_ASCII85EncodePages false = = = Boolean true, false
gs_AlwaysEmbed [] = = = Array Array von Strings
gs_AntiAliasColorImages (0) false = = = Boolean true, false
gs_AntiAliasGrayImages (0) false = = = Boolean true, false
gs_AntiAliasMonoImages (0) false = = = Boolean true, false
gs_AutoFilterColorImages (1) true = = = Boolean true, false
gs_AutoFilterGrayImages (1) true = = = Boolean true, false
gs_AutoPositionEPSFiles (0) true = = = Boolean true, false
gs_AutoRotatePages /PageByPage /PageByPage /None /None String /None, /PageByPage, /All
gs_Binding (0) /Left = = = String /Left
gs_CalCMYKProfile (0) () = = = String
gs_CalGrayProfile (0) () = = = String
gs_CalRGBProfile (0) () = = = String
gs_CannotEmbedFontPolicy (0) /Warning /Warning /Warning /Error String /Warning, /Error
gs_ColorACSImageDict Notiz 7 Notiz 7 Notiz 7 Notiz 8 Notiz 9 String
gs_ColorConversionStrategy (0,6) /LeaveColorUnchanged /sRGB /UseDeviceIndependentColor /LeaveColorUnchanged String /LeaveColorUnchanged, /sRGB, /UseDeviceIndependentColor
gs_ColorImageDepth -1 = = = Number
gs_ColorImageDict Notiz 7 = = = String
gs_ColorImageFilter /DCTEncode = = = String /DCTEncode
gs_ColorImageDownsampleThreshold 1.5 = = = Number
gs_ColorImageDownsampleType (3) /Subsample /Average /Bicubic /Bicubic String /Subsample, /Average, /Bicubic
gs_ColorImageResolution 72 72 300 300 Number z.B. 72, 300
gs_CompatibilityLevel 1.3 1.2 1.3 1.3 Number
gs_CompressPages true = = = Boolean true, false
gs_ConvertCMYKImagesToRGB true = = = Boolean true, false
gs_ConvertImagesToIndexed (0) true = = = Boolean true, false
gs_CoreDistVersion 4000 = = = Number
gs_CreateJobTicket (0) false false true true Boolean true, false
gs_DefaultRenderingIntent /Default = = = String /Default
gs_DetectBlends (0) true = = = Boolean true, false
gs_DoThumbnails (0) false false false true Boolean true, false
gs_DownsampleColorImages false true false false Boolean true, false
gs_DownsampleGrayImages false true false false Boolean true, false
gs_DownsampleMonoImages false true false false Boolean true, false
gs_EmbedAllFonts true false true true Boolean true, false
gs_EmitDSCWarnings (0) false = = = Boolean true, false
gs_EncodeColorImages true = = = Boolean true, false
gs_EncodeGrayImages true = = = Boolean true, false
gs_EncodeMonoImages true = = = Boolean true, false
gs_EndPage (0) -1 = = = Number
gs_GrayACSImageDict Notiz 7 Notiz 7 Notiz 7 Notiz 8 = String
gs_GrayImageDepth -1 = = = Number
gs_GrayImageDict Notiz 7 = = = String
gs_GrayImageDownsampleThreshold 1.5 = = = Number
gs_GrayImageDownsampleType (3) /Subsample /Average /Bicubic /Bicubic String /Subsample, /Average, /Bicubic
gs_GrayImageFilter /DCTEncode = = = String /DCTEncode
gs_GrayImageResolution 72 72 300 300 Number z.B. 72, 300
gs_ImageMemory (0) 500000 = = = Number
gs_LockDistillerParams false = = = Boolean true, false
gs_LZWEncodePages (2) false = = = Boolean true, false
gs_MaxSubsetPct 100 = = = Number
gs_MonoImageDepth -1 = = = Number
gs_MonoImageDict <> = = = String
gs_MonoImageDownsampleThreshold 1.5 = = = Number
gs_MonoImageDownsampleType /Subsample /Average /Bicubic /Bicubic String /Subsample, /Average, /Bicubic
gs_MonoImageFilter /CCITTFaxEncode = = = String /CCITTFaxEncode
gs_MonoImageResolution 300 300 1200 1200 Number z.B. 300, 1200
gs_NeverEmbed [] = = = Array Array von Strings
gs_OPM 1 = = = Number
gs_Optimize (0,5) false true true true Boolean true, false
gs_ParseDSCComments true = = = Boolean true, false
gs_ParseDSCCommentsForDocInfo true false true true Boolean true, false
gs_PreserveCopyPage (0) true = = = Boolean true, false
gs_PreserveEPSInfo (0) true = = = Boolean true, false
gs_PreserveHalftoneInfo false = = = Boolean true, false
gs_PreserveOPIComments (0) false false true true Boolean true, false
gs_PreserveOverprintSettings false false true true Boolean true, false
gs_sRGBProfile (0) () = = = String
gs_StartPage (0) 1 = = = Number
gs_SubsetFonts true = = = Boolean true, false
gs_TransferFunctionInfo (0) /Preserve = = = String /Preserve
gs_UCRandBGInfo /Remove /Remove /Preserve /Preserve String /Remove, /Preserve
gs_UseFlateCompression true = = = Boolean true, false
gs_UsePrologue (0) false = = = Boolean true, false

Details aus der Ghostscript-Dokumentation

(note 0) This parameter can be set and queried, but currently has no effect.

(note 1) AutoFilterxxxImages doesn't examine the image to decide between JPEG and LZW or Flate compression: it uses JPEG compression if the image has 8 bits per component and does not use an Indexed color space, and LZW or Flate compression otherwise.

(note 2) Because of Unisys's threats regarding the Welch patent, ps2pdf cannot actually use LZW compression: instead, it treats all requests for LZW compression as calling for Flate compression if UseFlateCompression is true and CompatibilityLevel >= 1.2, and ignores them otherwise.

(note 3) The xxxDownsampleType parameters can also have the value /Bicubic (a Distiller 4 feature), which is currently treated as equivalent to /Average.

(note 4) Currently, the transfer function is always applied. If the corresponding parameter is set to /Preserve, the function setting is also copied into the PDF file.

(note 5) Optimization (linearization) is implemented with a separate program, pdfopt input.pdf output.pdf; the Optimize parameter has no effect.

(note 6) Currently, colors for images and shadings are left in the color space specified in the PostScript input, except for ConvertCMYKImagesToRGB; the current color in the graphics state (used for fill, stroke, text, and imagemask) is always converted to the color space specified by the current value of ProcessColorModel. The intended behavior is the same as for Acrobat Distiller, except that if ColorConversionStrategy is set to /UseDeviceDependentColor, colors are converted to the color space specified by ProcessColorModel rather than always to /DeviceRGB.

(note 7) The default image parameter dictionary is:
    << /QFactor 0.9 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>

(note 8) The printer ACS image parameter dictionary is:
    << /QFactor 0.55 /Blend 1 /HSamples [2 1 1 2] /VSamples [2 1 1 2] >>

(note 9) The prepress ACS image parameter dictionary is:
    << /QFactor 0.25 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>

Limitations:
- ps2pdf will sometimes convert text to high-resolution bitmapped fonts rather than to embedded outline fonts. This occurs for Type 3, CIDFontType 1, or CIDFontType 4 fonts, or Type 0 fonts referencing these; it may also occur with fonts using non-standard encodings.
- The PDF output always represents text and graphics colors in DeviceGray or DeviceRGB (or DeviceCMYK if ProcessColorModel is /DeviceCMYK); all other color spaces are converted.
- ps2pdf may convert PostScript constructs to lower-level ones even if higher-level constructs are available (e.g., using charpath for clipping), affecting performance.
- Some PostScript files (e.g., from HIGZ) may trigger a limitcheck error due to extremely large coordinates; reducing the internal resolution with -r (e.g., -r300) may help.
- ps2pdf ignores certain PDF 1.3 pdfmarks related to document structure.
- ps2pdf currently has very limited support for PDF 1.4 transparency features.
- Known problems include issues with saving/restoring Distiller parameters and potential crashes if CompressPages is changed after marks are made.
- Incremental downloading of Type 1 fonts may result in embedded fonts missing FontDescriptor information, potentially causing crashes in Acrobat Reader 4 or incorrect spacing.
  

Beispiel

Ein typischer JSON-Body für einen POST-Request. Im Beispiel werden nur Werte gesetzt, die von den Standardwerten abweichen.

{
  "apiKey": "YOUR_API_KEY",
  "url": "https://example.com",
  "callbackUrl": "https://your-callback-url.com/notify",
  "landscape": true,
  "gs_option_set": "printer",
  "gs_DownsampleColorImages": true,
  "gs_resolution": 300,
  "gs_ProcessColorModel": "/DeviceGray"
}

Weitere Details zu den PDF-Optionen findest du in der Puppeteer PDF Options Dokumentation und zu den Ghostscript-Optionen in der Ghostscript Ps2pdf Options Dokumentation.

* = Erforderlicher Parameter