use of com.itextpdf.layout.element.Div in project i7js-highlevel by itext.
the class C04E01_DivExample1 method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
resultSet.remove(0);
for (List<String> record : resultSet) {
Div div = new Div().setBorderLeft(new SolidBorder(2)).setPaddingLeft(3).setMarginBottom(10);
String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
Link movie = new Link(record.get(2), PdfAction.createURI(url));
div.add(new Paragraph(movie.setFontSize(14))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
if (file.exists()) {
Image img = new Image(ImageDataFactory.create(file.getPath()));
img.scaleToFit(10000, 120);
div.add(img);
}
document.add(div);
}
document.close();
}
use of com.itextpdf.layout.element.Div in project i7js-highlevel by itext.
the class C04E05_ParagraphAndDiv2 method createPdf.
public void createPdf(String dest) throws IOException {
// Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
// Initialize document
Document document = new Document(pdf);
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
document.setTextAlignment(TextAlignment.JUSTIFIED).setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
BufferedReader br = new BufferedReader(new FileReader(SRC));
String line;
Div div = new Div();
while ((line = br.readLine()) != null) {
document.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0).setKeepWithNext(true));
div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
while ((line = br.readLine()) != null) {
div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36));
if (line.isEmpty()) {
document.add(div);
break;
}
}
}
document.add(div);
// Close document
document.close();
}
use of com.itextpdf.layout.element.Div in project i7js-highlevel by itext.
the class C04E02_DivExample2 method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
resultSet.remove(0);
for (List<String> record : resultSet) {
Div div = new Div().setKeepTogether(true).setBorderLeft(new SolidBorder(2)).setPaddingLeft(3).setMarginBottom(10);
String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
Link movie = new Link(record.get(2), PdfAction.createURI(url));
div.add(new Paragraph(movie.setFontSize(14))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
if (file.exists()) {
Image img = new Image(ImageDataFactory.create(file.getPath()));
img.scaleToFit(10000, 120);
div.add(img);
}
document.add(div);
}
document.close();
}
use of com.itextpdf.layout.element.Div in project i7js-highlevel by itext.
the class C07E03_PageXofY method createPdf.
public void createPdf(String dest) throws IOException {
// Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
pdf.addEventHandler(PdfDocumentEvent.START_PAGE, new Header("The Strange Case of Dr. Jekyll and Mr. Hyde"));
PageXofY event = new PageXofY(pdf);
pdf.addEventHandler(PdfDocumentEvent.END_PAGE, event);
// Initialize document
Document document = new Document(pdf);
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
document.setTextAlignment(TextAlignment.JUSTIFIED).setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
BufferedReader br = new BufferedReader(new FileReader(SRC));
String line;
Div div = new Div();
while ((line = br.readLine()) != null) {
document.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0).setKeepWithNext(true));
div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
while ((line = br.readLine()) != null) {
div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36).setMultipliedLeading(1.2f));
if (line.isEmpty()) {
document.add(div);
break;
}
}
}
document.add(div);
event.writeTotal(pdf);
// Close document
document.close();
}
use of com.itextpdf.layout.element.Div in project i7js-highlevel by itext.
the class C07E02_TextWatermark method createPdf.
public void createPdf(String dest) throws IOException {
// Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
pdf.addEventHandler(PdfDocumentEvent.END_PAGE, new TextWatermark());
// Initialize document
Document document = new Document(pdf);
PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
document.setTextAlignment(TextAlignment.JUSTIFIED).setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
BufferedReader br = new BufferedReader(new FileReader(SRC));
String line;
Div div = new Div();
while ((line = br.readLine()) != null) {
document.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0).setKeepWithNext(true));
div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
while ((line = br.readLine()) != null) {
div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36).setMultipliedLeading(1.2f));
if (line.isEmpty()) {
document.add(div);
break;
}
}
}
document.add(div);
// Close document
document.close();
}
Aggregations