Upload
gerardo-calderon
View
17
Download
2
Embed Size (px)
Citation preview
iText in Action
Second Edition
Bruno Lowagie — 1T3XT
Devoxx templates
Adding buttons as place holder
Mark tabs as annotations
Combining speakers and talks
Generating the complete guide
Chapters on itextpdf.com
Examples on SourceForge (SVN)
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
Part 2: Manipulating existing PDFs
Chapter 6: Working with existing PDFs
Chapter 7: Making documents interactive
Chapter 8: Filling out interactive forms
DEMO 1: XML Forms Architecture
Data in the form of XML
Using an XML Schema Definition
Creating a dynamic XFA form
Importing an XSD
Rearranged fields
Dynamic XFA form
Dynamic XFA form with data
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
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
BOOK DEMO 2: Parsing PDF
Parsing PDF
• PdfTextExtractor.getTextFromPage(reader, i)
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)
Parsing content streams
• Showing the TextRenderInfo
Structure in PDF
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
BOOK DEMO 3: PDF and Flash
Creating a movie calendar in Flash
Calendar in Action in HTML
Online XML data available
• http://flex.itextpdf.org/fff/day_2011-10-12.xml
Crossdomain.xml
• http://flex.itextpdf.org/crossdomain.xml
Calendar in Action in PDF
Guest Demo
iText for map printing
Joachim Van der Auwera
GeoSparc
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/
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
Choice for PDF
• Pixel-level reproducibility
• Portable and exchangeable
• Vector support
• Resolution control
Why iText
• Open source
• 2D graphics API
• Fast and robust
Design decisions
• Component model to support layout control,
editability and extensibility
• Client-side editing and print preview
• Server-side template rendering and persistence
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();
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()
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 !
Further things to explore
• GeoPDF
• 3D object mapping
• Multi-page reports