PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal...
Transcript of PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal...
![Page 1: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/1.jpg)
PDFs in Drupal
Making PDFs work well in Drupal 8Presented by Dan Hansen - Sevaa Group, Inc.
@DanAtSevaa @Sevaa #DrupalConNA
![Page 2: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/2.jpg)
Introduction - Who Am I?
Dan Hansen
Lead Developer at Sevaa Group, Inc.
Worked with Drupal for 7 years
Acquia Certified and generally pretty cool
![Page 3: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/3.jpg)
You Came Here to Hear About PDFs in Drupal
![Page 4: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/4.jpg)
The Importance of PDFs in Drupal
PDFs are universal as a document format, but can feel left behind in support
Previously a closed format
Previously an expensive format
Move to make PDF handling as ubiquitous in web as image handling is.
PDFs in core!
![Page 5: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/5.jpg)
Let’s talk about PDFs
Based on Postscript, a language used to format for printers.
Proprietary format from Adobe in 1993
ISO standardized in 2008 (ISO 32000-1)
Designed to bring together document layout with font embedding and data storage with available
compression.
![Page 6: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/6.jpg)
What Makes PDFs Special?
● Rich Media● Security● Standardization
![Page 7: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/7.jpg)
PDF Rendering Libraries
![Page 8: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/8.jpg)
Print-to-PDF
Important consideration: Do you actually need to generate PDFs in code?
Modern browsers offer effective Print-to-PDF built in, with easy control via print style sheets.
Generate PDFs if:
● You require precision layouts (forms are a good example)
● You need to implement a template
● You need to implement security features
![Page 9: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/9.jpg)
Rendering Libraries: jsPDF
Client-side rendering library
Can be used to render HTML with the addition of html2canvas or rasterizeHTML
https://github.com/MrRio/jsPDF
![Page 10: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/10.jpg)
Rendering Libraries: FPDF
Server-side, 100% PHP based
http://www.fpdf.org/
No updates since 2015
![Page 11: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/11.jpg)
Rendering Libraries: mPDF
Server-side, 100% PHP based
Based on FPDF & HTML2FPDF
Offers improved language and UTF-8 handling
Noted in it’s own docs as slower than the original tools!
https://mpdf.github.io/
![Page 12: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/12.jpg)
Rendering Libraries: TCPDF
Server-side, 100% PHP based
New version being worked on, which means the current functional version is considered ‘obsolete’ and
will no longer get updates.
Old version does not work on PHP 7.2+ without patching
https://github.com/tecnickcom/tc-lib-pdf/issues/18
https://github.com/tecnickcom/tcpdf
![Page 13: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/13.jpg)
Rendering Libraries: FPDI
Server-side bonus library for FPDF; Also works for TCPDF
Allows the use of PDF files as templates (kind of)
An extension library can also encrypt PDFs
https://www.setasign.com/products/fpdi/about/
Builder Beware! Support for versions of PDFs above 1.4 costs money!
![Page 14: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/14.jpg)
Rendering Libraries: DOMPDF
Server-side; 100% PHP Based
Back to active development after a long, static stint in Google Code. Also now cooperates well with
package management solutions like Composer
Powerful and widely-used, but with known issues (Render loop on large tables, no float support)
Only officially supports CSS 2.1 and HTML 5
http://dompdf.github.io/
![Page 15: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/15.jpg)
Rendering Libraries: Wkhtmltopdf
Server-side; Software Binary
Uses an interface like PHP Wkhtmltopdf to interface with Drupal and other PHP applications
Most predictable rendering--uses the WebKit engine
This is more than likely your best option--if you can get it work
![Page 16: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/16.jpg)
Rendering Libraries: PDFtk
Server-side; Software Binary
More of a PDF manipulation tool:
● Add/remove pages
● Combine PDFs
● Fill PDF templates with data
![Page 17: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/17.jpg)
Rendering Libraries: Lightning Round!
● html2ps/html2pdf
● AdobeFOB
● PDFLib
● Zend_Pdf
● XSL:FO
● And Many More!
![Page 18: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/18.jpg)
Drupal PDF Modules
![Page 19: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/19.jpg)
PDF Drupal Modules
Printer, email and PDF versions for Drupal 8 https://www.drupal.org/project/printable
● Stable as of the end of last year
● Relies on PDF API module, which is not stable
● PDF API does not install without older version of DOMPDF
Entity Print https://www.drupal.org/project/entity_print
● Flexible library selection
● No version issues; can use current branches
● Best replacement for old Print module.
![Page 20: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/20.jpg)
PDF Drupal Modules
FillPDF https://www.drupal.org/project/fillpdf
● Fills PDF templates with data
● Uses PDFtk or a Third-Party Service (paid)
● Can GREATLY reduce the overhead of rendering your PDFs
![Page 21: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/21.jpg)
Stupid PDF Tricks
![Page 22: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/22.jpg)
Make a PDF from HTML
Use Entity Print with Wkhtmltopdf or DOMPDF
But what if you don’t want to build based off an entity?
DEMO TIME!
![Page 23: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/23.jpg)
Combine Two PDFs
Use PDFtk and a wrapper like mikehaertl/php-pdftk
DEMO TIME!
![Page 24: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/24.jpg)
Dump a Generated PDF into A File Field
Use Drupal 8’s awesome entity handling
DEMO TIME!
![Page 25: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/25.jpg)
Fill in a PDF Template
Use FillPDF to do this!
Wanna do it programmatically? Use PDFtk and a wrapper like mikehaertl/php-pdftk
DEMO TIME!
![Page 26: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/26.jpg)
Generate a PDF with a Password on It
Leverage FPDI and it’s extensions
DEMO TIME!
![Page 27: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/27.jpg)
Questions?
![Page 28: PDFs in Drupal › sites › default › files › slides › PDFs in Drupa… · PDFs in Drupal Making PDFs work well in Drupal 8 Presented by Dan Hansen - Sevaa Group, Inc. @DanAtSevaa](https://reader035.fdocuments.net/reader035/viewer/2022070802/5f02f2277e708231d406cafe/html5/thumbnails/28.jpg)
Thank You!
@DanAtSevaa @Sevaa #DrupalConNA