In my web application, as per the requirement I need to print PDF file to laser printer without opening windows default “Print” popup.
So here I am using applet to print the bytes which are stored in HTML text area.
But it seems that the bytes generated after new String(pdf.getByte[]) is different than the actual PDF bytes.
In my controller I am storing the bytes to request scope as mentioned below :
request.setAttribute(PageRenderConstant.MULTI_SEL_PDF,new String(printOutputVO.getPdfBytes()));
And in HTML … I am storing the byte as below ..
<textarea style="visibility: hidden;" name="laserPrintData" id="laserPrintData" >
${multiselpdffile}
</textarea>
And here is the applet code to print the document to laser pritner…
function print(){
var applet = document.jZebra;
if (applet != null) {
var data = $("#laserPrintData").val();
//applet.append(data);
applet.appendPDF(data);
applet.printPS();
}
}
But it says “The provided PDF is corrupted file.” So the bytes after new String() operation are different.
So How can I retain the same bytes as it was before new String() operation ??
Use Base64 methods to convert byte[] to String and decode it back to byte[]