iText in Action - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

iText in Action

Description:

11 - 15 DECEMBER ANTWERP BELGIUM. Overall Presentation Goal. Learn about creating and ... Maintainer of the .NET port iTextSharp. Works at Consiste (Portugal) ... – PowerPoint PPT presentation

Number of Views:380
Avg rating:3.0/5.0
Slides: 42
Provided by: erik111
Category:

less

Transcript and Presenter's Notes

Title: iText in Action


1
(No Transcript)
2
iText in Action
  • Creating and Manipulating PDF

Bruno Lowagie Paulo Soares Main developers
of iText and iTextSharp
3
Overall Presentation Goal
  • Learn about creating and
  • manipulating PDF documents
  • with iText

4
Speakers 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)

5
Speakers Qualifications
  • Paulo Soares
  • Main developer of iText
  • Maintainer of the .NET port iTextSharp
  • Works at Consiste (Portugal)

6
Dr. iText
  • or
  • How I Learned to Stop Worrying and Love
  • PDF

7
Where to meet your Idols?
  • JavaPolis
  • The International Filmfestival Ghent
  • Almost 170 movies
  • Almost 2 weeks
  • Different locations in the city
  • Concerts, Events, Exhibitions

8
Filmfestival Preparation
  • Create Database
  • Movies title, director, duration
  • Screenings location, date, time
  • Competitions official selection, eXploreZone
  • Sections world cinema, history of film

9
Section
10
Titles
11
Directors
12
Screenings
13
Film Festival Preparation
  • Want to watch a lot of movies?
  • What is offered?
  • Create document from database

14
DEMO
15
Film Festival Preparation
  • Want to watch a lot of movies?
  • What is feasible?
  • Create schedule from database

16
DEMO
17
Film Festival Preparation
  • Want to watch a lot of movies?
  • Get an accreditation card!
  • Create document from template

18
DEMO
19
iText in Action
20
DEMO
21
PDF Creation
  • iText is not an end user tool
  • iText is for creating PDF on-the-fly
  • 10, 100, 1,000, 10,000 pages,

22
PDF manipulation
  • Concatenate, Split, Burst
  • Add bookmarks, page nrs, watermarks
  • Add digital signatures
  • Fill out PDF forms

23
iText in Action
  • Part 1 Introduction
  • Why iText?
  • Hello World (times 35)
  • Why PDF?

24
iText 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()
25
iText 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()
26
iText in Action
  • Part 2 Basic Building Blocks
  • Chunk, Phrase, Paragraph, List, Anchor,
  • Images
  • Tables and Columns

27
iText 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)
28
iText in Action
  • Part 3 Text and Graphics
  • Fonts
  • Low-level PDF
  • Graphics2D

29
iText 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
30
iText 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()
31
iText in Action
  • Part 4 Interactive PDF
  • Bookmarks, page transitions,
  • Actions, annotations, forms, fields
  • Creating PDF in a web application

32
Fill 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()
33
Fill 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()
34
Fill 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()
35
iText in Action
  • gt 250 source files
  • small standalone examples
  • larger Foobar examples

36
DEMO
37
Summary
  • Topics
  • PDF Creation
  • PDF Manipulation
  • Examples
  • Publish a database to PDF
  • Fill out a PDF form

38
Unknown, 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.

39
URLs
  • iText
  • http//www.lowagie.com/iText
  • http//itext.ugent.be/
  • iTextSharp
  • http//itextsharp.sourceforge.net/
  • iText in Action
  • http//www.manning.com/lowagie/

40
QA
41
  • Thank you for your attention!
Write a Comment
User Comments (0)
About PowerShow.com