We've had troubles with label printers, but not this type of trouble.
Does this also happen if the same document is printed again? If yes, it is reproducible 1) on PDFDebugger, 2) with a different printer?
Also make sure you're using the latest version of PDFBox (2.0.25), of java, and of your printer driver.
The code is fine. You can try to use a non zero dpi for PDFPageable (this option is also available in the menu in PDFDebugger so you can experiment). But this makes sense only if the problem is reproducible.
Tilman Am 19.01.2022 um 21:45 schrieb Christopher Stillwell:
I have a small utility that downloads available PDF files from an S3 bucket and then prints the file to an Afinia L801 label printer. I use PDDocument.load to load the file. Get a PrinterJob, set a PrintService on the job, create a PDFPageable on the document, set the pageable on the job, then call job.print(). Most of the time it works with no problem, but every now and then we will see a print problem such as the bottom of an image will be printed, but then the top part of the previous image will be printed, then a gap, and then the bottom of the current image again. The next image prints fine. Opening the file in Adobe Reader looks fine. I am using pdfbox 2.0.24. The PDF file is about 24m, but I am using 1G memory for the JVM. I'm not sure where the problem may be, so any suggestions on how to go about debugging would be appreciated. I've included a code snippet and some output logging in case I am doing something incorrectly. try ( PDDocument document = PDDocument.load( file ) ) { StopWatch timer = StopWatch.begin(); logger_.info( "PDDocument loaded" ); for (int i = 0; i < document.getNumberOfPages(); i++) { PDPage page = document.getPage( i ); PDRectangle mediaBox = page.getMediaBox(); // https://stackoverflow.com/questions/20904191/pdfbox-find-page-dimensions/20905166 logger_.info( String.format( "Page %s mediaBox: %s, %s x %s", i + 1, mediaBox, mediaBox.getHeight() / 72, mediaBox.getWidth() / 72 ) ); } // Get the PrintService if not already available. if ( printService == null ) { printService = choosePrinter(); if ( printService == null ) { logger_.log( Level.SEVERE, "A printer is required to be selected!" ); throw new RuntimeException( "A printer is required to be selected!" ); } } PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintService( printService ); PDFPageable pageable = new PDFPageable( document ); System.setProperty( "sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider" ); // https://pdfbox.apache.org/2.0/migration.html#pdf-printing job.setPageable( pageable ); logger_.info( String.format( "Print started : %s", file ) ); logger_.info( String.format( "Printer: %s, file: %s", printService.getName(), file ) ); job.print(); logger_.info( String.format( "Print complete : %s, duration %s", file, timer ) ); return true; } catch ( Throwable e ) { logger_.log( Level.SEVERE, String.format( "Print failed: %s", file ), e ); return false; } [2022-01-19 09:28:49] (PrintManager) INFO: Task-6260 Started [2022-01-19 09:28:51] (PrintManager) INFO: GET https://app.domain/resource/printqueue/next?queue=Printcenter/PrintQueue_4 [200] [2022-01-19 09:28:55] (PrintManager) INFO: Downloaded file: C:\Users\Print\Printcenter\PrintQueue_4\220119152822-FILE_NAME.pdf [2022-01-19 09:28:55] (PrintManager) INFO: POST https://app.domain/resource/printqueue/staged/3a7065a7-4658-41af-a555-2f738302fd64 [200] [2022-01-19 09:28:55] (PrintManager) INFO: [3a7065a7-4658-41af-a555-2f738302fd64] 220119152822-FILE_NAME.pdf updated to staged [2022-01-19 09:28:55] (PrintManager) INFO: PDDocument loaded [2022-01-19 09:28:55] (PrintManager) INFO: Page 1 mediaBox: [0.0,0.0,3412.8,540.0], 7.5 x 47.4 [2022-01-19 09:28:55] (PrintManager) INFO: Page 2 mediaBox: [0.0,0.0,3412.8,540.0], 7.5 x 47.4 [2022-01-19 09:28:55] (PrintManager) INFO: Page 3 mediaBox: [0.0,0.0,2556.0,540.0], 7.5 x 35.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 4 mediaBox: [0.0,0.0,2556.0,540.0], 7.5 x 35.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 5 mediaBox: [0.0,0.0,2556.0,540.0], 7.5 x 35.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 6 mediaBox: [0.0,0.0,2556.0,540.0], 7.5 x 35.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 7 mediaBox: [0.0,0.0,2556.0,540.0], 7.5 x 35.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 8 mediaBox: [0.0,0.0,1692.0,540.0], 7.5 x 23.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 9 mediaBox: [0.0,0.0,1116.0,540.0], 7.5 x 15.5 [2022-01-19 09:28:55] (PrintManager) INFO: Page 10 mediaBox: [0.0,0.0,1116.0,540.0], 7.5 x 15.5 [2022-01-19 09:28:55] (PrintManager) INFO: Print started : C:\Users\Print\Printcenter\PrintQueue_4\220119152822-FILE_NAME.pdf [2022-01-19 09:28:55] (PrintManager) INFO: Printer: Afinia L801 4, file: C:\Users\Print\Printcenter\PrintQueue_4\220119152822-FILE_NAME.pdf [2022-01-19 09:29:16] (PrintManager) INFO: Print complete : C:\Users\Print\Printcenter\PrintQueue_4\220119152822-FILE_NAME.pdf, duration 00:00:20,579 [2022-01-19 09:29:16] (PrintManager) INFO: Deleted: C:\Users\Print\Printcenter\PrintQueue_4\220119152822-FILE_NAME.pdf [2022-01-19 09:29:16] (PrintManager) INFO: POST https://app.domain/resource/printqueue/printed/3a7065a7-4658-41af-a555-2f738302fd64 [200] [2022-01-19 09:29:16] (PrintManager) INFO: [3a7065a7-4658-41af-a555-2f738302fd64] 220119152822-FILE_NAME.pdf updated to printed [2022-01-19 09:29:16] (PrintManager) INFO: Processed file 220119152822-FILE_NAME.pdf, duration 00:00:26,923 [2022-01-19 09:29:16] (PrintManager) INFO: Task-6260 Finished
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org For additional commands, e-mail: users-h...@pdfbox.apache.org