List of usage examples for com.lowagie.text Chunk setRemoteGoto
public Chunk setRemoteGoto(String filename, int page)
Chunk
. From source file:com.develog.utils.report.engine.export.JRPdfExporter.java
License:Open Source License
/** * *//*from w w w. j a v a2 s .co m*/ protected void exportImage(JRPrintImage printImage) throws DocumentException, IOException { pdfContentByte.setRGBColorFill(printImage.getBackcolor().getRed(), printImage.getBackcolor().getGreen(), printImage.getBackcolor().getBlue()); int borderOffset = 0; float borderCorrection = 0f; float lineWidth = 1f; boolean isLineDotted = false; switch (printImage.getPen()) { case JRGraphicElement.PEN_DOTTED: { borderOffset = 0; borderCorrection = 0f; lineWidth = 1f; isLineDotted = true; break; } case JRGraphicElement.PEN_4_POINT: { borderOffset = 2; borderCorrection = 0f; lineWidth = 4f; isLineDotted = false; break; } case JRGraphicElement.PEN_2_POINT: { borderOffset = 1; borderCorrection = 0f; lineWidth = 2f; isLineDotted = false; break; } case JRGraphicElement.PEN_THIN: { borderOffset = 0; borderCorrection = 0.25f; lineWidth = 0.5f; isLineDotted = false; break; } case JRGraphicElement.PEN_NONE: { borderOffset = 0; borderCorrection = 0.5f; lineWidth = 1f; isLineDotted = false; break; } case JRGraphicElement.PEN_1_POINT: default: { borderOffset = 0; borderCorrection = 0f; lineWidth = 1f; isLineDotted = false; break; } } if (printImage.getMode() == JRElement.MODE_OPAQUE) { pdfContentByte.setRGBColorStroke(printImage.getBackcolor().getRed(), printImage.getBackcolor().getGreen(), printImage.getBackcolor().getBlue()); pdfContentByte.setLineWidth(0.1f); pdfContentByte.setLineDash(0f); pdfContentByte.rectangle(printImage.getX() - borderCorrection, jasperPrint.getPageHeight() - printImage.getY() + borderCorrection, printImage.getWidth() + 2 * borderCorrection - 1, -printImage.getHeight() - 2 * borderCorrection + 1); pdfContentByte.fillStroke(); } int availableImageWidth = printImage.getWidth() - 2 * borderOffset; availableImageWidth = (availableImageWidth < 0) ? 0 : availableImageWidth; int availableImageHeight = printImage.getHeight() - 2 * borderOffset; availableImageHeight = (availableImageHeight < 0) ? 0 : availableImageHeight; int xoffset = 0; int yoffset = 0; if (printImage.getImageData() != null && availableImageWidth > 0 && availableImageHeight > 0) { //java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData()); //com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor()); //com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(awtImage, null); com.lowagie.text.Image image = null; float xalignFactor = 0f; switch (printImage.getHorizontalAlignment()) { case JRAlignment.HORIZONTAL_ALIGN_RIGHT: { xalignFactor = 1f; break; } case JRAlignment.HORIZONTAL_ALIGN_CENTER: { xalignFactor = 0.5f; break; } case JRAlignment.HORIZONTAL_ALIGN_LEFT: default: { xalignFactor = 0f; break; } } float yalignFactor = 0f; switch (printImage.getVerticalAlignment()) { case JRAlignment.VERTICAL_ALIGN_BOTTOM: { yalignFactor = 1f; break; } case JRAlignment.VERTICAL_ALIGN_MIDDLE: { yalignFactor = 0.5f; break; } case JRAlignment.VERTICAL_ALIGN_TOP: default: { yalignFactor = 0f; break; } } switch (printImage.getScaleImage()) { case JRImage.SCALE_IMAGE_CLIP: { java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData()); //image = com.lowagie.text.Image.getInstance(awtImage, null); int awtWidth = awtImage.getWidth(null); int awtHeight = awtImage.getHeight(null); xoffset = (int) (xalignFactor * (availableImageWidth - awtWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - awtHeight)); int minWidth = Math.min(awtWidth, availableImageWidth); int minHeight = Math.min(awtHeight, availableImageHeight); BufferedImage bi = new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(printImage.getBackcolor()); g.fillRect(0, 0, minWidth, minHeight); g.drawImage(awtImage, (xoffset > 0 ? 0 : xoffset), (yoffset > 0 ? 0 : yoffset), null); xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); //awtImage = bi.getSubimage(0, 0, minWidth, minHeight); awtImage = bi; //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor()); image = com.lowagie.text.Image.getInstance(awtImage, null); break; } case JRImage.SCALE_IMAGE_FILL_FRAME: { try { image = com.lowagie.text.Image.getInstance(printImage.getImageData()); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData()); image = com.lowagie.text.Image.getInstance(awtImage, null); } image.scaleAbsolute(availableImageWidth, availableImageHeight); break; } case JRImage.SCALE_IMAGE_RETAIN_SHAPE: default: { try { image = com.lowagie.text.Image.getInstance(printImage.getImageData()); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { java.awt.Image awtImage = JRImageLoader.loadImage(printImage.getImageData()); image = com.lowagie.text.Image.getInstance(awtImage, null); } image.scaleToFit(availableImageWidth, availableImageHeight); xoffset = (int) (xalignFactor * (availableImageWidth - image.plainWidth())); yoffset = (int) (yalignFactor * (availableImageHeight - image.plainHeight())); xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); break; } } /* image.setAbsolutePosition( printImage.getX() + borderOffset, jasperPrint.getPageHeight() - printImage.getY() - image.scaledHeight() - borderOffset ); pdfContentByte.addImage(image); */ Chunk chunk = new Chunk(image, -0.5f, 0.5f); if (printImage.getAnchorName() != null) { chunk.setLocalDestination(printImage.getAnchorName()); } switch (printImage.getHyperlinkType()) { case JRHyperlink.HYPERLINK_TYPE_REFERENCE: { if (printImage.getHyperlinkReference() != null) { chunk.setAnchor(printImage.getHyperlinkReference()); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: { if (printImage.getHyperlinkAnchor() != null) { chunk.setLocalGoto(printImage.getHyperlinkAnchor()); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: { if (printImage.getHyperlinkPage() != null) { chunk.setLocalGoto("JR_PAGE_ANCHOR_" + printImage.getHyperlinkPage().toString()); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: { if (printImage.getHyperlinkReference() != null && printImage.getHyperlinkAnchor() != null) { chunk.setRemoteGoto(printImage.getHyperlinkReference(), printImage.getHyperlinkAnchor()); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: { if (printImage.getHyperlinkReference() != null && printImage.getHyperlinkPage() != null) { chunk.setRemoteGoto(printImage.getHyperlinkReference(), printImage.getHyperlinkPage().intValue()); } break; } case JRHyperlink.HYPERLINK_TYPE_NONE: default: { break; } } ColumnText colText = new ColumnText(pdfContentByte); colText.setSimpleColumn(new Phrase(chunk), printImage.getX() + xoffset + borderOffset, jasperPrint.getPageHeight() - printImage.getY() - image.scaledHeight() - yoffset - borderOffset, printImage.getX() + xoffset + borderOffset + image.scaledWidth(), jasperPrint.getPageHeight() - printImage.getY() - yoffset - borderOffset, image.scaledHeight(), Element.ALIGN_LEFT); colText.go(); } if (printImage.getPen() != JRGraphicElement.PEN_NONE) { pdfContentByte.setRGBColorStroke(printImage.getForecolor().getRed(), printImage.getForecolor().getGreen(), printImage.getForecolor().getBlue()); pdfContentByte.setLineWidth(lineWidth); if (isLineDotted) { pdfContentByte.setLineDash(5f, 3f, 0f); } else { pdfContentByte.setLineDash(0f); } pdfContentByte.rectangle(printImage.getX() - borderCorrection, jasperPrint.getPageHeight() - printImage.getY() + borderCorrection, printImage.getWidth() + 2 * borderCorrection - 1, -printImage.getHeight() - 2 * borderCorrection + 1); pdfContentByte.stroke(); } }
From source file:com.develog.utils.report.engine.export.JRPdfExporter.java
License:Open Source License
/** * /*w w w .j a v a2 s .co m*/ */ protected Chunk getHyperlinkInfoChunk(JRPrintText text) { Chunk chunk = new Chunk(EMPTY_STRING); if (text.getAnchorName() != null) { chunk.setLocalDestination(text.getAnchorName()); } switch (text.getHyperlinkType()) { case JRHyperlink.HYPERLINK_TYPE_REFERENCE: { if (text.getHyperlinkReference() != null) { chunk.setAnchor(text.getHyperlinkReference()); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: { if (text.getHyperlinkAnchor() != null) { chunk.setLocalGoto(text.getHyperlinkAnchor()); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: { if (text.getHyperlinkPage() != null) { chunk.setLocalGoto("JR_PAGE_ANCHOR_" + text.getHyperlinkPage().toString()); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: { if (text.getHyperlinkReference() != null && text.getHyperlinkAnchor() != null) { chunk.setRemoteGoto(text.getHyperlinkReference(), text.getHyperlinkAnchor()); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: { if (text.getHyperlinkReference() != null && text.getHyperlinkPage() != null) { chunk.setRemoteGoto(text.getHyperlinkReference(), text.getHyperlinkPage().intValue()); } break; } case JRHyperlink.HYPERLINK_TYPE_NONE: default: { break; } } return chunk; }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
License:Open Source License
/** * *///from www . j a va 2 s .c om protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link) { if (link != null) { switch (link.getHyperlinkTypeValue()) { case REFERENCE: { if (link.getHyperlinkReference() != null) { switch (link.getHyperlinkTargetValue()) { case BLANK: { chunk.setAction(PdfAction.javaScript("if (app.viewerVersion < 7)" + "{this.getURL(\"" + link.getHyperlinkReference() + "\");}" + "else {app.launchURL(\"" + link.getHyperlinkReference() + "\", true);};", pdfWriter)); break; } case SELF: default: { chunk.setAnchor(link.getHyperlinkReference()); break; } } } break; } case LOCAL_ANCHOR: { if (link.getHyperlinkAnchor() != null) { chunk.setLocalGoto(link.getHyperlinkAnchor()); } break; } case LOCAL_PAGE: { if (link.getHyperlinkPage() != null) { chunk.setLocalGoto( JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + link.getHyperlinkPage().toString()); } break; } case REMOTE_ANCHOR: { if (link.getHyperlinkReference() != null && link.getHyperlinkAnchor() != null) { chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkAnchor()); } break; } case REMOTE_PAGE: { if (link.getHyperlinkReference() != null && link.getHyperlinkPage() != null) { chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkPage().intValue()); } break; } case CUSTOM: { if (hyperlinkProducerFactory != null) { String hyperlink = hyperlinkProducerFactory.produceHyperlink(link); if (hyperlink != null) { switch (link.getHyperlinkTargetValue()) { case BLANK: { chunk.setAction( PdfAction.javaScript( "if (app.viewerVersion < 7)" + "{this.getURL(\"" + hyperlink + "\");}" + "else {app.launchURL(\"" + hyperlink + "\", true);};", pdfWriter)); break; } case SELF: default: { chunk.setAnchor(hyperlink); break; } } } } } case NONE: default: { break; } } } }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
License:LGPL
/** * *//*from w w w . j a va2 s . c o m*/ protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link) { switch (link.getHyperlinkType()) { case JRHyperlink.HYPERLINK_TYPE_REFERENCE: { if (link.getHyperlinkReference() != null) { switch (link.getHyperlinkTarget()) { case JRHyperlink.HYPERLINK_TARGET_BLANK: { chunk.setAction(PdfAction.javaScript("if (app.viewerVersion < 7)" + "{this.getURL(\"" + link.getHyperlinkReference() + "\");}" + "else {app.launchURL(\"" + link.getHyperlinkReference() + "\", true);};", pdfWriter)); break; } case JRHyperlink.HYPERLINK_TARGET_SELF: default: { chunk.setAnchor(link.getHyperlinkReference()); break; } } } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: { if (link.getHyperlinkAnchor() != null) { chunk.setLocalGoto(link.getHyperlinkAnchor()); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: { if (link.getHyperlinkPage() != null) { chunk.setLocalGoto(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + link.getHyperlinkPage().toString()); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: { if (link.getHyperlinkReference() != null && link.getHyperlinkAnchor() != null) { chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkAnchor()); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: { if (link.getHyperlinkReference() != null && link.getHyperlinkPage() != null) { chunk.setRemoteGoto(link.getHyperlinkReference(), link.getHyperlinkPage().intValue()); } break; } case JRHyperlink.HYPERLINK_TYPE_CUSTOM: { if (hyperlinkProducerFactory != null) { String hyperlink = hyperlinkProducerFactory.produceHyperlink(link); if (hyperlink != null) { switch (link.getHyperlinkTarget()) { case JRHyperlink.HYPERLINK_TARGET_BLANK: { chunk.setAction( PdfAction.javaScript( "if (app.viewerVersion < 7)" + "{this.getURL(\"" + hyperlink + "\");}" + "else {app.launchURL(\"" + hyperlink + "\", true);};", pdfWriter)); break; } case JRHyperlink.HYPERLINK_TARGET_SELF: default: { chunk.setAnchor(hyperlink); break; } } } } } case JRHyperlink.HYPERLINK_TYPE_NONE: default: { break; } } }