use of com.itextpdf.layout.element.AreaBreak in project i7js-highlevel by itext.
the class JekyllHydeV6 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, PageSize.A4);
// Set column parameters
float offSet = 27;
float gutter = 18;
float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 3 - gutter;
float columnHeight = PageSize.A4.getHeight() - offSet * 2;
// Define column areas
Rectangle[] columns = { new Rectangle(offSet + gutter * 0.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter * 1.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth * 2 + gutter * 2.5f, offSet, columnWidth, columnHeight) };
document.setRenderer(new ColumnDocumentRenderer(document, columns));
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));
boolean chapter = false;
Div div = new Div();
AreaBreak areaBreak = new AreaBreak(AreaBreakType.NEXT_AREA);
String line;
while ((line = br.readLine()) != null) {
div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
div.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0));
while ((line = br.readLine()) != null) {
div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36));
if (line.isEmpty()) {
document.add(div);
if (chapter) {
document.add(areaBreak);
}
div = new Div();
chapter = true;
break;
}
}
}
document.add(div);
// Close document
document.close();
}
use of com.itextpdf.layout.element.AreaBreak in project i7js-highlevel by itext.
the class JekyllHydeV7 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, PageSize.A4);
// Set column parameters
float offSet = 27;
float gutter = 18;
float columnWidth = (PageSize.A4.getWidth() - offSet * 2) / 3 - gutter;
float columnHeight = PageSize.A4.getHeight() - offSet * 2;
// Define column areas
Rectangle[] columns = { new Rectangle(offSet + gutter * 0.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter * 1.5f, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth * 2 + gutter * 2.5f, offSet, columnWidth, columnHeight) };
document.setRenderer(new ColumnDocumentRenderer(document, columns));
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));
boolean chapter = false;
Div div = new Div();
AreaBreak areaBreak = new AreaBreak(AreaBreakType.NEXT_PAGE);
String line;
while ((line = br.readLine()) != null) {
div = new Div().setFont(font).setFontSize(11).setMarginBottom(18);
div.add(new Paragraph(line).setFont(bold).setFontSize(12).setMarginBottom(0));
while ((line = br.readLine()) != null) {
div.add(new Paragraph(line).setMarginBottom(0).setFirstLineIndent(36));
if (line.isEmpty()) {
document.add(div);
if (chapter) {
document.add(areaBreak);
}
div = new Div();
chapter = true;
break;
}
}
}
document.add(div);
// Close document
document.close();
}
use of com.itextpdf.layout.element.AreaBreak in project i7js-highlevel by itext.
the class C06E09_Annotation method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
PdfAction js = PdfAction.createJavaScript("app.alert('Boo!');");
PdfAnnotation la1 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).setHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT).setAction(js).setBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
Link link1 = new Link("here", (PdfLinkAnnotation) la1);
document.add(new Paragraph().add("Click ").add(link1).add(" if you want to be scared."));
// here we need to add a page to the document beforehand, because we'll need to get its instance for destination creation
pdf.addNewPage();
PdfAnnotation la2 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).setDestination(PdfExplicitDestination.createFit(pdf.getPage(2))).setHighlightMode(PdfAnnotation.HIGHLIGHT_PUSH).setBorderStyle(PdfAnnotation.STYLE_INSET);
Link link2 = new Link("next page", (PdfLinkAnnotation) la2);
document.add(new Paragraph().add("Go to the ").add(link2).add(" if you're too scared."));
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
document.add(new Paragraph().add("There, there, everything is OK."));
document.close();
}
use of com.itextpdf.layout.element.AreaBreak in project i7js-highlevel by itext.
the class C07E01_EventHandlers method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
pdf.getCatalog().setPageLayout(PdfName.TwoColumnLeft);
PageRotationEventHandler eventHandler = new PageRotationEventHandler();
pdf.addEventHandler(PdfDocumentEvent.START_PAGE, eventHandler);
Document document = new Document(pdf, PageSize.A8);
document.add(new Paragraph("Dr. Jekyll"));
eventHandler.setRotation(INVERTEDPORTRAIT);
document.add(new AreaBreak());
document.add(new Paragraph("Mr. Hyde"));
eventHandler.setRotation(LANDSCAPE);
document.add(new AreaBreak());
document.add(new Paragraph("Dr. Jekyll"));
eventHandler.setRotation(SEASCAPE);
document.add(new AreaBreak());
document.add(new Paragraph("Mr. Hyde"));
document.close();
}
use of com.itextpdf.layout.element.AreaBreak in project i7js-highlevel by itext.
the class C06E08_ExplicitDestinations method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
// here we need to add pages to the document beforehand, because we'll need to get their instances for destination creation
pdf.addNewPage();
pdf.addNewPage();
PdfDestination jekyll = PdfExplicitDestination.createFitH(pdf.getPage(1), 416);
PdfDestination hyde = PdfExplicitDestination.createXYZ(pdf.getPage(1), 150, 516, 2);
PdfDestination jekyll2 = PdfExplicitDestination.createFitR(pdf.getPage(2), 50, 380, 130, 440);
document.add(new Paragraph().add(new Link("Link to Dr. Jekyll", jekyll)));
document.add(new Paragraph().add(new Link("Link to Mr. Hyde", hyde)));
document.add(new Paragraph().add(new Link("Link to Dr. Jekyll on page 2", jekyll2)));
document.add(new Paragraph().setFixedPosition(50, 400, 80).add("Dr. Jekyll"));
document.add(new Paragraph().setFixedPosition(150, 500, 80).add("Mr. Hyde"));
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
document.add(new Paragraph().setFixedPosition(50, 400, 80).add("Dr. Jekyll on page 2"));
document.close();
}
Aggregations