Documentation · Technical Documentation

PDF Generation Technical Notes

This document describes how the ADP Car Market Hub plugin produces print-optimised vehicle datasheets ("exposés") that visitors can save as PDF using their browser's print dialog.

When to use this document

Read this document if you need to:

  • Customise which fields appear on the printable datasheet.
  • Replace the default QR-code image source with a self-hosted generator.
  • Embed a link to a vehicle's printable datasheet from another page or system.
  • Diagnose missing or incorrect data on the printable page.

Overview

The PDF datasheet is implemented in AS24CI\Pdf_Datasheet. It does not generate a binary PDF on the server. Instead, it renders a standalone HTML page (without the WordPress theme header/footer) optimised for the browser's Print → Save as PDF function.

This approach has two practical implications:

  • The output looks identical regardless of the active theme, because the theme is bypassed.
  • The browser drives the actual PDF rendering. The visitor (or the dealership team) creates the PDF locally; the server only serves HTML.

Trigger and routing

  • The class registers the public query variable as24ci_pdf.
  • A template_redirect action listens for the variable. When present and resolving to a published as24ci_car post, the plugin renders the datasheet and calls exit.
  • The URL helper Pdf_Datasheet::get_datasheet_url( $post_id ) returns home_url( '/?as24ci_pdf=<post_id>' ). Use this helper rather than constructing the URL by hand.

Validation rules:

  • Non-numeric or zero IDs return HTTP 400 with a translated "Invalid vehicle ID" message.
  • Missing post, wrong post type or non-published status returns HTTP 404 with a translated "Vehicle not found or not published" message.

Field selection

Pdf_Datasheet::get_allowed_fields() is the authoritative whitelist of fields that may appear on the datasheet. Any field not in the list is ignored, so administrators cannot show unsupported data by manipulating the saved settings.

Currently allowed fields:

  • title, price, mileage, first_reg, fuel_type, transmission, power, body_type, exterior_color, doors, seats, emission_class, co2, consumption, equipment, description, location, contact.

Defaults are exposed by get_default_settings() and overlaid onto the user's persisted PDF Manager settings, so newly added fields receive a sensible default value.

QR code

Pdf_Datasheet::get_qr_image_url( $target_url ) returns a QR image URL for embedding in the datasheet. The default implementation requests a 180×180 PNG from the public goqr.me service (https://api.qrserver.com/v1/create-qr-code/).

Operational details:

  • A defensive guard returns an empty string if the target URL contains autoscout24. so the QR code never accidentally links to the source listing detail page.
  • The default URL is filterable through as24ci_pdf_qr_image_url. Return an empty string to suppress the QR image entirely, or return your own (self-hosted) URL.

Step by step instructions

To preview a printable datasheet for a vehicle:

  1. Locate the vehicle in the WordPress admin or on the front-end.
  2. Open the URL https://example.com/?as24ci_pdf=<post_id> in a browser.
  3. Use the browser print dialog (Ctrl/Cmd + P) to save the page as a PDF or send it to a printer.

To customise the visible fields:

  1. Open the PDF Manager admin tab.
  2. Toggle the fields and branding options (logo, company, address, phone, etc.).
  3. Save. The settings are persisted in WordPress options and merged with the defaults at render time.

To replace the QR provider with a self-hosted generator:

  1. Add a small mu-plugin or theme snippet that hooks as24ci_pdf_qr_image_url, ignores the default and returns your own URL.
  2. Verify the result in a browser before deploying to production.

Configuration reference

Field whitelist: see get_allowed_fields() above. Default values: see get_default_settings(). The exact list of branding and layout options exposed in the PDF Manager admin tab is maintained server-side. Verify the current options against the PDF Manager screen before publishing customer-facing documentation.

Operational notes

  • The renderer outputs full HTML (including <!DOCTYPE>, <head>, inline styles) and calls exit to stop WordPress from sending its theme. Any plugin that hooks late in template_redirect and writes to the response after this point will not run.
  • Because the PDF is generated client-side by the browser, page numbering, headers/footers and paper size depend on the visitor's print settings, not the plugin.
  • The QR image is fetched by the visitor's browser (or by the print engine), not by the WordPress server. If your privacy policy forbids third-party requests in printable documents, override the QR URL or suppress it entirely via the filter.
  • The endpoint returns a public HTML page; do not embed confidential data in the configurable fields.

Troubleshooting

  • 404 page instead of the datasheet — the post does not exist, is not the as24ci_car post type, or is not publish. Verify the ID and the post status.
  • 400 "Invalid vehicle ID" — the value passed in ?as24ci_pdf= was not a positive integer.
  • Theme styles bleed into the printable page — the renderer bypasses the theme; if you see theme markup, another plugin is intercepting template_redirect before this one or the URL was not detected. Re-check the URL parameter and clear page caches.
  • QR code is missing or broken — the target URL contained autoscout24. (suppressed for safety) or a custom filter returned an empty string. Verify the target URL and the filter implementation.
  • PDF differs between browsers — print rendering varies across browsers and OS. Standardise on one browser/OS for customer-facing exports if precise layout matters.