-
Notifications
You must be signed in to change notification settings - Fork 74
Printing Pdf Content
On example project PdfPrinting you can see the complete code for how to print PDF file on escpos-coffee using PDFBox.
PdfBox is open source under Apache License and can be found on Github PdfBox
Steps to print pdf content:
1 - Configure Maven
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.19</version>
</dependency>
2 - Create input File, load PDF Document and Create PdfRenderer
File input = new File("C:\\Users\\macin\\desenv\\Document.pdf");
PDDocument document = PDDocument.load(input);
PDFRenderer pdfRenderer = new PDFRenderer(document);
3 - Render the first page to BufferedImage
BufferedImage image = pdfRenderer.renderImage(0);
4 - Choose the imageWrapper implementation (escpos algorithm to print images in printer) maybe the printer work better with one (print quickly) or doesn't recognize one or other algorithm, in other words, test it in your printer. Read more on Wiki Images (session - The ImageWrapperInterface implementation)
BitImageWrapper imageWrapper = new BitImageWrapper();
RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
GraphicsImageWrapper imageWrapper = new GraphicsImageWrapper();
5 - Choose the bitonal implemantation See if your image work better with bitonal threshold or ordered dither implementation, read more on Wiki Images (session - The Bitonal implementation algorithm)
Bitonal algorithm = new BitonalThreshold();
// or
Bitonal algorithm = new BitonalOrderedDither();
6 - print the image
imageHelper.write(escpos, new CoffeeImageImpl(image),imageWrapper,algorithm);