Dharma Teja Thammu (DharmaTejaT5078)
Corporation Service Company
Senior Software Engineer
Corporation Service Company
DharmaTejaT5078 Member since 2019 2 posts
Corporation Service Company
Posted: January 27, 2021
Last activity: January 27, 2021
Posted: 27 Jan 2021 15:25 EST
Last activity: 27 Jan 2021 16:32 EST

Print PDF

I have a requirement to print PDF through a background job in the application. I am planning to set up a Job scheduler and invoke a activity. However this code only seems to connect to a printer but unable to print. any ideas?  

java.net.Socket socket = null; java.net.InetAddress addr = null; java.net.InetSocketAddress socketAddress = null; java.io.BufferedReader reader= null; java.io.BufferedWriter writer= null; java.io.InputStream input = null; java.io.OutputStream output= null;

int port =9100; int timeout=5000; byte[] bodyBytes = null; //byte[] modifiedBodyBytes = null; //String bodyString = null;


    addr = java.net.InetAddress.getByName(hostName);     socket = new java.net.Socket(addr, port);     socket.setSoTimeout(timeout);        bodyBytes = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(pyStream);     oLog.infoForced("TestPrinter bodyBytes length "+bodyBytes.length);    // BodyString = new String(bodyBytes, "US-ASCII");    // modifiedBodyBytes= BodyString.getBytes("US-ASCII");

    output = socket.getOutputStream();       oLog.infoForced("TestPrinter output stream "+output);           input = socket.getInputStream();     oLog.infoForced("TestPrinter input stream "+input);            // kick it out     output.write(bodyBytes);     output.flush();     oLog.infoForced("TestPrinter output stream "+output);        socket.shutdownOutput();        reader = new java.io.BufferedReader(new java.io.InputStreamReader(input));      oLog.infoForced("TestPrinter read input stream "+reader);     printerResponse = reader.readLine();     oLog.infoForced("TestPrinter printer response "+printerResponse);          status = "success";     }   catch (Exception e) {   e.printStackTrace();     //oLog.error("TestPrinter Error in sending to printer ");   oLog.error("TestPrinter"+e);

  status = "fail"; } finally {     if (input != null) try { input.close();oLog.infoForced("TestPrinter closed input stream ");} catch (Exception e) {oLog.infoForced("TestPrinter Issue closing input stream ");   }   if (socket != null) try { socket.close(); oLog.infoForced("TestPrinter closed socket connection ");} catch (Exception e) {oLog.infoForced("TestPrinter Issue closing socket ");   }     if (output != null) try { output.close(); oLog.infoForced("TestPrinter closed output stream ");} catch (Exception e) {oLog.infoForced("TestPrinter Issue closing output stream ");} }

Pega Platform 8.3.3 Case Management Financial Services Senior System Architect
Moderation Team has archived post, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Discussion, please write a new Discussion.