How to fit a String inside a rectangle?

There are three options: Either you provide a bigger rectangle, so that the content fits inside, or you reduce the content (e.g. smaller font, less text),… Keep the size of the rectangle, keep the font size, etc… but add the content that doesn’t fit on the next page. How do you know if the content … Read more

Display Unicode characters in converting Html to Pdf

You can also use the new XMLWorkerHelper (from library itextsharp.xmlworker), you need to override the default FontFactory implementation however. void GeneratePdfFromHtml() { const string outputFilename = @”.\Files\report.pdf”; const string inputFilename = @”.\Files\report.html”; using (var input = new FileStream(inputFilename, FileMode.Open)) using (var output = new FileStream(outputFilename, FileMode.Create)) { CreatePdf(input, output); } } void CreatePdf(Stream htmlInput, Stream … Read more

How to merge documents correctly?

Using the Document and PdfWriter class in combination with the addTemplate() method to merge documents is a bad idea. That’s not what the addTemplate() method is meant for. You have explicitly or implicitly defined the page size for the Document you are working with. With the addTemplate() method, you add PdfImportedPage instances, and when you … Read more

Dependency error in jasper-reports from itext

A much simpler solution may be to upgrade to a newer version of jasperreports. Version 6.1.0 has this dependency on iText: <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version>2.1.7.js2</version> <scope>compile</scope> </dependency> No more “floating” dependency on iText, and it’s a version that’s custom made for jasperreports! See http://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports/6.1.0 for the complete pom.xml.

IText merge documents with acrofields

Depending on what you want exactly, different scenarios are possible, but in any case: you are doing it wrong. You should use either PdfCopy or PdfSmartCopy to merge documents. The different scenarios are explained in the following video tutorial. You can find most of the examples in the iText sandbox. Merging different forms (having different … Read more

Using iText to convert HTML to PDF

I think this is exactly what you were looking for http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html http://code.google.com/p/flying-saucer Flying Saucer’s primary purpose is to render spec-compliant XHTML and CSS 2.1 to the screen as a Swing component. Though it was originally intended for embedding markup into desktop applications (things like the iTunes Music Store), Flying Saucer has been extended work with … Read more

Return generated pdf using spring MVC

You were on the right track with response.getOutputStream(), but you’re not using its output anywhere in your code. Essentially what you need to do is to stream the PDF file’s bytes directly to the output stream and flush the response. In Spring you can do it like this: @RequestMapping(value=”/getpdf”, method=RequestMethod.POST) public ResponseEntity<byte[]> getPDF(@RequestBody String json) … Read more

ITextSharp insert text to an existing pdf

I found a way to do it (dont know if it is the best but it works) string oldFile = “oldFile.pdf”; string newFile = “newFile.pdf”; // open the reader PdfReader reader = new PdfReader(oldFile); Rectangle size = reader.GetPageSizeWithRotation(1); Document document = new Document(size); // open the writer FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write); PdfWriter … Read more