SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Copyright © 2013 Roots nv, Belgium - All rights reserved
iText @ Car-Pass
How to use PDF Templates with iText.
Copyright © 2011 Roots nv, Belgium - All rights reserved
Koen Dehaen
Managing Partner
@ Roots Software since 1997
Car-Pass and Johnson & Johnson
Enterprise Services Architect
!
koen.dehaen@roots.be
Copyright © 2011 Roots nv, Belgium - All rights reserved
Roots Software
Deliver business driven, sustainable and customised solutions
Based on Service Oriented Architecture
Projects managed with an Agile approach
!
Founded in 1994
Antwerp, Belgium
35 associates
Works for Car-Pass, Janssen Pharmaceutica, Johnson & Johnson,
DHL, Achmea, Sanoma Media Belgium, Sapa, Syngenia (GDF
Suez), …
!
www.roots.be
Copyright © 2011 Roots nv, Belgium - All rights reserved
What brings us here?
Our experience with iText (since version 2), iText used to
create simple & complex PDF’s from scratch
re-organise & watermark existing PDF’s
embed QR codes, images, …
complete PDF Templates
directly from the java code, no need for extra tooling
The Car-Pass IS v2 project
Copyright © 2013 Roots nv, Belgium - All rights reserved
how it all started
create a PDF from code
Copyright © 2011 Roots nv, Belgium - All rights reserved
Code - Hello World!
!
Document document = new Document();
PdfWriter.getInstance(document, new
FileOutputStream(“/tmp/hello-world.pdf”));
document.open();
document.add(new Paragraph("Hello World!"));
...
document.close();
!
http://itextpdf.com/book/examples.php
Copyright © 2011 Roots nv, Belgium - All rights reserved
Some real-life examples
Copyright © 2011 Roots nv, Belgium - All rights reserved
Our findings
Advantages
100% java, 100% cross-platform
No external tools/plug-ins required
Full control on the PDF structure in code
Disadvantages
Document layout managed by Developer
Use iText when
your document flow is straight forward
your document structure/layout is stable
a PDF Template is hard to build
Copyright © 2013 Roots nv, Belgium - All rights reserved
topic of today
PDF templates & QR codes
Copyright © 2013 Roots nv, Belgium - All rights reserved
before we start
introduce Car-Pass
Copyright © 2011 Roots nv, Belgium - All rights reserved
The starting point
Average annual registrations of second hand vehicles in
Belgium: 750.000 cars
Odometer Reading fraud was a serious problem in Belgium
> 60.000 new cases a year (estimates based on data Technical Inspection)
Estimated value of the fraud: € 150 – 200 million per year
Consequences
Poses financial risk and subsequent losses, for consumers
Bad image for second hand car salesmen
Distorted competition in the market & unfair practices
Authorities and automotive professional associations joined
efforts to create a legal framework
Copyright © 2011 Roots nv, Belgium - All rights reserved
Car-Pass
A Car-Pass is a legally
required document that a
seller of a used car has to
handover to the buyer.
It shows the history of
odometer readings since its
first registration.
A Car-Pass is delivered to
the seller by the technical
car inspection; who
requests it to Car-Pass vzw
Copyright © 2011 Roots nv, Belgium - All rights reserved
Car-Pass vzw
A non-profit organization authorized by Royal Decree
Founded in 2006
To manage the central database with the odometer readings
To deal effectively with odometer fraud
Copyright © 2011 Roots nv, Belgium - All rights reserved
Statistics
Since 2006
140.226.468 Odometers
readings
19.483.281 cars
In 2013
777.790 Car-Pass certificates
created (+- 500 / hour)
14.676.983 Odometer readings
6.143.554 vehicles are active.
source: http://www.car-pass.be/nl/docs/
2013_Jaarverslag_NL_final.pdf
Copyright © 2011 Roots nv, Belgium - All rights reserved
Car-Pass IS v2 project
Complete rebuild of the Car-Pass IS v1 platform
Keeping into account
performance
maintainability
scalability
traceability
security
Everything in 1 year
Copyright © 2011 Roots nv, Belgium - All rights reserved
Document (PDF tool) requirements
Fast & reliable tool to generate Car-Pass certificates & other PDF
documents
Based on Templates adjustable by the End-User
Ensure a small footprint
Improve customers experience
Transparant & affordable license
Copyright © 2011 Roots nv, Belgium - All rights reserved
iText: a perfect fit
Java has no support for PDF’s
Compared tools/suites/platforms vs API’s
iText, due to
Lightweight
Full control on PDF structure (helps to manage footprint)
Ability to manage PDF Templates with Acrobat Pro
Scalable, as it easily integrates in a SOA (even OSGI friendly)
Support for QR codes
Speed (under 90 ms / Car-Pass Certificate instead of 900 ms)
Our track record
Copyright © 2011 Roots nv, Belgium - All rights reserved
time for action
Copyright © 2011 Roots nv, Belgium - All rights reserved
Car-Pass Template
Copyright © 2011 Roots nv, Belgium - All rights reserved
Code - Complete Fields with data
try (
FileInputStream is = new FileInputStream(pdfTemplate);
FileOutputStream os = new FileOutputStream(completedCarPassPDF)
) {
PdfReader pdfReader = new PdfReader(is);
PdfStamper stamper = new PdfStamper(pdfReader, os);
AcroFields acroFields = stamper.getAcroFields();
for ( Map.Entry<String, String> entry : model.entrySet() ) {
acroFields.setField ( entry.getKey(), entry.getValue() );
}
stamper.setFormFlattening(true);
stamper.close();
pdfReader.close();
}
Copyright © 2011 Roots nv, Belgium - All rights reserved
Code - From Object to Key-Value pairs
Map<String, String> model = BeanUtils.recursiveDescribe ( carPass, "car-pass" );
http://stackoverflow.com/questions/6133660/recursive-beanutils-describe
model = car-pass.certificateNumber = 0782-7851-9342
car-pass.vin = VF154PB5VXA1138BB
car-pass.make = Renault Megane
car-pass.price = 7,00 EUR
car-pass.firstUse = 22/12/1981
car-pass.firstRegistrationBe = 22/12/1981
car-pass.validUntil = 01/02/2007
car-pass.odometerReadings[0].date = 01/12/2006
car-pass.odometerReadings[0].value = 185643
car-pass.odometerReadings[1].date = 16/04/2006
car-pass.odometerReadings[1].value = 173459
…
Copyright © 2011 Roots nv, Belgium - All rights reserved
Code - QR Code
BarcodeQRCode qrcode = new BarcodeQRCode("https://ws.car-pass.be/verify/" +
carPass.getCertificateNumber(), 160, 160, null);
!
Image image = qrcode.getImage();
image.setAbsolutePosition(430f, 650f);
PdfContentByte content = stamper.getOverContent(pdfReader.getNumberOfPages());
content.addImage(image);
!
!
Copyright © 2011 Roots nv, Belgium - All rights reserved
Code - Keeping it small
PdfDictionary drdict =
reader.getCatalog().getAsDict(PdfName.ACROFORM).getAsDict(PdfName.DR);
PdfDictionary drfontdict = drdict.getAsDict(PdfName.FONT);
for (PdfName key : new HashSet<PdfName>(drfontdict.getKeys())) {
drfontdict.remove(key);
}
PdfArray pages =
reader.getCatalog().getAsDict(PdfName.PAGES).getAsArray(PdfName.KIDS);
for (int i = 0; i < pages.size(); i++) {
PdfDictionary page = pages.getAsDict(i);
PdfArray annots = page.getAsArray(PdfName.ANNOTS);
for (int j = 0; j < annots.size(); j++) {
PdfDictionary annot = annots.getAsDict(j);
PdfName itvalue = annot.getAsName(new PdfName("IT"));
if (new PdfName("FreeTextTypewriter").equals(itvalue)) {
annot.put(new PdfName("IT"), new PdfName("FreeTextTypeWriter"));
}
}
}
Copyright © 2011 Roots nv, Belgium - All rights reserved
iText RUPS
http://itextpdf.com/product/itext_rups
Copyright © 2013 Roots nv, Belgium - All rights reserved
seeing, is believing
Copyright © 2011 Roots nv, Belgium - All rights reserved
www.roots.be
!
koen.dehaen@roots.be
!
github.com/koendehaen/
itext_summit_pdf_templates
Q&A

