Search in sources :

Example 36 with HashPrintRequestAttributeSet

use of javax.print.attribute.HashPrintRequestAttributeSet in project ofbiz-framework by apache.

the class OutputServices method sendPrintFromScreen.

public static Map<String, Object> sendPrintFromScreen(DispatchContext dctx, Map<String, ? extends Object> serviceContext) {
    Locale locale = (Locale) serviceContext.get("locale");
    VisualTheme visualTheme = (VisualTheme) serviceContext.get("visualTheme");
    String screenLocation = (String) serviceContext.remove("screenLocation");
    Map<String, Object> screenContext = UtilGenerics.checkMap(serviceContext.remove("screenContext"));
    String contentType = (String) serviceContext.remove("contentType");
    String printerContentType = (String) serviceContext.remove("printerContentType");
    if (UtilValidate.isEmpty(screenContext)) {
        screenContext = new HashMap<>();
    }
    screenContext.put("locale", locale);
    if (UtilValidate.isEmpty(contentType)) {
        contentType = "application/postscript";
    }
    if (UtilValidate.isEmpty(printerContentType)) {
        printerContentType = contentType;
    }
    try {
        MapStack<String> screenContextTmp = MapStack.create();
        screenContextTmp.put("locale", locale);
        Writer writer = new StringWriter();
        // substitute the freemarker variables...
        ScreenStringRenderer foScreenStringRenderer = new MacroScreenRenderer(visualTheme.getModelTheme().getType("screenfop"), visualTheme.getModelTheme().getScreenRendererLocation("screenfop"));
        ScreenRenderer screensAtt = new ScreenRenderer(writer, screenContextTmp, foScreenStringRenderer);
        screensAtt.populateContextForService(dctx, screenContext);
        screenContextTmp.putAll(screenContext);
        screensAtt.getContext().put("formStringRenderer", foFormRenderer);
        screensAtt.render(screenLocation);
        // create the input stream for the generation
        StreamSource src = new StreamSource(new StringReader(writer.toString()));
        // create the output stream for the generation
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Fop fop = ApacheFopWorker.createFopInstance(baos, MimeConstants.MIME_PDF);
        ApacheFopWorker.transform(src, null, fop);
        baos.flush();
        baos.close();
        // Print is sent
        DocFlavor psInFormat = new DocFlavor.INPUT_STREAM(printerContentType);
        InputStream bais = new ByteArrayInputStream(baos.toByteArray());
        DocAttributeSet docAttributeSet = new HashDocAttributeSet();
        List<Object> docAttributes = UtilGenerics.checkList(serviceContext.remove("docAttributes"));
        if (UtilValidate.isNotEmpty(docAttributes)) {
            for (Object da : docAttributes) {
                Debug.logInfo("Adding DocAttribute: " + da, module);
                docAttributeSet.add((DocAttribute) da);
            }
        }
        Doc myDoc = new SimpleDoc(bais, psInFormat, docAttributeSet);
        PrintService printer = null;
        // lookup the print service for the supplied printer name
        String printerName = (String) serviceContext.remove("printerName");
        if (UtilValidate.isNotEmpty(printerName)) {
            PrintServiceAttributeSet printServiceAttributes = new HashPrintServiceAttributeSet();
            printServiceAttributes.add(new PrinterName(printerName, locale));
            PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, printServiceAttributes);
            if (printServices.length > 0) {
                printer = printServices[0];
                Debug.logInfo("Using printer: " + printer.getName(), module);
                if (!printer.isDocFlavorSupported(psInFormat)) {
                    return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotSupportDocFlavorFormat", UtilMisc.toMap("psInFormat", psInFormat, "printerName", printer.getName()), locale));
                }
            }
            if (printer == null) {
                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotFound", UtilMisc.toMap("printerName", printerName), locale));
            }
        } else {
            // if no printer name was supplied, try to get the default printer
            printer = PrintServiceLookup.lookupDefaultPrintService();
            if (printer != null) {
                Debug.logInfo("No printer name supplied, using default printer: " + printer.getName(), module);
            }
        }
        if (printer == null) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotAvailable", locale));
        }
        PrintRequestAttributeSet praset = new HashPrintRequestAttributeSet();
        List<Object> printRequestAttributes = UtilGenerics.checkList(serviceContext.remove("printRequestAttributes"));
        if (UtilValidate.isNotEmpty(printRequestAttributes)) {
            for (Object pra : printRequestAttributes) {
                Debug.logInfo("Adding PrintRequestAttribute: " + pra, module);
                praset.add((PrintRequestAttribute) pra);
            }
        }
        DocPrintJob job = printer.createPrintJob();
        job.print(myDoc, praset);
    } catch (PrintException | IOException | TemplateException | GeneralException | SAXException | ParserConfigurationException e) {
        Debug.logError(e, "Error rendering [" + contentType + "]: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentRenderingError", UtilMisc.toMap("contentType", contentType, "errorString", e.toString()), locale));
    }
    return ServiceUtil.returnSuccess();
}
Also used : Locale(java.util.Locale) MacroScreenRenderer(org.apache.ofbiz.widget.renderer.macro.MacroScreenRenderer) ScreenRenderer(org.apache.ofbiz.widget.renderer.ScreenRenderer) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashDocAttributeSet(javax.print.attribute.HashDocAttributeSet) DocAttributeSet(javax.print.attribute.DocAttributeSet) PrintService(javax.print.PrintService) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) SAXException(org.xml.sax.SAXException) PrintException(javax.print.PrintException) StringWriter(java.io.StringWriter) SimpleDoc(javax.print.SimpleDoc) StringReader(java.io.StringReader) Doc(javax.print.Doc) SimpleDoc(javax.print.SimpleDoc) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) GeneralException(org.apache.ofbiz.base.util.GeneralException) HashDocAttributeSet(javax.print.attribute.HashDocAttributeSet) TemplateException(freemarker.template.TemplateException) Fop(org.apache.fop.apps.Fop) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocPrintJob(javax.print.DocPrintJob) IOException(java.io.IOException) ScreenStringRenderer(org.apache.ofbiz.widget.renderer.ScreenStringRenderer) MacroScreenRenderer(org.apache.ofbiz.widget.renderer.macro.MacroScreenRenderer) PrinterName(javax.print.attribute.standard.PrinterName) ByteArrayInputStream(java.io.ByteArrayInputStream) VisualTheme(org.apache.ofbiz.widget.renderer.VisualTheme) DocFlavor(javax.print.DocFlavor) Writer(java.io.Writer) StringWriter(java.io.StringWriter) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 37 with HashPrintRequestAttributeSet

