43
iText in Action Second Edition Bruno Lowagie 1T3XT

i Text in Action

Embed Size (px)

Citation preview

Page 1: i Text in Action

iText in Action

Second Edition

Bruno Lowagie — 1T3XT

Page 2: i Text in Action

Devoxx templates

Page 3: i Text in Action

Adding buttons as place holder

Page 4: i Text in Action

Mark tabs as annotations

Page 5: i Text in Action

Combining speakers and talks

Page 6: i Text in Action

Generating the complete guide

Page 7: i Text in Action
Page 8: i Text in Action

Chapters on itextpdf.com

Page 9: i Text in Action

Examples on SourceForge (SVN)

Page 10: i Text in Action

10

Part 1: Creating PDF from scratch

Chapter 1: Introducing PDF and iText

Chapter 2: Using iText’s basic building blocks

Chapter 3: Adding content at absolute positions

Chapter 4: Organizing content in tables

Chapter 5: Table, cell and page events

Page 11: i Text in Action

Part 2: Manipulating existing PDFs

Chapter 6: Working with existing PDFs

Chapter 7: Making documents interactive

Chapter 8: Filling out interactive forms

Page 12: i Text in Action

DEMO 1: XML Forms Architecture

Page 13: i Text in Action

Data in the form of XML

Page 14: i Text in Action

Using an XML Schema Definition

Page 15: i Text in Action

Creating a dynamic XFA form

Page 16: i Text in Action

Importing an XSD

Page 17: i Text in Action

Rearranged fields

Page 18: i Text in Action

Dynamic XFA form

Page 19: i Text in Action

Dynamic XFA form with data

Page 20: i Text in Action

Part 3: Essential iText Skills

Chapter 9: Integrating iText in your web apps

Chapter 10: Using color and images

Chapter 11: Choosing the right font

Chapter 12: Protecting your PDF

Page 21: i Text in Action

Part 4: Under the hood

Chapter 13: PDFs inside-out

Chapter 14: The imaging model

Chapter 15: Page content and structure

Chapter 16: PDF streams

Page 22: i Text in Action

BOOK DEMO 2: Parsing PDF

Page 23: i Text in Action

Parsing PDF

• PdfTextExtractor.getTextFromPage(reader, i)

Page 24: i Text in Action

RenderListener

Generic tag event: public void renderText(TextRenderInfo

renderInfo) {

System.out.print("<");

System.out.print(renderInfo.getText());

System.out.print(" @ (");

System.out.print(

renderInfo.getBaseline()

.getStartPoint().get(0));

System.out.print(", ");

System.out.print(

renderInfo.getBaseline()

.getStartPoint().get(1));

System.out.print(") l: ");

System.out.print(

renderInfo.getBaseline()

.getLength());

System.out.println(">");

}

• beginTextBlock()

• renderText(TextRenderInfo info)

• endTextBlock()

• renderImage(ImageRenderInfo info)

Page 25: i Text in Action

Parsing content streams

• Showing the TextRenderInfo

Page 26: i Text in Action

Structure in PDF

Page 27: i Text in Action

Tagged PDF to XML

• Take the file moby.xml

• Convert it to moby.pdf

– create a RoleMap

– parse the structure

– parse the content

• Convert tagged PDF to XML

Page 28: i Text in Action

BOOK DEMO 3: PDF and Flash

Page 29: i Text in Action

Creating a movie calendar in Flash

Page 30: i Text in Action

Calendar in Action in HTML

Page 31: i Text in Action

Online XML data available

• http://flex.itextpdf.org/fff/day_2011-10-12.xml

Page 32: i Text in Action

Crossdomain.xml

• http://flex.itextpdf.org/crossdomain.xml

Page 33: i Text in Action

Calendar in Action in PDF

Page 34: i Text in Action

Guest Demo

iText for map printing

Joachim Van der Auwera

GeoSparc

Page 35: i Text in Action

Introducing Geomajas

• World's first open source all-java web mapping

framework

• Using Spring framework, Google Web Toolkit

(GWT) and best-of-bread spatial open source

• Fully modular

• Showcase on

http://apps.geomajas.org/showcase-beta/

Page 36: i Text in Action

Need for better Web map printing

• HTML print is flawed

• Bad resolution

• No control over layout

• No control over vector graphics

• Not reproducible across browsers

Page 37: i Text in Action

Choice for PDF

• Pixel-level reproducibility

• Portable and exchangeable

• Vector support

• Resolution control

Page 38: i Text in Action

Why iText

• Open source

• 2D graphics API

• Fast and robust

Page 39: i Text in Action

Design decisions

• Component model to support layout control,

editability and extensibility

• Client-side editing and print preview

• Server-side template rendering and persistence

Page 40: i Text in Action

Problem: drawing vector layers

• PdfContentByte allows pen movements:

private void drawPathContent(Coordinate[] coord) {

pdfContentByte.moveTo(

origX + (float) coord[0].x,

origY + (float) coord[0].y);

for (int i = 1; i < coord.length; i++) {

pdfContentByte.lineTo(

origX + (float) coord[i].x,

origY + (float) coord[i].y);

}

}

• Fill according to even/uneven rule template.closePathEoFillStroke();

Page 41: i Text in Action

Problem: drawing tile-based raster layers

• Using JAI to create a large mosaic image first

ParameterBlock pbMosaic = new ParameterBlock();

pbMosaic.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);

for (RenderedImage renderedImage : images) {

pbMosaic.addSource(renderedImage);

}

RenderedOp mosaic = JAI.create(

"mosaic", pbMosaic,

new RenderingHints(JAI.KEY_IMAGE_LAYOUT,imageLayout));

• Convert to iText image by first streaming to

bytes and calling factory method: Image img = Image.getInstance(byte[])

• Draw with PdfContentByte addImage()

Page 42: i Text in Action

Problem: transparent color styles

• PDF supports complex transparency model

• iText graphic state holds pen state: private void setFill(Color color) {

// Color and transparency

PdfGState state = new PdfGState();

state.setFillOpacity(color.getAlpha() / 255f);

state.setBlendMode(PdfGState.BM_NORMAL);

template.setGState(state);

template.setColorFill(color);

}

• Don't forget to enclose in

PdfContentByte.save/restoreState() pair !

Page 43: i Text in Action

Further things to explore

• GeoPDF

• 3D object mapping

• Multi-page reports