The first part 'almost' worked - just an additional gray line in output.
The second part is mainly about Java limitations - not really PDFBox's
fault. When creating the PrintJob, we have to specify a media "size" or
"name". Problem is, that it has a check in the constructor, that throws
exception when the format is "landscape". FindMediaSize method returns a
nearest, but portrait sized media. Even the Java PrintDialog gets
available media list from printer setup, but filters out landscape
formats defined by the driver (silently swallowing constructor exception
and just not showing them).
Jakub Jelínek
------ Původní zpráva ------
Od "Tilman Hausherr" <thaush...@t-online.de>
Komu users@pdfbox.apache.org
Datum 13.06.2024 15:13:59
Předmět Re: PDFBox PDFPageable and Java printing problem (MediaSize
landscape workaround needed)
Hi,
I haven't really understood your post, apparently you're partly satisfied and
partly not, it's the second part I don't get. In the meantime I found the
ticket I mentioned this morning:
https://issues.apache.org/jira/browse/PDFBOX-3117 (9 years ago!)
and
https://issues.apache.org/jira/browse/PDFBOX-5202
I've also added a check for the centering part, so that it doesn't do a translation if
one of the values is negative. However while looking at the "center" code I
have some doubts whether this works at all. Or maybe it's only useful if PDFPrintable is
used (which has scaling options).
If you work for a company that can afford to buy something, have a look at
https://qz.io/ , the two brothers running that company have been regulars in
the tickets and they have years of experience with printing labels.
Tilman
On 13.06.2024 13:59, Jakub Jelínek wrote:
Hello,
thanks, it helped at least a bit - Print to PDF seems almost OK (it is adding a strange
line under the label frame, visible on label_result2.pdf + I have to specify
"PORTRAIT" orientation explicitly). Almost the same goes when I send it
directly to a label printer. I have used just a little bit different source label as I
was testing barcode generation yesterday and it tests a little better the edges, but with
the same dimensions of the original PDF.
java -jar pdfbox-app-3.0.3-20240613.101659-108.jar print -noCenter -silentPrint
-i=label.pdf -orientation=PORTRAIT -printerName="Microsoft Print to PDF"
java -jar pdfbox-app-3.0.3-20240613.101659-108.jar print -noCenter -silentPrint
-i=label.pdf -orientation=PORTRAIT -printerName="4BARCODE 4B-2054N"
For the label printer it works when I leave the dimensions on 40x20. Then it
fits the label, only crops sides (print_uncentered.png).
The png has original result with bad centering (bottom), uncentered (middle)
and an attempt to make it narrower (35x20mm). The narrower experiment failed
with printer failure (stopped in the middle of label with error and didn't work
until restarted).
https://drive.google.com/open?id=1718rA8sDqftmsD2y4wAVQhpL4J1dABA0&usp=drive_fs
<https://drive.google.com/open?id=1718rA8sDqftmsD2y4wAVQhpL4J1dABA0&usp=drive_fs>
So for now when I call the PDFPageable constructor with "PORTRAIT" orientation,
0 DPI, border=false, center=false it comes at least close, thanks.
It is probably still limited by the FindMedia of Java sending only a close
media size. E.g. for 55x20 (supposedly just wider then the label, I have added
margins to the source PDF to fit on paper, label3.pdf) it prints with some
format that takes 2,5 labels (the print starts in the middle of the first one
and spans another two empty labels, cropped to a much narrower column again
with some dotted lines, photo in print_wider.png).
Thanks for support,
Jakub Jelínek
------ Původní zpráva ------
Od "Tilman Hausherr" <thaush...@t-online.de>
Komu users@pdfbox.apache.org
Datum 13.06.2024 12:29:35
Předmět Re: PDFBox PDFPageable and Java printing problem (MediaSize landscape
workaround needed)
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