SlideShare a Scribd company logo
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)

More Related Content

What's hot

Graylog is the New Black
Graylog is the New BlackGraylog is the New Black
Graylog is the New Black
Megan Roddie
 
Tilera tile64 by Ibrahem Batta
Tilera tile64  by Ibrahem BattaTilera tile64  by Ibrahem Batta
Tilera tile64 by Ibrahem BattaIbrahem Batta
 
Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...
Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...
Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...
Deloitte Deutschland
 
QNAP Product Training
QNAP Product Training QNAP Product Training
QNAP Product Training
Hernan Lopez
 
Enfabrica - Bridging the Network and Memory Worlds
Enfabrica - Bridging the Network and Memory WorldsEnfabrica - Bridging the Network and Memory Worlds
Enfabrica - Bridging the Network and Memory Worlds
Memory Fabric Forum
 
Hp dl 380 g9
Hp dl 380 g9Hp dl 380 g9
Hp dl 380 g9
ganeshvm1
 
12 Principles Of Knowledge Management By Enamul Haque
12 Principles Of Knowledge Management By Enamul Haque12 Principles Of Knowledge Management By Enamul Haque
12 Principles Of Knowledge Management By Enamul Haque
Enamul Haque
 

What's hot (7)

Graylog is the New Black
Graylog is the New BlackGraylog is the New Black
Graylog is the New Black
 
Tilera tile64 by Ibrahem Batta
Tilera tile64  by Ibrahem BattaTilera tile64  by Ibrahem Batta
Tilera tile64 by Ibrahem Batta
 
Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...
Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...
Wirtschaftliche Erholung mit geopolitischen Risiken | 5 Trends für die deutsc...
 
QNAP Product Training
QNAP Product Training QNAP Product Training
QNAP Product Training
 
Enfabrica - Bridging the Network and Memory Worlds
Enfabrica - Bridging the Network and Memory WorldsEnfabrica - Bridging the Network and Memory Worlds
Enfabrica - Bridging the Network and Memory Worlds
 
Hp dl 380 g9
Hp dl 380 g9Hp dl 380 g9
Hp dl 380 g9
 
12 Principles Of Knowledge Management By Enamul Haque
12 Principles Of Knowledge Management By Enamul Haque12 Principles Of Knowledge Management By Enamul Haque
12 Principles Of Knowledge Management By Enamul Haque
 

Viewers also liked

Monetizing open-source projects
Monetizing open-source projectsMonetizing open-source projects
Monetizing open-source projects
iText Group nv
 
Intellectual property and licensing
Intellectual property and licensingIntellectual property and licensing
Intellectual property and licensing
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 PDF
iText Group nv
 
Oops, I broke my API
Oops, I broke my APIOops, I broke my API
Oops, I broke my API
iText Group nv
 
FIT Seminar Singapore presentation
FIT Seminar Singapore presentationFIT Seminar Singapore presentation
FIT Seminar Singapore presentation
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 PDF
iText 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 hit
iText 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 hare
iText Group nv
 
The importance of standards
The importance of standardsThe importance of standards
The importance of standards
iText Group nv
 
iText Summit 2014: Keynote talk
iText Summit 2014: Keynote talkiText Summit 2014: Keynote talk
iText Summit 2014: Keynote talk
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 ahead
iText Group nv
 
ZUGFeRD: an overview
ZUGFeRD: an overviewZUGFeRD: an overview
ZUGFeRD: an overview
iText Group nv
 

Viewers also liked (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
 

Similar to PDF made easy with iText 7

Next .NET and C#
Next .NET and C#Next .NET and C#
Next .NET and C#
Bertrand Le Roy
 
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.pdf
ShaiAlmog1
 
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
Vitaly 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 Windows
Shahar 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 System
Perforce
 
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 world
ColdFusionConference
 
Applying software engineering to configuration management
Applying software engineering to configuration managementApplying software engineering to configuration management
Applying software engineering to configuration management
Bart Vanbrabant
 
Code Generation using T4
Code Generation using T4Code Generation using T4
Code Generation using T4
Joubin 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 McCaffrey
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
Denis 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 Scripting
Alithya
 

Similar to 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
 

More from iText Group nv

The effects of the GDPR
The effects of the GDPRThe effects of the GDPR
The effects of the GDPR
iText Group nv
 
Build your own_photobooth
Build your own_photoboothBuild your own_photobooth
Build your own_photobooth
iText 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 PDF
iText 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 Legal
iText 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 Study
iText 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 cycle
iText Group nv
 
The XML Forms Architecture
The XML Forms ArchitectureThe XML Forms Architecture
The XML Forms Architecture
iText 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 PDFs
iText 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
 

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

Recently uploaded

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
vrstrong314
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

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)