Hi,
I've now added the center parameter to PDFPageable and a noCenter option
to the print command line utility
https://issues.apache.org/jira/browse/PDFBOX-5837
Please get it at
https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.3-SNAPSHOT/
and test it and tell us if this helps or not.
Tilman
On 13.06.2024 05:28, Tilman Hausherr wrote:
I remember having seen something like this years ago, but I don't
remember if we were able to fix it. Labels have also made trouble for
years.
Anyway, I just woke up and played around a bit:
- Orientation.LANDSCAPE rotates it
- Orientation.AUTO rotates it
- Orientation.PORTRAIT doesn't rotate but it is cut off because the
page is moved to the left, like your "result" PDF.
The last one may or may not be a bug on our side. This happens when
centering is done. If I switch off centering then the image looks like
this when doing print to PDF:
-------------------------------|
-------------------------------|
I might be able to solve this by supporting the center parameter in
PDFPageable (and in the command line application) so you can set it to
false. I'm not sure if changing the centering behavior would break
existing applications.
if (center)
{
graphics2D.translate((imageableWidth -
cropBox.getWidth() * scale) / 2,
(imageableHeight -
cropBox.getHeight() * scale) / 2);
}
Tilman
On 12.06.2024 16:12, Jakub Jelínek wrote:
Hello,
it seems a rather sparse question, but I've found several occurences
of the same problem, only not directly bound to PDFBox as it is
mainly a Java Printing framework problem, but I'm looking for a
workaround.
I'm generating documents using Freemarker templates + FlyingSaucer
library (template -> HTML -> PDF). That part works well, producing
desired documents with any requested custom "paper" formats.
Adobe AcrobatReader displays them correctly and it is even capable of
printing them to a label printer via Windows print drivers (Zebra
thermal printer, a Chineese 4Barcode thermal printer or any standard
Windows printer).
I'm using PDFBox (currently 3.0.2, but it is probably a problem since
dark ages) to get PDFPageable to be printed on a HW printer (or a
Windows virtual printer or whatever else, it really doesn't matter).
And there comes the problem with Java printing framework - it doesn't
accept MediaSize with width > height. I'm not talking about printing
"landscape" as on most printers (taking the paper with the narrower
edge first and rotating the image). I'm printing on labels on a long
roll, so I can't feed them rotated. Everything works perfectly with
"portrait" format media (e.g. 10x15cm labels), but when it comes to
"landscape" fed media (40x10mm, 50x20mm...), I'm out of luck as Java
framework "fixes" page format to nearest "portrait" oriented format
with borders, silently ignoring the exception thrown in the MediaSize
print attribute constructor (complaining about the W>H). The same
happens when using the PDFBox-app.jar with print command (I'm
printing almost the same way as the PDFBox-app does, only loading the
generated PDF directly via a memory buffer).
I know that it is a Java framework limitation, question is if there
is a known workaround for that. I can't make the media "higher" as it
wastes labels (and in case of e.g. RFID tag labels it gets very
expensive).
Attached is a test "label.pdf" PDF (40x10mm) that prints badly from
Java (even on "PrintToPDF" printer or any standard printer, no need
for a label printer to test) - shifted down and left by a default A10
paper border. "label_result.pdf" is an attempt to print similar label
(40x20) to a windows "Print to PDF" printer. Printing the same PDF
from AcrobatReader works perfectly, even directly to the label printer.
Thanks, Jakub
Jakub Jelínek
jakub.jeli...@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail:users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail:users-h...@pdfbox.apache.org