Contenu connexe

Plus de iText Group nv

PDF made easy with iText 7
PDF made easy with iText 7PDF made easy with iText 7
PDF made easy with iText 7iText Group nv
 
Start-ups: the tortoise and the hare
Start-ups: the tortoise and the hareStart-ups: the tortoise and the hare
Start-ups: the tortoise and the hareiText Group nv
 
IANAL: what developers should know about IP and Legal
IANAL: what developers should know about IP and LegalIANAL: what developers should know about IP and Legal
IANAL: what developers should know about IP and LegaliText Group nv
 
Digital Signatures in the Cloud: A B2C Case Study
Digital Signatures in the Cloud: A B2C Case StudyDigital Signatures in the Cloud: A B2C Case Study
Digital Signatures in the Cloud: A B2C Case StudyiText Group nv
 
Digital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDFDigital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDFiText Group nv
 
PDF is dead. Long live PDF... with Java!
PDF is dead. Long live PDF... with Java!PDF is dead. Long live PDF... with Java!
PDF is dead. Long live PDF... with Java!iText Group nv
 
Digital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDFDigital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDFiText Group nv
 
iText Summit 2014: Talk: iText throughout the document life cycle
iText Summit 2014: Talk: iText throughout the document life cycleiText Summit 2014: Talk: iText throughout the document life cycle
iText Summit 2014: Talk: iText throughout the document life cycleiText Group nv
 
