filmov
tv
Java - PDF - How to Create a PDF using Java and IText - Session 2 of the Series

Показать описание
Hello Everyone, lets learn how to create a pdf document using Java.
Here is the sample code used in the video:
public class CreatePDFDocument {
private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED);
private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
public static void main(String[] args) {
try {
Document document = new Document();
addMetaData(document);
addTitlePage(document);
} catch (Exception e) {
}
}
private static void addMetaData(Document document) {
}
private static void addTitlePage(Document document) throws DocumentException {
Paragraph preface = new Paragraph();
// We add one empty line
addEmptyLine(preface, 1);
// Lets write a big header
addEmptyLine(preface, 1);
// Will create: Report generated by: _name, _date
smallBold));
addEmptyLine(preface, 3);
addEmptyLine(preface, 3);
"Hello, Welcome to Khan's Tech Lab",
redFont));
// Start a new page
}
private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i lessthan number; i++) {
}
}
}
Here is the sample code used in the video:
public class CreatePDFDocument {
private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED);
private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
public static void main(String[] args) {
try {
Document document = new Document();
addMetaData(document);
addTitlePage(document);
} catch (Exception e) {
}
}
private static void addMetaData(Document document) {
}
private static void addTitlePage(Document document) throws DocumentException {
Paragraph preface = new Paragraph();
// We add one empty line
addEmptyLine(preface, 1);
// Lets write a big header
addEmptyLine(preface, 1);
// Will create: Report generated by: _name, _date
smallBold));
addEmptyLine(preface, 3);
addEmptyLine(preface, 3);
"Hello, Welcome to Khan's Tech Lab",
redFont));
// Start a new page
}
private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i lessthan number; i++) {
}
}
}