use of javax.print.attribute.HashPrintRequestAttributeSet in project pdfbox by apache.

the class PDFDebugger method printMenuItemActionPerformed.

private void printMenuItemActionPerformed(ActionEvent evt) {
    if (document == null) {
        return;
    }
    try {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPageable(new PDFPageable(document));
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        PDViewerPreferences vp = document.getDocumentCatalog().getViewerPreferences();
        if (vp != null && vp.getDuplex() != null) {
            String dp = vp.getDuplex();
            if (PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp)) {
                pras.add(Sides.TWO_SIDED_LONG_EDGE);
            } else if (PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp)) {
                pras.add(Sides.TWO_SIDED_SHORT_EDGE);
            } else if (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp)) {
                pras.add(Sides.ONE_SIDED);
            }
        }
        if (job.printDialog(pras)) {
            job.print(pras);
        }
    } catch (PrinterException e) {
        throw new RuntimeException(e);
    }
}
Also used : PDFPageable(org.apache.pdfbox.printing.PDFPageable) COSString(org.apache.pdfbox.cos.COSString) PrinterException(java.awt.print.PrinterException) PDViewerPreferences(org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Example 38 with HashPrintRequestAttributeSet

use of javax.print.attribute.HashPrintRequestAttributeSet in project opt4j by felixreimann.

the class PlotFrame method _printCrossPlatform.

/**
 * Print using the cross platform dialog. FIXME: this dialog is slow and is
 * often hidden behind other windows. However, it does honor the user's
 * choice of portrait vs. landscape
 */
protected void _printCrossPlatform() {
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(plot);
    if (job.printDialog(aset)) {
        try {
            job.print(aset);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Printing failed:\n" + ex.toString(), "Print Error", JOptionPane.WARNING_MESSAGE);
        }
    }
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Example 39 with HashPrintRequestAttributeSet

use of javax.print.attribute.HashPrintRequestAttributeSet in project antlr4 by tunnelvisionlabs.

the class GraphicsSupport method saveImage.

public static void saveImage(final JComponent comp, String fileName) throws IOException, PrintException {
    if (fileName.endsWith(".ps") || fileName.endsWith(".eps")) {
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mimeType = "application/postscript";
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);
        System.out.println(Arrays.toString(factories));
        if (factories.length > 0) {
            FileOutputStream out = new FileOutputStream(fileName);
            PrintService service = factories[0].getPrintService(out);
            SimpleDoc doc = new SimpleDoc(new Printable() {

                @Override
                public int print(Graphics g, PageFormat pf, int page) {
                    if (page >= 1)
                        return Printable.NO_SUCH_PAGE;
                    else {
                        Graphics2D g2 = (Graphics2D) g;
                        g2.translate((pf.getWidth() - pf.getImageableWidth()) / 2, (pf.getHeight() - pf.getImageableHeight()) / 2);
                        if (comp.getWidth() > pf.getImageableWidth() || comp.getHeight() > pf.getImageableHeight()) {
                            double sf1 = pf.getImageableWidth() / (comp.getWidth() + 1);
                            double sf2 = pf.getImageableHeight() / (comp.getHeight() + 1);
                            double s = Math.min(sf1, sf2);
                            g2.scale(s, s);
                        }
                        comp.paint(g);
                        return Printable.PAGE_EXISTS;
                    }
                }
            }, flavor, null);
            DocPrintJob job = service.createPrintJob();
            PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
            job.print(doc, attributes);
            out.close();
        }
    } else {
        // parrt: works with [image/jpeg, image/png, image/x-png, image/vnd.wap.wbmp, image/bmp, image/gif]
        Rectangle rect = comp.getBounds();
        BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = (Graphics2D) image.getGraphics();
        g.setColor(Color.WHITE);
        g.fill(rect);
        // g.setColor(Color.BLACK);
        comp.paint(g);
        String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
        boolean result = ImageIO.write(image, extension, new File(fileName));
        if (!result) {
            System.err.println("Now imager for " + extension);
        }
        g.dispose();
    }
}
Also used : Rectangle(java.awt.Rectangle) DocPrintJob(javax.print.DocPrintJob) BufferedImage(java.awt.image.BufferedImage) PrintService(javax.print.PrintService) Graphics2D(java.awt.Graphics2D) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) Graphics(java.awt.Graphics) PageFormat(java.awt.print.PageFormat) SimpleDoc(javax.print.SimpleDoc) FileOutputStream(java.io.FileOutputStream) Printable(java.awt.print.Printable) DocFlavor(javax.print.DocFlavor) StreamPrintServiceFactory(javax.print.StreamPrintServiceFactory) File(java.io.File) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 40 with HashPrintRequestAttributeSet