iText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText Group nv
 
iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...
iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...
iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...iText Group nv
 
The XML Forms Architecture
The XML Forms ArchitectureThe XML Forms Architecture
The XML Forms ArchitectureiText Group nv
 
Damn, the new generation kids are getting iPads in Highschool!
Damn, the new generation kids are getting iPads in Highschool!Damn, the new generation kids are getting iPads in Highschool!
Damn, the new generation kids are getting iPads in Highschool!iText Group nv
 
PAdES signatures in iText and the road ahead
PAdES signatures in iText and the road aheadPAdES signatures in iText and the road ahead
PAdES signatures in iText and the road aheadiText Group nv
 
Best practices in Certifying and Signing PDFs
Best practices in Certifying and Signing PDFsBest practices in Certifying and Signing PDFs
Best practices in Certifying and Signing PDFsiText Group nv
 
Choosing the iText Solution that is right for you: Community or Commercial ed...
Choosing the iText Solution that is right for you: Community or Commercial ed...Choosing the iText Solution that is right for you: Community or Commercial ed...
Choosing the iText Solution that is right for you: Community or Commercial ed...iText Group nv
 
The importance of standards
The importance of standardsThe importance of standards
The importance of standardsiText Group nv
 

Plus de iText Group nv (17)

PDF made easy with iText 7
PDF made easy with iText 7PDF made easy with iText 7
PDF made easy with iText 7
 
Start-ups: the tortoise and the hare
Start-ups: the tortoise and the hareStart-ups: the tortoise and the hare
Start-ups: the tortoise and the hare
 
IANAL: what developers should know about IP and Legal
IANAL: what developers should know about IP and LegalIANAL: what developers should know about IP and Legal
IANAL: what developers should know about IP and Legal
 
Digital Signatures in the Cloud: A B2C Case Study
Digital Signatures in the Cloud: A B2C Case StudyDigital Signatures in the Cloud: A B2C Case Study
Digital Signatures in the Cloud: A B2C Case Study
 
Digital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDFDigital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDF
 
ZUGFeRD: an overview
ZUGFeRD: an overviewZUGFeRD: an overview
ZUGFeRD: an overview
 
PDF is dead. Long live PDF... with Java!
PDF is dead. Long live PDF... with Java!PDF is dead. Long live PDF... with Java!
PDF is dead. Long live PDF... with Java!
 
Digital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDFDigital Signatures: how it's done in PDF
Digital Signatures: how it's done in PDF
 
iText Summit 2014: Talk: iText throughout the document life cycle
iText Summit 2014: Talk: iText throughout the document life cycleiText Summit 2014: Talk: iText throughout the document life cycle
iText Summit 2014: Talk: iText throughout the document life cycle
 
iText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText Summit 2014: Keynote talk
iText Summit 2014: Keynote talk
 
iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...
iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...
iText Summit 2014: Talk: eGriffie and JustX, introducing digital documents at...
 
The XML Forms Architecture
The XML Forms ArchitectureThe XML Forms Architecture
The XML Forms Architecture
 
Damn, the new generation kids are getting iPads in Highschool!
Damn, the new generation kids are getting iPads in Highschool!Damn, the new generation kids are getting iPads in Highschool!
Damn, the new generation kids are getting iPads in Highschool!
 
PAdES signatures in iText and the road ahead
PAdES signatures in iText and the road aheadPAdES signatures in iText and the road ahead
PAdES signatures in iText and the road ahead
 
Best practices in Certifying and Signing PDFs
Best practices in Certifying and Signing PDFsBest practices in Certifying and Signing PDFs
Best practices in Certifying and Signing PDFs
 
Choosing the iText Solution that is right for you: Community or Commercial ed...
Choosing the iText Solution that is right for you: Community or Commercial ed...Choosing the iText Solution that is right for you: Community or Commercial ed...
Choosing the iText Solution that is right for you: Community or Commercial ed...
 
The importance of standards
The importance of standardsThe importance of standards
The importance of standards
 

Dernier

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Dernier (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

iText Summit 2014: Talk: How to use PDF Templates with iText

  • 1. Copyright © 2013 Roots nv, Belgium - All rights reserved iText @ Car-Pass How to use PDF Templates with iText.
  • 2. Copyright © 2011 Roots nv, Belgium - All rights reserved Koen Dehaen Managing Partner @ Roots Software since 1997 Car-Pass and Johnson & Johnson Enterprise Services Architect ! koen.dehaen@roots.be
  • 3. Copyright © 2011 Roots nv, Belgium - All rights reserved Roots Software Deliver business driven, sustainable and customised solutions Based on Service Oriented Architecture Projects managed with an Agile approach ! Founded in 1994 Antwerp, Belgium 35 associates Works for Car-Pass, Janssen Pharmaceutica, Johnson & Johnson, DHL, Achmea, Sanoma Media Belgium, Sapa, Syngenia (GDF Suez), … ! www.roots.be
  • 4. Copyright © 2011 Roots nv, Belgium - All rights reserved What brings us here? Our experience with iText (since version 2), iText used to create simple & complex PDF’s from scratch re-organise & watermark existing PDF’s embed QR codes, images, … complete PDF Templates directly from the java code, no need for extra tooling The Car-Pass IS v2 project
  • 5. Copyright © 2013 Roots nv, Belgium - All rights reserved how it all started create a PDF from code
  • 6. Copyright © 2011 Roots nv, Belgium - All rights reserved Code - Hello World! ! Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(“/tmp/hello-world.pdf”)); document.open(); document.add(new Paragraph("Hello World!")); ... document.close(); ! http://itextpdf.com/book/examples.php
  • 7. Copyright © 2011 Roots nv, Belgium - All rights reserved Some real-life examples
  • 8. Copyright © 2011 Roots nv, Belgium - All rights reserved Our findings Advantages 100% java, 100% cross-platform No external tools/plug-ins required Full control on the PDF structure in code Disadvantages Document layout managed by Developer Use iText when your document flow is straight forward your document structure/layout is stable a PDF Template is hard to build
  • 9. Copyright © 2013 Roots nv, Belgium - All rights reserved topic of today PDF templates & QR codes
  • 10. Copyright © 2013 Roots nv, Belgium - All rights reserved before we start introduce Car-Pass
  • 11. Copyright © 2011 Roots nv, Belgium - All rights reserved The starting point Average annual registrations of second hand vehicles in Belgium: 750.000 cars Odometer Reading fraud was a serious problem in Belgium > 60.000 new cases a year (estimates based on data Technical Inspection) Estimated value of the fraud: € 150 – 200 million per year Consequences Poses financial risk and subsequent losses, for consumers Bad image for second hand car salesmen Distorted competition in the market & unfair practices Authorities and automotive professional associations joined efforts to create a legal framework
  • 12. Copyright © 2011 Roots nv, Belgium - All rights reserved Car-Pass A Car-Pass is a legally required document that a seller of a used car has to handover to the buyer. It shows the history of odometer readings since its first registration. A Car-Pass is delivered to the seller by the technical car inspection; who requests it to Car-Pass vzw
  • 13. Copyright © 2011 Roots nv, Belgium - All rights reserved Car-Pass vzw A non-profit organization authorized by Royal Decree Founded in 2006 To manage the central database with the odometer readings To deal effectively with odometer fraud
  • 14. Copyright © 2011 Roots nv, Belgium - All rights reserved Statistics Since 2006 140.226.468 Odometers readings 19.483.281 cars In 2013 777.790 Car-Pass certificates created (+- 500 / hour) 14.676.983 Odometer readings 6.143.554 vehicles are active. source: http://www.car-pass.be/nl/docs/ 2013_Jaarverslag_NL_final.pdf
  • 15. Copyright © 2011 Roots nv, Belgium - All rights reserved Car-Pass IS v2 project Complete rebuild of the Car-Pass IS v1 platform Keeping into account performance maintainability scalability traceability security Everything in 1 year
  • 16. Copyright © 2011 Roots nv, Belgium - All rights reserved Document (PDF tool) requirements Fast & reliable tool to generate Car-Pass certificates & other PDF documents Based on Templates adjustable by the End-User Ensure a small footprint Improve customers experience Transparant & affordable license
  • 17. Copyright © 2011 Roots nv, Belgium - All rights reserved iText: a perfect fit Java has no support for PDF’s Compared tools/suites/platforms vs API’s iText, due to Lightweight Full control on PDF structure (helps to manage footprint) Ability to manage PDF Templates with Acrobat Pro Scalable, as it easily integrates in a SOA (even OSGI friendly) Support for QR codes Speed (under 90 ms / Car-Pass Certificate instead of 900 ms) Our track record
  • 18. Copyright © 2011 Roots nv, Belgium - All rights reserved time for action
  • 19. Copyright © 2011 Roots nv, Belgium - All rights reserved Car-Pass Template
  • 20. Copyright © 2011 Roots nv, Belgium - All rights reserved Code - Complete Fields with data try ( FileInputStream is = new FileInputStream(pdfTemplate); FileOutputStream os = new FileOutputStream(completedCarPassPDF) ) { PdfReader pdfReader = new PdfReader(is); PdfStamper stamper = new PdfStamper(pdfReader, os); AcroFields acroFields = stamper.getAcroFields(); for ( Map.Entry<String, String> entry : model.entrySet() ) { acroFields.setField ( entry.getKey(), entry.getValue() ); } stamper.setFormFlattening(true); stamper.close(); pdfReader.close(); }
  • 21. Copyright © 2011 Roots nv, Belgium - All rights reserved Code - From Object to Key-Value pairs Map<String, String> model = BeanUtils.recursiveDescribe ( carPass, "car-pass" ); http://stackoverflow.com/questions/6133660/recursive-beanutils-describe model = car-pass.certificateNumber = 0782-7851-9342 car-pass.vin = VF154PB5VXA1138BB car-pass.make = Renault Megane car-pass.price = 7,00 EUR car-pass.firstUse = 22/12/1981 car-pass.firstRegistrationBe = 22/12/1981 car-pass.validUntil = 01/02/2007 car-pass.odometerReadings[0].date = 01/12/2006 car-pass.odometerReadings[0].value = 185643 car-pass.odometerReadings[1].date = 16/04/2006 car-pass.odometerReadings[1].value = 173459 …
  • 22. Copyright © 2011 Roots nv, Belgium - All rights reserved Code - QR Code BarcodeQRCode qrcode = new BarcodeQRCode("https://ws.car-pass.be/verify/" + carPass.getCertificateNumber(), 160, 160, null); ! Image image = qrcode.getImage(); image.setAbsolutePosition(430f, 650f); PdfContentByte content = stamper.getOverContent(pdfReader.getNumberOfPages()); content.addImage(image); ! !
  • 23. Copyright © 2011 Roots nv, Belgium - All rights reserved Code - Keeping it small PdfDictionary drdict = reader.getCatalog().getAsDict(PdfName.ACROFORM).getAsDict(PdfName.DR); PdfDictionary drfontdict = drdict.getAsDict(PdfName.FONT); for (PdfName key : new HashSet<PdfName>(drfontdict.getKeys())) { drfontdict.remove(key); } PdfArray pages = reader.getCatalog().getAsDict(PdfName.PAGES).getAsArray(PdfName.KIDS); for (int i = 0; i < pages.size(); i++) { PdfDictionary page = pages.getAsDict(i); PdfArray annots = page.getAsArray(PdfName.ANNOTS); for (int j = 0; j < annots.size(); j++) { PdfDictionary annot = annots.getAsDict(j); PdfName itvalue = annot.getAsName(new PdfName("IT")); if (new PdfName("FreeTextTypewriter").equals(itvalue)) { annot.put(new PdfName("IT"), new PdfName("FreeTextTypeWriter")); } } }
  • 24. Copyright © 2011 Roots nv, Belgium - All rights reserved iText RUPS http://itextpdf.com/product/itext_rups
  • 25. Copyright © 2013 Roots nv, Belgium - All rights reserved seeing, is believing
  • 26. Copyright © 2011 Roots nv, Belgium - All rights reserved www.roots.be ! koen.dehaen@roots.be ! github.com/koendehaen/ itext_summit_pdf_templates Q&A