Printing PDF or PNG in POS Thermal printer with java









up vote
0
down vote

favorite












I Everyone. I have a problem printing ticket with java. I generated ticket with jasper and then I need to print it in POS Thermal printer. I try to print PDF and the result got
Wrong Format
Then I convert pdf to png with pdfbox but the image print too small.
How can I print correctly? Is there any way to print PDF for POS Thremal Printer correctly or fill and increase the PNG Image?



Print PNG too small



Printing from Adobe reader directly to my POS Thermal Printer, I had the correctly ticket.
Correct from Adobe Reader



Here's part of my code:



PDDocument document = PDDocument.load(new File(pathFile+".pdf"));
PDPage pd;

PDFRenderer pdfRenderer = new PDFRenderer(document);

for (int page = 0; page < document.getNumberOfPages(); ++page)

pd = document.getPage(page);
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
ImageIOUtil.writeImage(bim, pathFile +".png", 300);


document.close();

FileInputStream is = new FileInputStream(pathFile+".png");

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob job = mPrinter.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);

job.print(doc, null);

is.close();









share|improve this question

















  • 1




    PDFBox allows to print PDFs directly. To see whether it works at all (there have been many troubles with tiny printers), download the pdfbox-app and try the command line utility pdfbox.apache.org/2.0/commandline.html#printpdf . If that works, get the source code and find the file Printing.java that one has several ways to print from PDF.
    – Tilman Hausherr
    Nov 10 at 15:21










  • Thanks for your suggestion. I could print through PDFBox's print method directly.The difference with adobe reader printing is that I had to fit the page format of my jasper template(receipt template) according to printing width defined in thermal printer technical manual because PDFBox doesn't fit the pdf to paper size.
    – Alvaro Chillcce
    Nov 12 at 18:58











  • There is a PDFBox printing option to fit to size, second parameter of PDFPrintable constructor. (Yes, that option isn't available on the command line)
    – Tilman Hausherr
    Nov 13 at 7:48














up vote
0
down vote

favorite












I Everyone. I have a problem printing ticket with java. I generated ticket with jasper and then I need to print it in POS Thermal printer. I try to print PDF and the result got
Wrong Format
Then I convert pdf to png with pdfbox but the image print too small.
How can I print correctly? Is there any way to print PDF for POS Thremal Printer correctly or fill and increase the PNG Image?



Print PNG too small



Printing from Adobe reader directly to my POS Thermal Printer, I had the correctly ticket.
Correct from Adobe Reader



Here's part of my code:



PDDocument document = PDDocument.load(new File(pathFile+".pdf"));
PDPage pd;

PDFRenderer pdfRenderer = new PDFRenderer(document);

for (int page = 0; page < document.getNumberOfPages(); ++page)

pd = document.getPage(page);
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
ImageIOUtil.writeImage(bim, pathFile +".png", 300);


document.close();

FileInputStream is = new FileInputStream(pathFile+".png");

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob job = mPrinter.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);

job.print(doc, null);

is.close();









share|improve this question

















  • 1




    PDFBox allows to print PDFs directly. To see whether it works at all (there have been many troubles with tiny printers), download the pdfbox-app and try the command line utility pdfbox.apache.org/2.0/commandline.html#printpdf . If that works, get the source code and find the file Printing.java that one has several ways to print from PDF.
    – Tilman Hausherr
    Nov 10 at 15:21










  • Thanks for your suggestion. I could print through PDFBox's print method directly.The difference with adobe reader printing is that I had to fit the page format of my jasper template(receipt template) according to printing width defined in thermal printer technical manual because PDFBox doesn't fit the pdf to paper size.
    – Alvaro Chillcce
    Nov 12 at 18:58











  • There is a PDFBox printing option to fit to size, second parameter of PDFPrintable constructor. (Yes, that option isn't available on the command line)
    – Tilman Hausherr
    Nov 13 at 7:48












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I Everyone. I have a problem printing ticket with java. I generated ticket with jasper and then I need to print it in POS Thermal printer. I try to print PDF and the result got
Wrong Format
Then I convert pdf to png with pdfbox but the image print too small.
How can I print correctly? Is there any way to print PDF for POS Thremal Printer correctly or fill and increase the PNG Image?



Print PNG too small



Printing from Adobe reader directly to my POS Thermal Printer, I had the correctly ticket.
Correct from Adobe Reader



Here's part of my code:



PDDocument document = PDDocument.load(new File(pathFile+".pdf"));
PDPage pd;

PDFRenderer pdfRenderer = new PDFRenderer(document);

for (int page = 0; page < document.getNumberOfPages(); ++page)

pd = document.getPage(page);
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
ImageIOUtil.writeImage(bim, pathFile +".png", 300);


document.close();

FileInputStream is = new FileInputStream(pathFile+".png");

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob job = mPrinter.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);

