By the way in which, iText just isn’t an end-user software. Sometimes you received’t apply it to your Desktop as you’ll use Acrobat or every other PDF utility. Reasonably, you’ll construct iText into your individual purposes so as to automate the PDF creation and manipulation course of.
Listed below are a few issues for which you should use iText (Java-PDF Library):
- Serve PDF to a browser
- Generate dynamic paperwork from XML recordsdata or databases
- Use PDF’s many interactive options
- Add bookmarks, web page numbers, watermarks, and so on.
- Cut up, concatenate, and manipulate PDF pages
- Automate filling out of PDF varieties
- Add digital signatures to a PDF file
- Technical Necessities to make use of iText
- It is best to have JDK 1.4 or later to combine iText PDF technology in your utility.
That is additionally one of many high 20 Java libraries I like to recommend Java programmer to be taught. Studying these libraries will significantly enhance your capability as a Java developer.
Getting iText
You may both obtain iText jar from its house web page http://www.lowagie.com/iText/obtain.html
iText core: iText-5.5.13.jar
or you can even obtain from the Maven repository by including iText dependency in your pom.xml file.
iText Maven Dependency
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<model>5.5.13</model>
</dependency>
iText Gradle Dependency
compile group: 'com.itextpdf', identify: 'itextpdf', model: '5.5.13'
iText JARS :
C:m2repositorycomlowagieitext4.2.1itext-4.2.1.jar
C:m2repositoryorgbouncycastlebctsp-jdk141.38bctsp-jdk14-1.38.jar
C:m2repositoryorgbouncycastlebcprov-jdk141.38bcprov-jdk14-1.38.jar
C:m2repositoryorgbouncycastlebcmail-jdk141.38bcmail-jdk14-1.38.jar
C:m2repositoryjfreejfreechart1.0.12jfreechart-1.0.12.jar
C:m2repositoryjfreejcommon1.0.15jcommon-1.0.15.jar
C:m2repositoryorgswinglabspdf-renderer1.0.5pdf-renderer-1.0.5.jar
The right way to create PDF recordsdata/paperwork in Java – iText library Instance
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Date;
import com.lowagie.textual content.Doc;
import com.lowagie.textual content.Paragraph;
import com.lowagie.textual content.pdf.PdfWriter;
public class Testing {
public static void important(String args[]) {
OutputStream file = null;
strive {
file = new FileOutputStream(new File("Contacts.pdf"));
Doc doc = new Doc();
PdfWriter.getInstance(doc, file);
doc.open();
doc.add(new Paragraph("Whats up World, Creating PDF
doc in Java is straightforward"));
doc.add(new Paragraph("You might be buyer # 2345433"));
doc.add(new Paragraph(new Date(new java.util.Date().getTime()).toString()));
doc.addCreationDate();
doc.addAuthor("Javarevisited");
doc.addTitle("The right way to create PDF doc in Java");
doc.addCreator("Because of iText, writing into PDF is straightforward");
doc.shut();
System.out.println("Your PDF File is succesfully created");
} catch (Exception e) {
e.printStackTrace();
} lastly {
strive {
if (file != null) {
file.shut();
}
} catch (IOException io) {
}
}
}
}
Output:
Your PDF File is efficiently created
Including metadata/Setting attributes of PDF utilizing free Java-PDF library
Whilst you generate a PDF, chances are you’ll need to set its totally different attribute like: writer identify, title, file description and so on. iText jar may also help you to set totally different attributes of a PDF file. Doc object present totally different strategies so as to add varied attributes to a PDF file.
doc.addCreationDate();
doc.addAuthor("");
doc.addTitle("The right way to create PDF doc in Java");
doc.addCreator("Because of iText, writing into PDF is straightforward");
That is all on the right way to generate PDF recordsdata in Java utilizing iText. A lot of open supply framework makes use of iText to offer PDF assist of their utility. for instance show tag, which is a well-liked JSP tag library to generate dynamic HTML tables, let you export desk in PDF format. It does this conversion through the use of iText library, so all you want is to incorporate iText.jar in your classpath and growth, you possibly can export PDF paperwork from Java utility.
For those who like this text, chances are you’ll discover the next articles fascinating as nicely:
Thanks for studying this text to date. In case you have any suggestions or questions then please share your ideas by commenting, I extremely recognize your remark and attempt to reply as quickly as doable.