<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>pdf on David Hamp-Gonsalves</title><link>https://davidhampgonsalves.com/tags/pdf/</link><description>Recent content in pdf on David Hamp-Gonsalves</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Mon, 16 May 2011 00:00:00 +0000</lastBuildDate><atom:link href="https://davidhampgonsalves.com/tags/pdf/index.xml" rel="self" type="application/rss+xml"/><item><title>PDF's using iText in 10 lines</title><link>https://davidhampgonsalves.com/pdfs-using-itext-in-10-lines/</link><pubDate>Mon, 16 May 2011 00:00:00 +0000</pubDate><guid>https://davidhampgonsalves.com/pdfs-using-itext-in-10-lines/</guid><description>There are some getting started tutorials for the iText library but I don&amp;rsquo;t think they really capture how fast and easy it is to get working PDF&amp;rsquo;s.
Your standard servlet hello world example is 10 super simple lines.
In your servlets doGet method:
response.setContentType(&amp;#34;application/pdf&amp;#34;); Document document = new Document(); try { PdfWriter.getInstance(document, response.getOutputStream()); document.open(); document.add(new Paragraph(&amp;#34;Hello world&amp;#34;)); document.close(); } catch (DocumentException e) { //handle the error } to break that down: First you need to let the browser know via the http response headers that the content is a pdf.</description></item></channel></rss>