SlideShare uma empresa Scribd logo
1 de 38
PDF made easy with iText 7
What’s new in iText and iTextSharp?
Benoit Lagae, Developer, iText Software
Bruno Lowagie, Chief Strategy Officer, iText Group
Why did we write iText?
• Specific problems that needed to be solved
– Emancipate PDF from the desktop to the server
• Solved in 1998 with a first PDF library
• Deep knowledge of PDF required
– Make PDF creation easier for developers
• Solved in 2000 with the release of iText
• Concept: PdfWriter and Document
• Add high-level objects (e.g. paragraph, list, table)
History
• First release: 2000
• iText 1: 2003
• iText 2: 2007
• iText 5: 2009; upgrade to Java 5
• iText 7: 2016; upgrade to Java 7
iText is available for Java and .NET
Why iText 7?
iText 5 was approaching the limits of its architecture.
iText 7 overcomes these limits and enables further user-driven feature
development and more efficient support
• Complete revision of all classes and interfaces based on experience
with iText 5.
• Complete new layout module, which resolves some inconsistencies
in iText 5 and enables generation of complex layouts.
• Complete rewrite of font support enabling advanced typography.
iText 7: modular approach
Basic design principle
OutputStream fos = new FileOutputStream(dest);
PdfWriter writer = new PdfWriter(fos);
PdfDocument pdf = new PdfDocument(writer);
// PDF knowledge needed to add content
pdf.close();
OutputStream fos = new FileOutputStream(dest);
PdfWriter writer = new PdfWriter(fos);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
// No PDF knowledge needed to add content
document.close();
iText’s basic building
blocks: examples
Hello world: code
OutputStream fos = new FileOutputStream(dest);
PdfWriter writer = new PdfWriter(fos);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();
Hello world: result
Hello world: the hard way
FileOutputStream fos = new FileOutputStream(dest);
PdfWriter writer = new PdfWriter(fos);
PdfDocument pdf = new PdfDocument(writer);
PageSize ps = PageSize.A4;
PdfPage page = pdf.addNewPage(ps);
PdfCanvas canvas = new PdfCanvas(page);
canvas.beginText()
.setFontAndSize(
PdfFontFactory.createFont(FontConstants.HELVETICA), 12)
.moveText(36, 790)
.showText("Hello World!")
.endText();
pdf.close();
List example: code
// Create a PdfFont
PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
// Add a Paragraph
document.add(new Paragraph("iText is:").setFont(font));
// Create a List
List list = new List()
.setSymbolIndent(12)
.setListSymbol("u2022")
.setFont(font);
// Add ListItem objects
list.add(new ListItem("Never gonna give you up"))
.add(new ListItem("Never gonna let you down"))
.add(new ListItem("Never gonna run around and desert you"))
.add(new ListItem("Never gonna make you cry"))
.add(new ListItem("Never gonna say goodbye"))
.add(new ListItem("Never gonna tell a lie and hurt you"));
// Add the list
document.add(list);
List example: result
Image example
Image fox = new Image(ImageFactory.getImage(FOX));
Image dog = new Image(ImageFactory.getImage(DOG));
Paragraph p = new Paragraph("Quick brown ").add(fox)
.add(" jumps over the lazy ").add(dog);
document.add(p);
New in iText 7:
improved typography
and support for Indic scripts
iText 5: missing links
Indic scripts:
•Only unsupported major script family
•Feature request #1
•Huge opportunity
•limited support in most other PDF libraries
Other features:
•Optional ligatures in Latin script
•Vowel diacritics in Arabic
Indic scripts: problems
•Lack of expertise
•Unicode encodes 49 Indic scripts
•Complex scripts with unique features
•Glyph repositioning: ह + ि = िह
•Glyph substitution: ம + ு = மு
•Half-characters: त + + य = त्य
•Unsolvable issues for iText 5 font engine
•No dedicated Unicode points for half-characters
•No font lookups past ‘uFFFF’
•Ligaturization is context-dependent (virama)
Indic scripts: solutions
Writing a new font engine
• Automatic script recognition
• Based on Unicode ranges
• Flexibility = extensibility
• Generic Shaper class
• Separate module, only called when necessary
• Glyph replacement rules
• Different per writing system
• Alternate glyphs are font-dependent
Indic scripts: examples
PdfFont font = PdfFontFactory.createFont(arial, PdfEncodings.IDENTITY_H, true);
String txt = "u0938u093Eu0939u093Fu0924u094Du092Fu0915u093Eu0930"; // saahityakaar
document.add(new Paragraph(txt).setFont(font));
String txt = "u0B8Eu0BB4u0BC1u0BA4u0BCDu0BA4u0BBEu0BB3u0BB0u0BCD"; // eluttaalar
document.add(new Paragraph(txt).setFont(font));
Other scripts: examples
PdfFont font = PdfFontFactory.createFont(arial, PdfEncodings.IDENTITY_H, true);
String txt = " u0627u0644u0643u0627u062Au0628"; // al-katibu
document.add(new Paragraph(txt).setFont(font));
String txt = "writer";
GlyphLine glyphLine = font.createGlyphLine(txt);
Shaper.applyLigaFeature(foglihtenNo07, glyphLine, null);
canvas.showText(glyphLine)
Status of advanced
typography in iText 7
•Indic scripts
•We already support:
•Devanagari
•Tamil
•Coming soon:
•Telugu
•Others: based on customer demand
•Arabic
•Support for vocalized Arabic (diacritics) is in development
•Latin
•Optional ligatures are fully supported
Real-world use:
Publishing a database
CSV example
Imagine a series of records
Parse CSV line by line
OutputStream fos = new FileOutputStream(dest);
PdfWriter writer = new PdfWriter(fos);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf, PageSize.A4.rotate());
document.setMargins(20, 20, 20, 20);
PdfFont font = PdfFontFactory.createFont(FontConstants.HELVETICA);
PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
Table table = new Table(new float[]{4, 1, 3, 4, 3, 3, 3, 3, 1});
table.setWidthPercent(100);
BufferedReader br = new BufferedReader(new FileReader(DATA));
String line = br.readLine();
process(table, line, bold, true);
while ((line = br.readLine()) != null) {
process(table, line, font, false);
}
br.close();
document.add(table);
document.close();
Process each line
public void process(Table table, String line,
PdfFont font, boolean isHeader) {
StringTokenizer tokenizer = new StringTokenizer(line, ";");
while (tokenizer.hasMoreTokens()) {
if (isHeader) {
table.addHeaderCell(
new Cell().add(
new Paragraph(tokenizer.nextToken()).setFont(font)));
} else {
table.addCell(
new Cell().add(
new Paragraph(tokenizer.nextToken()).setFont(font)));
}
}
}
CSV: resulting report
Form filling
Form flattening
Example form
Look inside your PDF
Fill the form
PdfReader reader = new PdfReader(src);
PdfWriter writer = new PdfWriter(dest);
PdfDocument pdf = new PdfDocument(reader, writer);
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("name").setValue("James Bond");
fields.get("language").setValue("English");
fields.get("experience1").setValue("Off");
fields.get("experience2").setValue("Yes");
fields.get("experience3").setValue("Yes");
fields.get("shift").setValue("Any");
fields.get("info").setValue("I was 38 years old when I became an MI6 agent.");
pdf.close();
Result after filling
Flatten the form
PdfReader reader = new PdfReader(src);
PdfWriter writer = new PdfWriter(dest);
PdfDocument pdf = new PdfDocument(reader, writer);
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("name").setValue("James Bond");
fields.get("language").setValue("English");
fields.get("experience1").setValue("Off");
fields.get("experience2").setValue("Yes");
fields.get("experience3").setValue("Yes");
fields.get("shift").setValue("Any");
fields.get("info").setValue("I was 38 years old when I became an MI6 agent.");
form.flattenFields();
pdf.close();
Result after flattening
Form flattening
Merging
United States: Example form
Flatten and merge
PdfDocument destPdfDocument = new PdfDocument(new PdfWriter(dest));
BufferedReader bufferedReader = new BufferedReader(new FileReader(DATA));
String line;
while ((line = bufferedReader.readLine()) != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument sourcePdfDocument =
new PdfDocument(new PdfReader(SRC), new PdfWriter(baos));
PdfAcroForm form = PdfAcroForm.getAcroForm(sourcePdfDocument, true);
StringTokenizer tokenizer = new StringTokenizer(line, ";");
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("name").setValue(tokenizer.nextToken());
form.flattenFields();
sourcePdfDocument.close();
sourcePdfDocument = new PdfDocument(
new PdfReader(new ByteArrayInputStream(baos.toByteArray())));
sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(),
destPdfDocument, null);
sourcePdfDocument.close();
}
bufferedReader.close();
destPdfDocument.close();
The result
(and why we don’t like it)
Flatten and merge
PdfWriter writer = new PdfWriter(dest).setSmartMode(true);
PdfDocument destPdfDocument = new PdfDocument(writer);
BufferedReader bufferedReader = new BufferedReader(new FileReader(DATA));
String line;
while ((line = bufferedReader.readLine()) != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument sourcePdfDocument =
new PdfDocument(new PdfReader(SRC), new PdfWriter(baos));
PdfAcroForm form = PdfAcroForm.getAcroForm(sourcePdfDocument, true);
StringTokenizer tokenizer = new StringTokenizer(line, ";");
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("name").setValue(tokenizer.nextToken());
form.flattenFields();
sourcePdfDocument.close();
sourcePdfDocument = new PdfDocument(
new PdfReader(new ByteArrayInputStream(baos.toByteArray())));
sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(),
destPdfDocument, null);
sourcePdfDocument.close();
}
bufferedReader.close();
destPdfDocument.close();
The result
(much better than before)

