Download the PHP package manuxi/sulu-pdf-bundle without Composer
On this page you can find all versions of the php package manuxi/sulu-pdf-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sulu-pdf-bundle
SuluPdfBundle
🇩🇪 Deutsche Version
PDF download for Sulu 3 content. The bundle renders the public page of an article, event or page, reduces it to its content and sets that into a designed PDF layout (logo, brand color, font, page numbers, QR code to the online version, optional company data). Nothing has to be built twice: every block template you already have keeps working, because the PDF is made from the rendered HTML.
How it works
GET /pdf/{resourceKey}/{id}?locale=delooks up the profile for the resource key (articles,events,pages, ...). No profile or PDF switched off: 404.- The public page is rendered through a sub-request.
- The rules of the profile (CSS selectors) pick title, header data, hero image, lead and main content. Scripts, forms, buttons, icons and carousel chrome are dropped, lazy images get their real URL, figures and galleries are rebuilt as tables (dompdf cannot lay out block images inside
figurereliably). - The content is set into
@SuluPdf/document.html.twigand converted with dompdf. Logo, rule and footer with the page count are drawn on every page.
Requirements
- PHP 8.2+, Sulu 3.x
ext-intl,ext-dom
Installation
Register the bundle in config/bundles.php (Symfony Flex does this for you):
Import the route, config/routes/sulu_pdf.yaml:
Link to the PDF in a template:
Configuration
config/packages/sulu_pdf.yaml, all keys are optional:
Paths are absolute or relative to the project directory.
Profiles
A profile says for one kind of content whether a PDF exists, with which options, and where the parts of its page are.
Articles (automatic)
Recommended: the switches in the excerpt tab (excerpt.articles: true, see below). Their default rules match the article templates of the reference theme (.article-main, .article-header, ...), other themes override them as shown above.
Legacy: with manuxi/sulu-article-configuration-bundle 1.4.x (and without excerpt.articles) the profile articles reads that bundle's own switches (tab "Configuration"). Version 2.0 of the article configuration bundle no longer has these fields, so with 2.x use excerpt.articles.
Switch in the excerpt tab (pages, articles, events)
adds a PDF section to the excerpt tab of that content, as its last section (download on/off, image captions, last-modified date, link/QR code, company data; articles also have the author box), and registers the profile (pages, articles, events) that reads these values. The switches use Sulu's own hook for extra excerpt fields (sulu_content.content_excerpt_form), so they are saved in the content's excerpt data: per language, and with the draft/publish workflow like any other content. Only the published version decides whether the download exists.
- Pages have no author box. Without
excerpt.pagesdefine a profile withresource_key: pagesin the config - then every page has a PDF. - Articles: with
excerpt.articlesthe excerpt switches replace the PDF switches of the article configuration bundle (its profile is then not registered). Without it that bundle's tab "Configuration" decides (see above). - Events: with
excerpt.eventsthe excerpt switches decide per event; without it on/off and the options come fromsulu_pdf.profiles.eventsfor all events. Date and venue are printed as header lines from the event's own data (not scraped from the page), the event's last change is used for "last modified".
To show a link only where a PDF exists:
Profiles from config
Every profile with a resource_key in sulu_pdf.profiles offers a PDF for all resources of that key, with the options given there (show_captions, show_author, show_modified, show_online_link, company_data).
Profiles in PHP
Implement Manuxi\SuluPdfBundle\Profile\PdfProfileInterface and tag the service sulu_pdf.profile:
A profile can additionally implement Manuxi\SuluPdfBundle\Profile\PdfMetaProviderInterface (getMeta(string $id, string $locale): array) to print header lines from the content's own data, such as a date or a venue, in front of the entries the meta rule finds.
Rules
CSS selectors; single-part rules are searched inside root, the first match wins.
| Rule | Default | Meaning |
|---|---|---|
root |
body |
container that holds the header data |
title |
h1 |
title (also removed from the content, the layout prints it) |
overline, subtitle, lead |
- | optional header texts (removed from the content when found inside it) |
badges, meta |
- | every match becomes one badge / one meta entry (removed from the content when found inside it) |
hero |
- | container of the hero image (printed once at the top) |
main |
main |
the content; falls back to <main>, then <body> |
gallery |
- | container of a gallery: its pictures are printed in two columns |
author |
- | author box, removed when "author" is switched off |
remove |
- | more elements to drop; adds to the built-in list (nav, footer, scripts, ...) |
exclude_figures |
- | figures that keep their markup |
Company data
The bundle has no company data of its own. Implement Manuxi\SuluPdfBundle\Service\CompanyDataProviderInterface (name, street, zip, city, phone, email, url), for example reading your organisation snippet, and set it as company_data_provider. The option company_data puts it into the footer of every page or into the closing box.
Customizing the layout
Override @SuluPdf/document.html.twig with templates/bundles/SuluPdfBundle/document.html.twig. dompdf understands CSS 2.1 only (no flexbox, grid, custom properties), so the layout is plain on purpose.
Good to know
- The selectors depend on your theme's markup - set the rules per project.
- Images are fetched over HTTP; on local hosts (
localhost,local.*,*.test,*.local) certificate verification is switched off for that. .webpimages are requested as.jpg(dompdf cannot read WebP; Sulu picks the format by URL extension).- The logo must be PNG or JPG.
- Fonts are registered in
%kernel.cache_dir%/sulu_pdfon the first request after a cache clear.
Tests
License
MIT
All versions of sulu-pdf-bundle with dependencies
ext-dom Version *
ext-intl Version *
bacon/bacon-qr-code Version ^3.0
dompdf/dompdf Version ^3.1
doctrine/dbal Version ^3.6 || ^4.0
sulu/sulu Version ^3.0
symfony/css-selector Version ^6.4 || ^7.0
symfony/framework-bundle Version ^6.4 || ^7.0
symfony/string Version ^6.4 || ^7.0
symfony/twig-bundle Version ^6.4 || ^7.0