job.print(doc, null);

is.close();









share|improve this question













I Everyone. I have a problem printing ticket with java. I generated ticket with jasper and then I need to print it in POS Thermal printer. I try to print PDF and the result got
Wrong Format
Then I convert pdf to png with pdfbox but the image print too small.
How can I print correctly? Is there any way to print PDF for POS Thremal Printer correctly or fill and increase the PNG Image?



Print PNG too small



Printing from Adobe reader directly to my POS Thermal Printer, I had the correctly ticket.
Correct from Adobe Reader



Here's part of my code:



PDDocument document = PDDocument.load(new File(pathFile+".pdf"));
PDPage pd;

PDFRenderer pdfRenderer = new PDFRenderer(document);

for (int page = 0; page < document.getNumberOfPages(); ++page)

pd = document.getPage(page);
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
ImageIOUtil.writeImage(bim, pathFile +".png", 300);


document.close();

FileInputStream is = new FileInputStream(pathFile+".png");

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob job = mPrinter.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);

job.print(doc, null);

is.close();






java printing pdfbox thermal-printer receipt






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 15:11









Alvaro Chillcce

1




1







  • 1




    PDFBox allows to print PDFs directly. To see whether it works at all (there have been many troubles with tiny printers), download the pdfbox-app and try the command line utility pdfbox.apache.org/2.0/commandline.html#printpdf . If that works, get the source code and find the file Printing.java that one has several ways to print from PDF.
    – Tilman Hausherr
    Nov 10 at 15:21










  • Thanks for your suggestion. I could print through PDFBox's print method directly.The difference with adobe reader printing is that I had to fit the page format of my jasper template(receipt template) according to printing width defined in thermal printer technical manual because PDFBox doesn't fit the pdf to paper size.
    – Alvaro Chillcce
    Nov 12 at 18:58











  • There is a PDFBox printing option to fit to size, second parameter of PDFPrintable constructor. (Yes, that option isn't available on the command line)
    – Tilman Hausherr
    Nov 13 at 7:48












  • 1




    PDFBox allows to print PDFs directly. To see whether it works at all (there have been many troubles with tiny printers), download the pdfbox-app and try the command line utility pdfbox.apache.org/2.0/commandline.html#printpdf . If that works, get the source code and find the file Printing.java that one has several ways to print from PDF.
    – Tilman Hausherr
    Nov 10 at 15:21










  • Thanks for your suggestion. I could print through PDFBox's print method directly.The difference with adobe reader printing is that I had to fit the page format of my jasper template(receipt template) according to printing width defined in thermal printer technical manual because PDFBox doesn't fit the pdf to paper size.
    – Alvaro Chillcce
    Nov 12 at 18:58











  • There is a PDFBox printing option to fit to size, second parameter of PDFPrintable constructor. (Yes, that option isn't available on the command line)
    – Tilman Hausherr
    Nov 13 at 7:48







1




1




PDFBox allows to print PDFs directly. To see whether it works at all (there have been many troubles with tiny printers), download the pdfbox-app and try the command line utility pdfbox.apache.org/2.0/commandline.html#printpdf . If that works, get the source code and find the file Printing.java that one has several ways to print from PDF.
– Tilman Hausherr
Nov 10 at 15:21




PDFBox allows to print PDFs directly. To see whether it works at all (there have been many troubles with tiny printers), download the pdfbox-app and try the command line utility pdfbox.apache.org/2.0/commandline.html#printpdf . If that works, get the source code and find the file Printing.java that one has several ways to print from PDF.
– Tilman Hausherr
Nov 10 at 15:21












Thanks for your suggestion. I could print through PDFBox's print method directly.The difference with adobe reader printing is that I had to fit the page format of my jasper template(receipt template) according to printing width defined in thermal printer technical manual because PDFBox doesn't fit the pdf to paper size.
– Alvaro Chillcce
Nov 12 at 18:58





Thanks for your suggestion. I could print through PDFBox's print method directly.The difference with adobe reader printing is that I had to fit the page format of my jasper template(receipt template) according to printing width defined in thermal printer technical manual because PDFBox doesn't fit the pdf to paper size.
– Alvaro Chillcce
Nov 12 at 18:58













There is a PDFBox printing option to fit to size, second parameter of PDFPrintable constructor. (Yes, that option isn't available on the command line)
– Tilman Hausherr
Nov 13 at 7:48




There is a PDFBox printing option to fit to size, second parameter of PDFPrintable constructor. (Yes, that option isn't available on the command line)
– Tilman Hausherr
Nov 13 at 7:48

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240275%2fprinting-pdf-or-png-in-pos-thermal-printer-with-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240275%2fprinting-pdf-or-png-in-pos-thermal-printer-with-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo