SlideShare a Scribd company logo
1 of 26
Download to read offline
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

More Related Content

More from 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
 

More from 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
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

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