Mais conteúdo relacionado

Mais procurados

Introducing OpenAPI Version 3.1
Introducing OpenAPI Version 3.1Introducing OpenAPI Version 3.1
Introducing OpenAPI Version 3.1SmartBear
 
Introduction to sitecore identity
Introduction to sitecore identityIntroduction to sitecore identity
Introduction to sitecore identityGopikrishna Gujjula
 
Create a Unified View of Your Application Security Program – Black Duck Hub a...
Create a Unified View of Your Application Security Program – Black Duck Hub a...Create a Unified View of Your Application Security Program – Black Duck Hub a...
Create a Unified View of Your Application Security Program – Black Duck Hub a...Denim Group
 
apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...
apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...
apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...apidays
 
How API Enablement Drives Legacy Modernization
How API Enablement Drives Legacy ModernizationHow API Enablement Drives Legacy Modernization
How API Enablement Drives Legacy ModernizationMuleSoft
 
Facebook api
Facebook api Facebook api
Facebook api snipermkd
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!Alex Borysov
 
Building APIs with Apigee Edge and Microsoft Azure
Building APIs with Apigee Edge and Microsoft AzureBuilding APIs with Apigee Edge and Microsoft Azure
Building APIs with Apigee Edge and Microsoft AzureApigee | Google Cloud
 
