Title: iText in Action
1(No Transcript)
2iText in Action
- Creating and Manipulating PDF
Bruno Lowagie Paulo Soares Main developers
of iText and iTextSharp
3Overall Presentation Goal
- Learn about creating and
- manipulating PDF documents
- with iText
4Speakers Qualifications
- Bruno Lowagie
- Original developer of iText
- Author of the book iText in Action
- Works at Ghent University (Belgium)
- Research project for Actuate (Eclipse/BIRT)
5Speakers Qualifications
- Paulo Soares
- Main developer of iText
- Maintainer of the .NET port iTextSharp
- Works at Consiste (Portugal)
6Dr. iText
- or
- How I Learned to Stop Worrying and Love
- PDF
7Where to meet your Idols?
- JavaPolis
- The International Filmfestival Ghent
- Almost 170 movies
- Almost 2 weeks
- Different locations in the city
- Concerts, Events, Exhibitions
8Filmfestival Preparation
- Create Database
- Movies title, director, duration
- Screenings location, date, time
- Competitions official selection, eXploreZone
- Sections world cinema, history of film
9Section
10Titles
11Directors
12Screenings
13Film Festival Preparation
- Want to watch a lot of movies?
- What is offered?
- Create document from database
14DEMO
15Film Festival Preparation
- Want to watch a lot of movies?
- What is feasible?
- Create schedule from database
16DEMO
17Film Festival Preparation
- Want to watch a lot of movies?
- Get an accreditation card!
- Create document from template
18DEMO
19iText in Action
20DEMO
21PDF Creation
- iText is not an end user tool
- iText is for creating PDF on-the-fly
- 10, 100, 1,000, 10,000 pages,
22PDF manipulation
- Concatenate, Split, Burst
- Add bookmarks, page nrs, watermarks
- Add digital signatures
- Fill out PDF forms
23iText in Action
- Part 1 Introduction
- Why iText?
- Hello World (times 35)
- Why PDF?
24iText in Action part 1
Creating a PDF document in 5 steps
1 Document document new Document() try
2 PdfWriter.getInstance(document, new
FileOuputStream("HelloWorld.pdf")) 3 document
open() 4 document.add(new Paragraph("Hello
World")) catch(DocumentException de)
catch(IOException ioe)
5 document.close()
25iText in Action part 1
Adding a watermark
PdfReader reader new PdfReader("original.pdf")
PdfStamper stamper new PdfStamper( reader,
new FileOutputStream("new.pdf")) Image img
Image.getInstance("watermark.jpg") img.setAbsolut
ePosition(200, 400) PdfContentByte under int
total reader.getNumberOfPages() 1 for (int i
1 i lt total i) under
stamper.getUnderContent(i) under.addImage(img)
stamper.close()
26iText in Action
- Part 2 Basic Building Blocks
- Chunk, Phrase, Paragraph, List, Anchor,
- Images
- Tables and Columns
27iText in Action part 2
Simple PdfPTable example
PdfPTable table new PdfPTable(3) PdfPCell cell
new PdfPCell( new Paragraph("header with
colspan 3")) cell.setColspan(3) table.addCell(ce
ll) table.addCell("1.1") table.addCell("2.1") t
able.addCell("3.1") document.add(table)
28iText in Action
- Part 3 Text and Graphics
- Fonts
- Low-level PDF
- Graphics2D
29iText in Action part 3
Simple PDF syntax example
cb.saveState() // q cb.setLineWidth(0.
3f) // 0.3 w cb.setGrayStroke(0.9f) //
0.9 G cb.setLineDash(3, 1) // 3 1
d cb.moveTo(36, 842) // 36 842
m cb.lineTo(36, 0) // 36 0
l cb.stroke() //
S cb.restoreState() // Q
30iText in Action part 3
Simple Graphics2D example
PdfContentByte cb writer.getDirectContent() Gra
phics2D graphics2D cb.createGraphics(595,
842) graphics2D.drawString("Hello World", 36,
36) graphics2D.drawLine(36, 42, 108,
42) graphics2D.dispose()
31iText in Action
- Part 4 Interactive PDF
- Bookmarks, page transitions,
- Actions, annotations, forms, fields
- Creating PDF in a web application
32Fill out form
Simple PDF form example
PdfReader reader new PdfReader("form.pdf") PdfS
tamper stamper new PdfStamper(reader,
baos) AcroFields form stamper.getAcroFields()
form.setField("name", "Laura")
form.setField("location", "Foobar")
form.setField("job", "developer")
stamper.close()
33Fill out form
PDF form example
PdfReader reader new PdfReader("form.pdf") PdfS
tamper stamper new PdfStamper(reader,
baos) AcroFields form stamper.getAcroFields()
form.setFieldProperty("type", "textcolor",
Color.BLUE, null) form.setField("type", "VIP
Pass") form.setFieldProperty("filmfestival",
"bgcolor", Color.BLUE, null) form.regenerateField
("filmfestival") stamper.setFormFlattening(true)
stamper.close()
34Fill out form
PDF form example
PdfReader reader new PdfReader(path
CARD) PdfStamper stamper new
PdfStamper(reader, baos) AcroFields form
stamper.getAcroFields() PushbuttonField bt
form.getNewPushbuttonFromField("photo") bt.setLay
out(PushbuttonField.LAYOUT_ICON_ONLY) bt.setPropo
rtionalIcon(true) bt.setImage(data.getPhoto()) f
orm.replacePushbuttonField( "photo",
bt.getField()) stamper.close()
35iText in Action
- gt 250 source files
- small standalone examples
- larger Foobar examples
36DEMO
37Summary
- Topics
- PDF Creation
- PDF Manipulation
- Examples
- Publish a database to PDF
- Fill out a PDF form
38Unknown, Unloved
- The Power of PDF is often underestimated
- especially by developers that dont know
- what PDF is about.
- With iText they no longer have an excuse
- not to start using and loving PDF
- iText is PDF made easy.
39URLs
- iText
- http//www.lowagie.com/iText
- http//itext.ugent.be/
- iTextSharp
- http//itextsharp.sourceforge.net/
- iText in Action
- http//www.manning.com/lowagie/
40QA
41- Thank you for your attention!