/** * <p> * A primitive attempt at copying links from page <code>sourcePage</code> * of <code>PdfReader reader</code> to page <code>targetPage</code> of * <code>PdfStamper stamper</code>. * </p> * <p> * This method is meant only for the use case at hand, i.e. copying a link * to an external URI without expecting any advanced features. * </p> */ void copyLinks(PdfStamper stamper, int targetPage, PdfReader reader, int sourcePage) { PdfDictionary sourcePageDict = reader.getPageNRelease(sourcePage); PdfArray annotations = sourcePageDict.getAsArray(PdfName.ANNOTS); if (annotations != null && annotations.size() > 0) { for (PdfObject annotationObject : annotations) { annotationObject = PdfReader.getPdfObject(annotationObject); if (!annotationObject.isDictionary()) continue; PdfDictionary annotation = (PdfDictionary) annotationObject; if (!PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE))) continue; PdfArray rectArray = annotation.getAsArray(PdfName.RECT); if (rectArray == null || rectArray.size() < 4) continue; Rectangle rectangle = PdfReader.getNormalizedRectangle(rectArray); PdfName hightLight = annotation.getAsName(PdfName.H); if (hightLight == null) hightLight = PdfAnnotation.HIGHLIGHT_INVERT; PdfDictionary actionDict = annotation.getAsDict(PdfName.A); if (actionDict == null || !PdfName.URI.equals(actionDict.getAsName(PdfName.S))) continue; PdfString urlPdfString = actionDict.getAsString(PdfName.URI); if (urlPdfString == null) continue; PdfAction action = new PdfAction(urlPdfString.toString()); PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(), rectangle, hightLight, action); stamper.addAnnotation(link, targetPage); } } }
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { if(!securityInfoManager.hasPrivilege(LoggedInInfo.getLoggedInInfoFromSession(request), "_report", "r", null)) { throw new SecurityException("missing required security object (_report)"); } String[] demos = request.getParameterValues("demos"); String curUser_no = (String) request.getSession().getAttribute("user"); UserPropertyDAO propertyDao = (UserPropertyDAO) SpringUtils.getBean("UserPropertyDAO"); UserProperty prop; String defaultPrinterNamePDFLabel = ""; Boolean silentPrintPDFLabel = false; prop = propertyDao.getProp(curUser_no, UserProperty.DEFAULT_PRINTER_PDF_ENVELOPE); if (prop != null) { defaultPrinterNamePDFLabel = prop.getValue(); } prop = propertyDao.getProp(curUser_no, UserProperty.DEFAULT_PRINTER_PDF_ENVELOPE_SILENT_PRINT); if (prop != null) { if (prop.getValue().equalsIgnoreCase("yes")) { silentPrintPDFLabel = true; } } String exportPdfJavascript = ""; if (defaultPrinterNamePDFLabel != null && !defaultPrinterNamePDFLabel.isEmpty()) { exportPdfJavascript = "var params = this.getPrintParams();" + "params.pageHandling=params.constants.handling.none;" + "params.printerName='" + defaultPrinterNamePDFLabel + "';"; if (silentPrintPDFLabel == true) { exportPdfJavascript += "params.interactive=params.constants.interactionLevel.silent;"; } exportPdfJavascript += "this.print(params);"; } //TODO: Change to be able to use other size envelopes Rectangle _10Envelope = new Rectangle(0,0,684,297); float marginLeft = 252; float marginRight = 0; float marginTop = 144; float marginBottom = 0; Document document = new Document(_10Envelope,marginLeft,marginRight,marginTop,marginBottom); response.setContentType("application/pdf"); //response.setHeader("Content-Disposition", "attachment; filename=\"envelopePDF-"+UtilDateUtilities.getToday("yyyy-mm-dd.hh.mm.ss")+".pdf\""); response.setHeader("Content-Disposition", "filename=\"envelopePDF-"+UtilDateUtilities.getToday("yyyy-mm-dd.hh.mm.ss")+".pdf\""); try { PdfWriter writer=PdfWriter.getInstance(document, response.getOutputStream()); document.open(); for (int i = 0; i <demos.length;i++){ DemographicData demoData = new DemographicData(); Demographic d = demoData.getDemographic(LoggedInInfo.getLoggedInInfoFromSession(request), demos[i]); String address = d.getAddress()==null ? "" : d.getAddress(); String city = d.getCity()==null ? "" : d.getCity(); String province = d.getProvince()==null ? "" : d.getProvince(); String postal = d.getPostal()==null ? "" : d.getPostal(); String envelopeLabel = d.getFirstName()+" "+d.getLastName()+"\n"+address+"\n"+city+", "+province+"\n"+postal; document.add(getEnvelopeLabel(envelopeLabel)); document.newPage(); } PdfAction action = PdfAction.javaScript(exportPdfJavascript, writer); writer.setOpenAction(action); } catch(DocumentException de) { logger.error("", de); } catch(IOException ioe) { logger.error("", ioe); } document.close(); return null; }
public ExternalLinkDecorator(String url) { super(new PdfAction(url)); this.url = url; }
public PdfActionDecorator(PdfAction action) { super(); this.action = action; }