What's New in API Connect & DataPower Gateway in 1H 2018
What's New in API Connect & DataPower Gateway in 1H 2018What's New in API Connect & DataPower Gateway in 1H 2018
What's New in API Connect & DataPower Gateway in 1H 2018IBM API Connect
 
Be project ppt asp.net
Be project ppt asp.netBe project ppt asp.net
Be project ppt asp.netSanket Jagare
 

Mais procurados (20)

Introducing OpenAPI Version 3.1
Introducing OpenAPI Version 3.1Introducing OpenAPI Version 3.1
Introducing OpenAPI Version 3.1
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Introduction to sitecore identity
Introduction to sitecore identityIntroduction to sitecore identity
Introduction to sitecore identity
 
Create a Unified View of Your Application Security Program – Black Duck Hub a...
Create a Unified View of Your Application Security Program – Black Duck Hub a...Create a Unified View of Your Application Security Program – Black Duck Hub a...
Create a Unified View of Your Application Security Program – Black Duck Hub a...
 
apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...
apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...
apidays Paris 2022 - Sustainable API Green Score, Yannick Tremblais (Groupe R...
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
Architecture for the API-enterprise
Architecture for the API-enterpriseArchitecture for the API-enterprise
Architecture for the API-enterprise
 
Attacking REST API
Attacking REST APIAttacking REST API
Attacking REST API
 
API
APIAPI
API
 
How API Enablement Drives Legacy Modernization
How API Enablement Drives Legacy ModernizationHow API Enablement Drives Legacy Modernization
How API Enablement Drives Legacy Modernization
 
Facebook api
Facebook api Facebook api
Facebook api
 
API Management
API ManagementAPI Management
API Management
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
 
OpenID Connect Explained
OpenID Connect ExplainedOpenID Connect Explained
OpenID Connect Explained
 
Kong Workshop.pdf
Kong Workshop.pdfKong Workshop.pdf
Kong Workshop.pdf
 
Definitive Guide to API Management
Definitive Guide to API ManagementDefinitive Guide to API Management
Definitive Guide to API Management
 
Building APIs with Apigee Edge and Microsoft Azure
Building APIs with Apigee Edge and Microsoft AzureBuilding APIs with Apigee Edge and Microsoft Azure
Building APIs with Apigee Edge and Microsoft Azure
 
What's New in API Connect & DataPower Gateway in 1H 2018
What's New in API Connect & DataPower Gateway in 1H 2018What's New in API Connect & DataPower Gateway in 1H 2018
What's New in API Connect & DataPower Gateway in 1H 2018
 
Be project ppt asp.net
Be project ppt asp.netBe project ppt asp.net
Be project ppt asp.net
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 

Destaque

Monetizing open-source projects
Monetizing open-source projectsMonetizing open-source projects
Monetizing open-source projectsiText Group nv
 
Intellectual property and licensing
Intellectual property and licensingIntellectual property and licensing
Intellectual property and licensingiText 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
 
FIT Seminar Singapore presentation
FIT Seminar Singapore presentationFIT Seminar Singapore presentation
FIT Seminar Singapore presentationiText 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
 
Tech Startup Day 2015: 4 failures and 1 hit
Tech Startup Day 2015: 4 failures and 1 hitTech Startup Day 2015: 4 failures and 1 hit
Tech Startup Day 2015: 4 failures and 1 hitiText 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
 
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
 
The importance of standards
The importance of standardsThe importance of standards
The importance of standardsiText Group nv
 
iText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText 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
 

Destaque (14)

Monetizing open-source projects
Monetizing open-source projectsMonetizing open-source projects
Monetizing open-source projects
 
Intellectual property and licensing
Intellectual property and licensingIntellectual property and licensing
Intellectual property and licensing
 
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
 
Oops, I broke my API
Oops, I broke my APIOops, I broke my API
Oops, I broke my API
 
FIT Seminar Singapore presentation
FIT Seminar Singapore presentationFIT Seminar Singapore presentation
FIT Seminar Singapore presentation
 
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
 
Tech Startup Day 2015: 4 failures and 1 hit
Tech Startup Day 2015: 4 failures and 1 hitTech Startup Day 2015: 4 failures and 1 hit
Tech Startup Day 2015: 4 failures and 1 hit
 
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...
 
Apache Fop
Apache FopApache Fop
Apache Fop
 
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
 
The importance of standards
The importance of standardsThe importance of standards
The importance of standards
 
iText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText Summit 2014: Keynote talk
iText Summit 2014: Keynote talk
 
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
 
ZUGFeRD: an overview
ZUGFeRD: an overviewZUGFeRD: an overview
ZUGFeRD: an overview
 

Semelhante a PDF made easy with iText 7

OSSBarCamp Talk on Dexy
OSSBarCamp Talk on DexyOSSBarCamp Talk on Dexy
OSSBarCamp Talk on Dexyananelson
 
Creating a Facebook Clone - Part V - Transcript.pdf
Creating a Facebook Clone - Part V - Transcript.pdfCreating a Facebook Clone - Part V - Transcript.pdf
Creating a Facebook Clone - Part V - Transcript.pdfShaiAlmog1
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInVitaly Gordon
 
Phpconf taiwan-2012
Phpconf taiwan-2012Phpconf taiwan-2012
Phpconf taiwan-2012Hash Lin
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on WindowsShahar Evron
 
[Mentor Graphics] A Perforce-based Automatic Document Generation System
[Mentor Graphics] A Perforce-based Automatic Document Generation System[Mentor Graphics] A Perforce-based Automatic Document Generation System
[Mentor Graphics] A Perforce-based Automatic Document Generation SystemPerforce
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overviewbwullems
 
10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the world10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the worldColdFusionConference
 
Applying software engineering to configuration management
Applying software engineering to configuration managementApplying software engineering to configuration management
Applying software engineering to configuration managementBart Vanbrabant
 
Code Generation using T4
Code Generation using T4Code Generation using T4
Code Generation using T4Joubin Najmaie
 
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...Titouan Vervack
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Anupam Ranku
 
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
PDF Generation in Rails with Prawn and Prawn-to: John McCaffreyPDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
PDF Generation in Rails with Prawn and Prawn-to: John McCaffreyJohn McCaffrey
 
.Net passé, présent et futur
.Net passé, présent et futur.Net passé, présent et futur
.Net passé, présent et futurDenis Voituron
 
Taking Your FDM Application to the Next Level with Advanced Scripting
Taking Your FDM Application to the Next Level with Advanced ScriptingTaking Your FDM Application to the Next Level with Advanced Scripting
Taking Your FDM Application to the Next Level with Advanced ScriptingAlithya
 

Semelhante a PDF made easy with iText 7 (20)

ODF Toolkit with .NET Support
ODF Toolkit with .NET SupportODF Toolkit with .NET Support
ODF Toolkit with .NET Support
 
Next .NET and C#
Next .NET and C#Next .NET and C#
Next .NET and C#
 
OSSBarCamp Talk on Dexy
OSSBarCamp Talk on DexyOSSBarCamp Talk on Dexy
OSSBarCamp Talk on Dexy
 
Creating a Facebook Clone - Part V - Transcript.pdf
Creating a Facebook Clone - Part V - Transcript.pdfCreating a Facebook Clone - Part V - Transcript.pdf
Creating a Facebook Clone - Part V - Transcript.pdf
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
Phpconf taiwan-2012
Phpconf taiwan-2012Phpconf taiwan-2012
Phpconf taiwan-2012
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on Windows
 
[Mentor Graphics] A Perforce-based Automatic Document Generation System
[Mentor Graphics] A Perforce-based Automatic Document Generation System[Mentor Graphics] A Perforce-based Automatic Document Generation System
[Mentor Graphics] A Perforce-based Automatic Document Generation System
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overview
 
10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the world10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the world
 
Applying software engineering to configuration management
Applying software engineering to configuration managementApplying software engineering to configuration management
Applying software engineering to configuration management
 
Code Generation using T4
Code Generation using T4Code Generation using T4
Code Generation using T4
 
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
 
Bi
BiBi
Bi
 
Dynamic Web Programming
Dynamic Web ProgrammingDynamic Web Programming
Dynamic Web Programming
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
 
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
PDF Generation in Rails with Prawn and Prawn-to: John McCaffreyPDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
 
.Net passé, présent et futur
.Net passé, présent et futur.Net passé, présent et futur
.Net passé, présent et futur
 
Taking Your FDM Application to the Next Level with Advanced Scripting
Taking Your FDM Application to the Next Level with Advanced ScriptingTaking Your FDM Application to the Next Level with Advanced Scripting
Taking Your FDM Application to the Next Level with Advanced Scripting
 
UNO based ODF Toolkit API
UNO based ODF Toolkit APIUNO based ODF Toolkit API
UNO based ODF Toolkit API
 

Mais de iText Group nv

The effects of the GDPR
The effects of the GDPRThe effects of the GDPR
The effects of the GDPRiText Group nv
 
Build your own_photobooth
Build your own_photoboothBuild your own_photobooth
Build your own_photoboothiText Group nv
 
ETDA Conference - Digital signatures: how it's done in PDF
ETDA Conference - Digital signatures: how it's done in PDFETDA Conference - Digital signatures: how it's done in PDF
ETDA Conference - Digital signatures: how it's done in PDFiText 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
 
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
 
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
 
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
 
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
 

Mais de iText Group nv (11)

The effects of the GDPR
The effects of the GDPRThe effects of the GDPR
The effects of the GDPR
 
Build your own_photobooth
Build your own_photoboothBuild your own_photobooth
Build your own_photobooth
 
ETDA Conference - Digital signatures: how it's done in PDF
ETDA Conference - Digital signatures: how it's done in PDFETDA Conference - Digital signatures: how it's done in PDF
ETDA Conference - Digital signatures: how it's done in PDF
 
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
 
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 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
 
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!
 
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...
 

Último

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Último (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

PDF made easy with iText 7

  • 1. PDF made easy with iText 7 What’s new in iText and iTextSharp? Benoit Lagae, Developer, iText Software Bruno Lowagie, Chief Strategy Officer, iText Group
  • 2. Why did we write iText? • Specific problems that needed to be solved – Emancipate PDF from the desktop to the server • Solved in 1998 with a first PDF library • Deep knowledge of PDF required – Make PDF creation easier for developers • Solved in 2000 with the release of iText • Concept: PdfWriter and Document • Add high-level objects (e.g. paragraph, list, table)
  • 3. History • First release: 2000 • iText 1: 2003 • iText 2: 2007 • iText 5: 2009; upgrade to Java 5 • iText 7: 2016; upgrade to Java 7 iText is available for Java and .NET
  • 4. Why iText 7? iText 5 was approaching the limits of its architecture. iText 7 overcomes these limits and enables further user-driven feature development and more efficient support • Complete revision of all classes and interfaces based on experience with iText 5. • Complete new layout module, which resolves some inconsistencies in iText 5 and enables generation of complex layouts. • Complete rewrite of font support enabling advanced typography.
  • 5. iText 7: modular approach
  • 6. Basic design principle OutputStream fos = new FileOutputStream(dest); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); // PDF knowledge needed to add content pdf.close(); OutputStream fos = new FileOutputStream(dest); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf); // No PDF knowledge needed to add content document.close();
  • 8. Hello world: code OutputStream fos = new FileOutputStream(dest); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf); document.add(new Paragraph("Hello World!")); document.close();
  • 10. Hello world: the hard way FileOutputStream fos = new FileOutputStream(dest); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); PageSize ps = PageSize.A4; PdfPage page = pdf.addNewPage(ps); PdfCanvas canvas = new PdfCanvas(page); canvas.beginText() .setFontAndSize( PdfFontFactory.createFont(FontConstants.HELVETICA), 12) .moveText(36, 790) .showText("Hello World!") .endText(); pdf.close();
  • 11. List example: code // Create a PdfFont PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN); // Add a Paragraph document.add(new Paragraph("iText is:").setFont(font)); // Create a List List list = new List() .setSymbolIndent(12) .setListSymbol("u2022") .setFont(font); // Add ListItem objects list.add(new ListItem("Never gonna give you up")) .add(new ListItem("Never gonna let you down")) .add(new ListItem("Never gonna run around and desert you")) .add(new ListItem("Never gonna make you cry")) .add(new ListItem("Never gonna say goodbye")) .add(new ListItem("Never gonna tell a lie and hurt you")); // Add the list document.add(list);
  • 13. Image example Image fox = new Image(ImageFactory.getImage(FOX)); Image dog = new Image(ImageFactory.getImage(DOG)); Paragraph p = new Paragraph("Quick brown ").add(fox) .add(" jumps over the lazy ").add(dog); document.add(p);
  • 14. New in iText 7: improved typography and support for Indic scripts
  • 15. iText 5: missing links Indic scripts: •Only unsupported major script family •Feature request #1 •Huge opportunity •limited support in most other PDF libraries Other features: •Optional ligatures in Latin script •Vowel diacritics in Arabic
  • 16. Indic scripts: problems •Lack of expertise •Unicode encodes 49 Indic scripts •Complex scripts with unique features •Glyph repositioning: ह + ि = िह •Glyph substitution: ம + ு = மு •Half-characters: त + + य = त्य •Unsolvable issues for iText 5 font engine •No dedicated Unicode points for half-characters •No font lookups past ‘uFFFF’ •Ligaturization is context-dependent (virama)
  • 17. Indic scripts: solutions Writing a new font engine • Automatic script recognition • Based on Unicode ranges • Flexibility = extensibility • Generic Shaper class • Separate module, only called when necessary • Glyph replacement rules • Different per writing system • Alternate glyphs are font-dependent
  • 18. Indic scripts: examples PdfFont font = PdfFontFactory.createFont(arial, PdfEncodings.IDENTITY_H, true); String txt = "u0938u093Eu0939u093Fu0924u094Du092Fu0915u093Eu0930"; // saahityakaar document.add(new Paragraph(txt).setFont(font)); String txt = "u0B8Eu0BB4u0BC1u0BA4u0BCDu0BA4u0BBEu0BB3u0BB0u0BCD"; // eluttaalar document.add(new Paragraph(txt).setFont(font));
  • 19. Other scripts: examples PdfFont font = PdfFontFactory.createFont(arial, PdfEncodings.IDENTITY_H, true); String txt = " u0627u0644u0643u0627u062Au0628"; // al-katibu document.add(new Paragraph(txt).setFont(font)); String txt = "writer"; GlyphLine glyphLine = font.createGlyphLine(txt); Shaper.applyLigaFeature(foglihtenNo07, glyphLine, null); canvas.showText(glyphLine)
  • 20. Status of advanced typography in iText 7 •Indic scripts •We already support: •Devanagari •Tamil •Coming soon: •Telugu •Others: based on customer demand •Arabic •Support for vocalized Arabic (diacritics) is in development •Latin •Optional ligatures are fully supported
  • 21. Real-world use: Publishing a database CSV example
  • 22. Imagine a series of records
  • 23. Parse CSV line by line OutputStream fos = new FileOutputStream(dest); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf, PageSize.A4.rotate()); document.setMargins(20, 20, 20, 20); PdfFont font = PdfFontFactory.createFont(FontConstants.HELVETICA); PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD); Table table = new Table(new float[]{4, 1, 3, 4, 3, 3, 3, 3, 1}); table.setWidthPercent(100); BufferedReader br = new BufferedReader(new FileReader(DATA)); String line = br.readLine(); process(table, line, bold, true); while ((line = br.readLine()) != null) { process(table, line, font, false); } br.close(); document.add(table); document.close();
  • 24. Process each line public void process(Table table, String line, PdfFont font, boolean isHeader) { StringTokenizer tokenizer = new StringTokenizer(line, ";"); while (tokenizer.hasMoreTokens()) { if (isHeader) { table.addHeaderCell( new Cell().add( new Paragraph(tokenizer.nextToken()).setFont(font))); } else { table.addCell( new Cell().add( new Paragraph(tokenizer.nextToken()).setFont(font))); } } }
  • 29. Fill the form PdfReader reader = new PdfReader(src); PdfWriter writer = new PdfWriter(dest); PdfDocument pdf = new PdfDocument(reader, writer); PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true); Map<String, PdfFormField> fields = form.getFormFields(); fields.get("name").setValue("James Bond"); fields.get("language").setValue("English"); fields.get("experience1").setValue("Off"); fields.get("experience2").setValue("Yes"); fields.get("experience3").setValue("Yes"); fields.get("shift").setValue("Any"); fields.get("info").setValue("I was 38 years old when I became an MI6 agent."); pdf.close();
  • 31. Flatten the form PdfReader reader = new PdfReader(src); PdfWriter writer = new PdfWriter(dest); PdfDocument pdf = new PdfDocument(reader, writer); PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true); Map<String, PdfFormField> fields = form.getFormFields(); fields.get("name").setValue("James Bond"); fields.get("language").setValue("English"); fields.get("experience1").setValue("Off"); fields.get("experience2").setValue("Yes"); fields.get("experience3").setValue("Yes"); fields.get("shift").setValue("Any"); fields.get("info").setValue("I was 38 years old when I became an MI6 agent."); form.flattenFields(); pdf.close();
  • 35. Flatten and merge PdfDocument destPdfDocument = new PdfDocument(new PdfWriter(dest)); BufferedReader bufferedReader = new BufferedReader(new FileReader(DATA)); String line; while ((line = bufferedReader.readLine()) != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(SRC), new PdfWriter(baos)); PdfAcroForm form = PdfAcroForm.getAcroForm(sourcePdfDocument, true); StringTokenizer tokenizer = new StringTokenizer(line, ";"); Map<String, PdfFormField> fields = form.getFormFields(); fields.get("name").setValue(tokenizer.nextToken()); form.flattenFields(); sourcePdfDocument.close(); sourcePdfDocument = new PdfDocument( new PdfReader(new ByteArrayInputStream(baos.toByteArray()))); sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(), destPdfDocument, null); sourcePdfDocument.close(); } bufferedReader.close(); destPdfDocument.close();
  • 36. The result (and why we don’t like it)
  • 37. Flatten and merge PdfWriter writer = new PdfWriter(dest).setSmartMode(true); PdfDocument destPdfDocument = new PdfDocument(writer); BufferedReader bufferedReader = new BufferedReader(new FileReader(DATA)); String line; while ((line = bufferedReader.readLine()) != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(SRC), new PdfWriter(baos)); PdfAcroForm form = PdfAcroForm.getAcroForm(sourcePdfDocument, true); StringTokenizer tokenizer = new StringTokenizer(line, ";"); Map<String, PdfFormField> fields = form.getFormFields(); fields.get("name").setValue(tokenizer.nextToken()); form.flattenFields(); sourcePdfDocument.close(); sourcePdfDocument = new PdfDocument( new PdfReader(new ByteArrayInputStream(baos.toByteArray()))); sourcePdfDocument.copyPagesTo(1, sourcePdfDocument.getNumberOfPages(), destPdfDocument, null); sourcePdfDocument.close(); } bufferedReader.close(); destPdfDocument.close();
  • 38. The result (much better than before)