Skip to content

04. HelloPrint

Antonio Diaz Arroyo edited this page Oct 16, 2015 · 13 revisions

Print from Spring MVC 3.2.

Example of use iText to generate a PDF and print it from browse in Chrome in Spring MVC 3.2.

Important points


Project Structure


pom.xml
<dependency>
	<groupId>com.itextpdf</groupId>
	<artifactId>itextpdf</artifactId>
	<version>${itext.version}</version>
</dependency>

Standalone example

standalone iText java application:

package com;

import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfWriter;

public class SavePdfLocal {
	public static void main(String[] args) throws Exception {
		System.out.println("working with documents...");
		Document document = new Document();
		PdfWriter.getInstance(document, new FileOutputStream("c:/Users/toni/Desktop/salida.pdf"));
		Rectangle one = new Rectangle(226.72f, 340.08f);
		document.setPageSize(one);
		document.setMargins(2, 2, 2, 2);
		document.open();
		Paragraph p = new Paragraph("Hi");
		document.add(p);
		document.close();
	}
}

Clone this wiki locally