use of javax.print.attribute.HashPrintRequestAttributeSet in project lar_361 by comitsrl.

the class ReportStarterWithTxtExporter method startProcess.

/**
 *  Start the process.
 *  Called then pressing the Process button in R_Request.
 *  It should only return false, if the function could not be performed
 *  as this causes the process to abort.
 *  @author rlemeill
 *  @param ctx context
 *  @param pi standard process info
 *  @param trx
 *  @return true if success
 */
public boolean startProcess(Properties ctx, ProcessInfo pi, Trx trx) {
    processInfo = pi;
    String Name = pi.getTitle();
    int AD_PInstance_ID = pi.getAD_PInstance_ID();
    int Record_ID = pi.getRecord_ID();
    log.info("Name=" + Name + "  AD_PInstance_ID=" + AD_PInstance_ID + " Record_ID=" + Record_ID);
    String trxName = null;
    if (trx != null) {
        trxName = trx.getTrxName();
    }
    ReportData reportData = getReportData(pi, trxName);
    if (reportData == null) {
        reportResult(AD_PInstance_ID, "Can not find report data", trxName);
        return false;
    }
    String reportPath = reportData.getReportFilePath();
    if (Util.isEmpty(reportPath, true)) {
        reportResult(AD_PInstance_ID, "Can not find report", trxName);
        return false;
    }
    JasperData data = null;
    File reportFile = null;
    String fileExtension = "";
    HashMap<String, Object> params = new HashMap<String, Object>();
    addProcessParameters(AD_PInstance_ID, params, trxName);
    addProcessInfoParameters(params, pi.getParameter());
    reportFile = getReportFile(reportPath, (String) params.get("ReportType"));
    if (reportFile == null || reportFile.exists() == false) {
        log.severe("No report file found for given type, falling back to " + reportPath);
        reportFile = getReportFile(reportPath);
    }
    if (reportFile == null || reportFile.exists() == false) {
        String tmp = "Can not find report file at path - " + reportPath;
        log.severe(tmp);
        reportResult(AD_PInstance_ID, tmp, trxName);
    }
    if (reportFile != null) {
        data = processReport(reportFile);
        fileExtension = reportFile.getName().substring(reportFile.getName().lastIndexOf("."), reportFile.getName().length());
    } else {
        return false;
    }
    JasperReport jasperReport = data.getJasperReport();
    String jasperName = data.getJasperName();
    String name = jasperReport.getName();
    File reportDir = data.getReportDir();
    // Add reportDir to class path
    ClassLoader scl = ClassLoader.getSystemClassLoader();
    try {
        java.net.URLClassLoader ucl = new java.net.URLClassLoader(new java.net.URL[] { reportDir.toURI().toURL() }, scl);
        net.sf.jasperreports.engine.util.JRResourcesUtil.setThreadClassLoader(ucl);
    } catch (MalformedURLException me) {
        log.warning("Could not add report directory to classpath: " + me.getMessage());
    }
    if (jasperReport != null) {
        File[] subreports;
        // Subreports
        if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
            // Locate and download subreports from remote webcontext
            subreports = getHttpSubreports(jasperName + "Subreport", reportPath, fileExtension);
        } else if (reportPath.startsWith("attachment:")) {
            subreports = getAttachmentSubreports(reportPath);
        } else if (reportPath.startsWith("resource:")) {
            subreports = getResourceSubreports(name + "Subreport", reportPath, fileExtension);
        } else // TODO: Implement file:/ lookup for subreports
        {
            // Locate subreports from local/remote filesystem
            subreports = reportDir.listFiles(new FileFilter(jasperName + "Subreport", reportDir, fileExtension));
        }
        for (int i = 0; i < subreports.length; i++) {
            // @Trifon - begin
            if (subreports[i].getName().toLowerCase().endsWith(".jasper") || subreports[i].getName().toLowerCase().endsWith(".jrxml")) {
                JasperData subData = processReport(subreports[i]);
                if (subData.getJasperReport() != null) {
                    params.put(subData.getJasperName(), subData.getJasperFile().getAbsolutePath());
                }
            }
        // @Trifon - end
        }
        if (Record_ID > 0)
            params.put("RECORD_ID", new Integer(Record_ID));
        // contribution from Ricardo (ralexsander)
        // in iReports you can 'SELECT' AD_Client_ID, AD_Org_ID and AD_User_ID using only AD_PINSTANCE_ID
        params.put("AD_PINSTANCE_ID", new Integer(AD_PInstance_ID));
        // FR [3123850] - Add continuosly needed parameters to Jasper Starter - Carlos Ruiz - GlobalQSS
        params.put("AD_CLIENT_ID", new Integer(Env.getAD_Client_ID(Env.getCtx())));
        params.put("AD_ROLE_ID", new Integer(Env.getAD_Role_ID(Env.getCtx())));
        params.put("AD_USER_ID", new Integer(Env.getAD_User_ID(Env.getCtx())));
        Language currLang = Env.getLanguage(Env.getCtx());
        String printerName = null;
        MPrintFormat printFormat = null;
        PrintInfo printInfo = null;
        ProcessInfoParameter[] pip = pi.getParameter();
        // Get print format and print info parameters
        if (pip != null) {
            for (int i = 0; i < pip.length; i++) {
                if (ReportCtl.PARAM_PRINT_FORMAT.equalsIgnoreCase(pip[i].getParameterName())) {
                    printFormat = (MPrintFormat) pip[i].getParameter();
                }
                if (ReportCtl.PARAM_PRINT_INFO.equalsIgnoreCase(pip[i].getParameterName())) {
                    printInfo = (PrintInfo) pip[i].getParameter();
                }
                if (ReportCtl.PARAM_PRINTER_NAME.equalsIgnoreCase(pip[i].getParameterName())) {
                    printerName = (String) pip[i].getParameter();
                }
            }
        }
        if (printFormat != null) {
            if (printInfo != null) {
                // Set the language of the print format if we're printing a document
                if (printInfo.isDocument()) {
                    currLang = printFormat.getLanguage();
                }
            }
            // Set printer name unless already set.
            if (printerName == null) {
                printerName = printFormat.getPrinterName();
            }
        }
        params.put("CURRENT_LANG", currLang.getAD_Language());
        params.put(JRParameter.REPORT_LOCALE, currLang.getLocale());
        // Resources
        File resFile = null;
        if (reportPath.startsWith("attachment:") && attachment != null) {
            resFile = getAttachmentResourceFile(jasperName, currLang);
        } else if (reportPath.startsWith("resource:")) {
            resFile = getResourcesForResourceFile(jasperName, currLang);
        // TODO: Implement file:/ for resources
        } else {
            resFile = new File(jasperName + "_" + currLang.getLocale().getLanguage() + ".properties");
            if (!resFile.exists()) {
                resFile = null;
            }
            if (resFile == null) {
                resFile = new File(jasperName + ".properties");
                if (!resFile.exists()) {
                    resFile = null;
                }
            }
        }
        if (resFile != null) {
            try {
                PropertyResourceBundle res = new PropertyResourceBundle(new FileInputStream(resFile));
                params.put("RESOURCE", res);
            } catch (IOException e) {
                ;
            }
        }
        Connection conn = null;
        try {
            conn = getConnection();
            jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
            // @Marcos Custom - begin
            log.info("ReportStarterWithTxtExporter.startProcess print report -" + jasperPrint.getName());
            String Param_Inicial;
            String Param_Final;
            if (params.containsKey("FECHA_INICIAL_Info1"))
                Param_Inicial = params.get("FECHA_INICIAL_Info1").toString();
            else
                Param_Inicial = "";
            if (params.containsKey("FECHA_FINAL_Info1"))
                Param_Final = "_al_" + params.get("FECHA_FINAL_Info1").toString();
            else
                Param_Final = "";
            String fileName = new String(jasperPrint.getName() + "_" + Param_Inicial.replace("/", "-") + Param_Final.replace("/", "-") + ".txt");
            JRTextExporter jrtxt = new JRTextExporter();
            File destFile = new File(fileName);
            Integer PageWidth = jasperPrint.getPageWidth();
            Integer CharWidth = 10;
            Integer Par_PageWidth = PageWidth / CharWidth;
            jrtxt.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            jrtxt.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
            jrtxt.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Float(10));
            jrtxt.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Float(20));
            jrtxt.setParameter(JRTextExporterParameter.PAGE_WIDTH, Par_PageWidth.floatValue());
            try {
                jrtxt.exportReport();
                log.info("Archivo Exportado: ");
                if (Env.getWindow(0) != null)
                    ADialog.info(0, Env.getWindow(0), "Archivo Exportado:", fileName);
            } catch (JRException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            // @Marcos Custom - end
            if (reportData.isDirectPrint()) {
                log.info("ReportStarterWithTxtExporter.startProcess print report -" + jasperPrint.getName());
                // RF 1906632
                if (!processInfo.isBatch()) {
                    // Get printer job
                    PrinterJob printerJob = org.compiere.print.CPrinter.getPrinterJob(printerName);
                    // Set print request attributes
                    // Paper Attributes:
                    PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
                    // add:				copies, job-name, priority
                    if (// @Trifon
                    printInfo == null || printInfo.isDocumentCopy() || printInfo.getCopies() < 1)
                        prats.add(new Copies(1));
                    else
                        prats.add(new Copies(printInfo.getCopies()));
                    Locale locale = Language.getLoginLanguage().getLocale();
                    // @Trifon
                    String printFormat_name = printFormat == null ? "" : printFormat.getName();
                    int numCopies = printInfo == null ? 0 : printInfo.getCopies();
                    prats.add(new JobName(printFormat_name + "_" + pi.getRecord_ID(), locale));
                    prats.add(PrintUtil.getJobPriority(jasperPrint.getPages().size(), numCopies, true));
                    // Create print service exporter
                    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
                    ;
                    // Set parameters
                    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, printerJob.getPrintService());
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printerJob.getPrintService().getAttributes());
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, prats);
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
                    // Print report / document
                    exporter.exportReport();
                } else {
                    // Used For the PH
                    try {
                        File PDF = File.createTempFile("mail", ".pdf");
                        JasperExportManager.exportReportToPdfFile(jasperPrint, PDF.getAbsolutePath());
                        processInfo.setPDFReport(PDF);
                    } catch (IOException e) {
                        log.severe("ReportStarterWithTxtExporter.startProcess: Can not make PDF File - " + e.getMessage());
                    }
                }
            // You can use JasperPrint to create PDF
            // JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
            } else {
            // @Marcos : ProcessCtl.java llama a ReportStarter y se vuelve a generar la visualizacion del reporte.
            // log.info( "ReportStarterWithTxtExporter.startProcess run report -"+jasperPrint.getName());
            // JRViewerProvider viewerLauncher = getReportViewerProvider();
            // viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
            }
        } catch (JRException e) {
            log.severe("ReportStarterWithTxtExporter.startProcess: Can not run report - " + e.getMessage());
        } finally {
            if (conn != null)
                try {
                    conn.close();
                } catch (SQLException e) {
                }
        }
    }
    reportResult(AD_PInstance_ID, null, trxName);
    return true;
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) JRTextExporter(net.sf.jasperreports.engine.export.JRTextExporter) JRException(net.sf.jasperreports.engine.JRException) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) JobName(javax.print.attribute.standard.JobName) PrintInfo(org.compiere.model.PrintInfo) JasperReport(net.sf.jasperreports.engine.JasperReport) PropertyResourceBundle(java.util.PropertyResourceBundle) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) Language(org.compiere.util.Language) JRPrintServiceExporter(net.sf.jasperreports.engine.export.JRPrintServiceExporter) Copies(javax.print.attribute.standard.Copies) Connection(java.sql.Connection) CConnection(org.compiere.db.CConnection) IOException(java.io.IOException) JasperPrint(net.sf.jasperreports.engine.JasperPrint) FileInputStream(java.io.FileInputStream) ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) MPrintFormat(org.compiere.print.MPrintFormat) DigestOfFile(org.compiere.utils.DigestOfFile) File(java.io.File) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)40 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)28 PrinterJob (java.awt.print.PrinterJob)16 PrintService (javax.print.PrintService)13 IOException (java.io.IOException)12 JobName (javax.print.attribute.standard.JobName)12 PrinterException (java.awt.print.PrinterException)10 File (java.io.File)9 DocFlavor (javax.print.DocFlavor)9 Copies (javax.print.attribute.standard.Copies)9 DocPrintJob (javax.print.DocPrintJob)8 Attribute (javax.print.attribute.Attribute)7 SimpleDoc (javax.print.SimpleDoc)6 PageFormat (java.awt.print.PageFormat)5 PrintException (javax.print.PrintException)5 PrintRequestAttribute (javax.print.attribute.PrintRequestAttribute)5 PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)4 Destination (javax.print.attribute.standard.Destination)4 java.awt.print (java.awt.print)3 Printable (java.awt.print.Printable)3