List of usage examples for com.lowagie.text Chunk Chunk
public Chunk(Image image, float offsetX, float offsetY, boolean changeLeading)
Image
. From source file:datasoul.servicelist.ServiceListExporterDocument.java
License:Open Source License
private LinkedList<Paragraph> addChordsShape(ArrayList<String> chordsName) throws DocumentException { ChordsDB chordsDB = ChordsDB.getInstance(); String notCatalogued = ""; LinkedList<Chunk> images = new LinkedList<Chunk>(); LinkedList<File> filesToDelete = new LinkedList<File>(); LinkedList<Paragraph> ret = new LinkedList<Paragraph>(); for (int i = 0; i < chordsName.size(); i++) { Chord chord = chordsDB.getChordByName(chordsName.get(i)); if (chord != null) { ChordShapePanel csp = new ChordShapePanel(2, chord.getName(), chord.getShape()); BufferedImage im = csp.createImage(); try { File tmp = File.createTempFile("datasoul-img", ".png"); tmp.deleteOnExit();/* ww w . j a va 2 s. c om*/ filesToDelete.add(tmp); ImageIO.write(im, "png", tmp); Chunk c = new Chunk(Image.getInstance(tmp.getAbsolutePath()), 0, 0, false); images.add(c); } catch (IOException e) { JOptionPane.showMessageDialog(null, java.util.ResourceBundle .getBundle("datasoul/internationalize").getString("INTERNAL ERROR: ") + e.getMessage()); } } else { notCatalogued += chordsName.get(i); } } Paragraph p = new Paragraph(); if (!images.isEmpty()) { for (Chunk c : images) { p.add(c); } p.setLeading(images.getFirst().getImage().getScaledHeight()); p.setKeepTogether(true); } ret.add(p); if (!notCatalogued.equals("")) { p = new Paragraph( java.util.ResourceBundle.getBundle("datasoul/internationalize") .getString("THE FOLLOWING CHORDS ARE NOT CATALOGED: ") + notCatalogued, FontFactory.getFont(FontFactory.HELVETICA, 8)); ret.add(p); } for (File f : filesToDelete) { try { f.delete(); } catch (Exception e) { //ignore, it will be deleted on exit } } return ret; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java
License:Open Source License
@Override protected void visitPicture(CTPicture picture, Float offsetX, org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromH.Enum relativeFromH, Float offsetY,/*from ww w . j a v a 2s . c om*/ org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromV.Enum relativeFromV, STWrapText.Enum wrapText, IITextContainer pdfParentContainer) throws Exception { CTPositiveSize2D ext = picture.getSpPr().getXfrm().getExt(); long x = ext.getCx(); long y = ext.getCy(); byte[] pictureData = super.getPictureBytes(picture); if (pictureData != null) { try { Image img = Image.getInstance(pictureData); img.scaleAbsolute(emu2points(x), emu2points(y)); IITextContainer parentOfParentContainer = pdfParentContainer.getITextContainer(); if (parentOfParentContainer != null && parentOfParentContainer instanceof PdfPCell) { parentOfParentContainer.addElement(img); } else { float chunkOffsetX = 0; if (offsetX != null) { if (STRelFromH.CHARACTER.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.COLUMN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.INSIDE_MARGIN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.LEFT_MARGIN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.MARGIN.equals(relativeFromH)) { chunkOffsetX = pdfDocument.left() + offsetX; } else if (STRelFromH.OUTSIDE_MARGIN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.PAGE.equals(relativeFromH)) { chunkOffsetX = offsetX - pdfDocument.left(); } } float chunkOffsetY = 0; boolean useExtendedImage = false; if (STRelFromV.PARAGRAPH.equals(relativeFromV)) { useExtendedImage = true; } if (useExtendedImage) { ExtendedImage extImg = new ExtendedImage(img, -offsetY); if (STRelFromV.PARAGRAPH.equals(relativeFromV)) { chunkOffsetY = -extImg.getScaledHeight(); } Chunk chunk = new Chunk(extImg, chunkOffsetX, chunkOffsetY, false); pdfParentContainer.addElement(chunk); } /* * float chunkOffsetY = 0; if ( wrapText != null ) { chunkOffsetY = -img.getScaledHeight(); } * boolean useExtendedImage = offsetY != null; // if ( STRelFromV.PARAGRAPH.equals( relativeFromV ) * ) // { // useExtendedImage = true; // } // if ( useExtendedImage ) { float imgY = -offsetY; if ( * pdfHeader != null ) { float headerY = pdfHeader.getY() != null ? pdfHeader.getY() : 0; imgY += - * img.getScaledHeight() + headerY; } ExtendedImage extImg = new ExtendedImage( img, imgY ); // if ( * STRelFromV.PARAGRAPH.equals( relativeFromV ) ) // { // chunkOffsetY = -extImg.getScaledHeight(); * // } Chunk chunk = new Chunk( extImg, chunkOffsetX, chunkOffsetY, false ); * pdfParentContainer.addElement( chunk ); } */ else { if (pdfParentContainer instanceof Paragraph) { // I don't know why but we need add some spacing before in the paragraph // otherwise the image cut the text of the below paragraph (see FormattingTests JUnit)? Paragraph paragraph = (Paragraph) pdfParentContainer; paragraph.setSpacingBefore(paragraph.getSpacingBefore() + 5f); } pdfParentContainer.addElement(new Chunk(img, chunkOffsetX, chunkOffsetY, false)); } } } catch (Exception e) { LOGGER.severe(e.getMessage()); } } }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected void visitPicture(CTPicture picture, Float offsetX, org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromH.Enum relativeFromH, Float offsetY,//from w w w . jav a2 s .c om org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.STRelFromV.Enum relativeFromV, STWrapText.Enum wrapText, IITextContainer pdfParentContainer) throws Exception { CTPositiveSize2D ext = picture.getSpPr().getXfrm().getExt(); long x = ext.getCx(); long y = ext.getCy(); XWPFPictureData pictureData = super.getPictureData(picture); if (pictureData != null) { try { Image img = Image.getInstance(pictureData.getData()); img.scaleAbsolute(emu2points(x), emu2points(y)); IITextContainer parentOfParentContainer = pdfParentContainer.getITextContainer(); if (parentOfParentContainer != null && parentOfParentContainer instanceof PdfPCell) { parentOfParentContainer.addElement(img); } else { float chunkOffsetX = 0; if (offsetX != null) { if (STRelFromH.CHARACTER.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.COLUMN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.INSIDE_MARGIN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.LEFT_MARGIN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.MARGIN.equals(relativeFromH)) { chunkOffsetX = pdfDocument.left() + offsetX; } else if (STRelFromH.OUTSIDE_MARGIN.equals(relativeFromH)) { chunkOffsetX = offsetX; } else if (STRelFromH.PAGE.equals(relativeFromH)) { chunkOffsetX = offsetX - pdfDocument.left(); } } float chunkOffsetY = 0; boolean useExtendedImage = false; if (STRelFromV.PARAGRAPH.equals(relativeFromV)) { useExtendedImage = true; } if (useExtendedImage) { ExtendedImage extImg = new ExtendedImage(img, -offsetY); if (STRelFromV.PARAGRAPH.equals(relativeFromV)) { chunkOffsetY = -extImg.getScaledHeight(); } Chunk chunk = new Chunk(extImg, chunkOffsetX, chunkOffsetY, false); pdfParentContainer.addElement(chunk); } /* * float chunkOffsetY = 0; if ( wrapText != null ) { * chunkOffsetY = -img.getScaledHeight(); } boolean * useExtendedImage = offsetY != null; // if ( * STRelFromV.PARAGRAPH.equals( relativeFromV ) ) // { // * useExtendedImage = true; // } // if ( useExtendedImage ) * { float imgY = -offsetY; if ( pdfHeader != null ) { float * headerY = pdfHeader.getY() != null ? pdfHeader.getY() : * 0; imgY += - img.getScaledHeight() + headerY; } * ExtendedImage extImg = new ExtendedImage( img, imgY ); // * if ( STRelFromV.PARAGRAPH.equals( relativeFromV ) ) // { * // chunkOffsetY = -extImg.getScaledHeight(); // } Chunk * chunk = new Chunk( extImg, chunkOffsetX, chunkOffsetY, * false ); pdfParentContainer.addElement( chunk ); } */ else { if (pdfParentContainer instanceof Paragraph) { // I don't know why but we need add some spacing // before in the paragraph // otherwise the image cut the text of the below // paragraph (see FormattingTests JUnit)? Paragraph paragraph = (Paragraph) pdfParentContainer; paragraph.setSpacingBefore(paragraph.getSpacingBefore() + 5f); } pdfParentContainer.addElement(new Chunk(img, chunkOffsetX, chunkOffsetY, false)); } } } catch (Exception e) { LOGGER.severe(e.getMessage()); } } }
From source file:org.mapfish.print.PDFUtils.java
License:Open Source License
public static Chunk createImageChunk(RenderingContext context, double maxWidth, double maxHeight, URI url, float rotation) throws DocumentException { final Image image = createImage(context, maxWidth, maxHeight, url, rotation); return new Chunk(image, 0f, 0f, true); }
From source file:org.mapfish.print.TotalPageNum.java
License:Open Source License
public Chunk createPlaceHolder() throws BadElementException { float width = totalPageNumFont.getWidthPoint(SAMPLE_VALUE, totalPageNumFontSize); float height = totalPageNumFont.getAscentPoint(SAMPLE_VALUE, totalPageNumFontSize) - totalPageNumFont.getDescentPoint(SAMPLE_VALUE, totalPageNumFontSize); if (totalPageNum == null) { totalPageNum = dc.createTemplate(width, height); }/* w ww.j a v a 2 s . c om*/ Image image = Image.getInstance(totalPageNum); return new Chunk(image, 0, 0, true); }