use of com.itextpdf.layout.element.Image 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.Image in project i7js-highlevel by itext.
the class C07E04_ImageWatermark method createPdf.
public void createPdf(String dest) throws IOException {
// Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Image img = new Image(ImageDataFactory.create(IMG));
IEventHandler handler = new TransparentImage(img);
pdf.addEventHandler(PdfDocumentEvent.START_PAGE, handler);
// Initialize document
Document document = new Document(pdf);
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 name, line;
Paragraph p;
boolean title = true;
int counter = 0;
List<SimpleEntry<String, SimpleEntry<String, Integer>>> toc = new ArrayList<>();
while ((line = br.readLine()) != null) {
p = new Paragraph(line);
p.setKeepTogether(true);
if (title) {
name = String.format("title%02d", counter++);
SimpleEntry<String, Integer> titlePage = new SimpleEntry(line, pdf.getNumberOfPages());
p.setFont(bold).setFontSize(12).setKeepWithNext(true).setDestination(name).setNextRenderer(new UpdatePageRenderer(p, titlePage));
title = false;
document.add(p);
toc.add(new SimpleEntry(name, titlePage));
} else {
p.setFirstLineIndent(36);
if (line.isEmpty()) {
p.setMarginBottom(12);
title = true;
} else {
p.setMarginBottom(0);
}
document.add(p);
}
}
pdf.removeEventHandler(PdfDocumentEvent.START_PAGE, handler);
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
p = new Paragraph().setFont(bold).add("Table of Contents").setDestination("toc");
document.add(p);
toc.remove(0);
List<TabStop> tabstops = new ArrayList();
tabstops.add(new TabStop(580, TabAlignment.RIGHT, new DottedLine()));
for (SimpleEntry<String, SimpleEntry<String, Integer>> entry : toc) {
SimpleEntry<String, Integer> text = entry.getValue();
p = new Paragraph().addTabStops(tabstops).add(text.getKey()).add(new Tab()).add(String.valueOf(text.getValue())).setAction(PdfAction.createGoTo(entry.getKey()));
document.add(p);
}
// Close document
document.close();
}
use of com.itextpdf.layout.element.Image in project i7js-highlevel by itext.
the class ImageProperties method createPdf.
public void createPdf(String dest) throws IOException {
// Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
Image img1 = new Image(ImageDataFactory.create(TEST1));
img1.scaleToFit(100, 100).setDestination("Top");
document.add(img1);
Image img2 = new Image(ImageDataFactory.create(TEST2));
img2.setHeight(300);
document.add(img2);
Image img3 = new Image(ImageDataFactory.create(TEST3));
img3.scaleToFit(100, 100);
img3.setBackgroundColor(ColorConstants.BLUE);
document.add(img3);
Image img4 = new Image(ImageDataFactory.create(TEST4));
img4.scaleToFit(100, 100);
img4.setBackgroundColor(ColorConstants.RED);
document.add(img4);
Image img5 = new Image(ImageDataFactory.create(TEST5));
img5.scaleToFit(50, 50);
Style style = new Style();
style.setBorderRight(new SolidBorder(2));
img5.addStyle(style);
document.add(img5);
Image img6 = new Image(ImageDataFactory.create(TEST6));
PdfAction top = PdfAction.createGoTo("Top");
img6.scaleToFit(100, 100).setAction(top);
document.add(img6);
document.close();
}
use of com.itextpdf.layout.element.Image in project pdf-editor by Pdf-Creator.
the class PDFDocument method addRectangleWithFormulaItem.
public void addRectangleWithFormulaItem(FormulaItem formulaItem) throws IOException {
PdfCanvas canvas = new PdfCanvas(currentPage);
Rectangle rect = new Rectangle(formulaItem.getX(), formulaItem.getY(), formulaItem.getW(), formulaItem.getW());
canvas.setStrokeColor(formulaItem.getRectangleStrokeColor()).setFillColor(formulaItem.getRectangleStrokeColor()).rectangle(rect).fill().stroke();
// very strange method
TeXFormula tf = new TeXFormula(formulaItem.getFormula());
TeXIcon ti = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, formulaItem.getFontSize());
BufferedImage bimg = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
// -- painting the formula --
Graphics2D g2d = bimg.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, ti.getIconWidth(), ti.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
ti.paintIcon(jl, g2d, 0, 0);
// --------------------------
// -- adding it to pdf --
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bimg, "png", byteArrayOutputStream);
ImageData data = ImageDataFactory.create(byteArrayOutputStream.toByteArray());
Image image = new Image(data);
image.setFixedPosition(formulaItem.getX(), formulaItem.getY());
image.scaleAbsolute(formulaItem.getW(), formulaItem.getH());
new Canvas(canvas, rect).add(image);
}
use of com.itextpdf.layout.element.Image in project digilib by robcast.
the class PDFStreamWorker method addImage.
/**
* adds an image to the document.
*
* @param doc
* @param iji
* @return
* @throws InterruptedException
* @throws ExecutionException
* @throws IOException
* @throws DocumentException
*/
public Document addImage(Document doc, ImageJobDescription iji) throws InterruptedException, ExecutionException, IOException {
// create image worker
ImageWorker job = new ImageWorker(dlConfig, iji);
// submit
Future<DocuImage> jobTicket = imageJobCenter.submit(job);
// wait for result
DocuImage img = jobTicket.get();
Image pdfimg = new Image(ImageDataFactory.create(img.getAwtImage(), null));
// fit the image to the page
pdfimg.setAutoScale(true);
// add to PDF
doc.add(pdfimg);
return doc;
}
Aggregations