New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Margins ignored HTML, Images #8
Comments
I have a fix for margins at 8c1a114 |
At a glance, I don't see anything that stands out as incorrect, but my test results are failing pretty badly... 2" margins seem to be doing some sort of doubling on the right and the bottom. Here's in interesting conversation about margins with 2.0 on the PDFBOX mailing list...
|
@bberenz I see what you are describing, but your results are completely different. |
Are they different because you used |
Oh, that makes more sense that our results are so different. I had thought perhaps the job attributes (margins, etc) were making it to PDFBOX and being processed twice (once by the rasterizer, again by the print job), so I bumped |
It's ugly, but try this out... stills seems to scale incorrectly, but see how this fixes the margins? //margins
if (pxlOpts.getMargins() != null) {
pageX += pxlOpts.getMargins().left();
pageY += pxlOpts.getMargins().top();
- pageW -= (pxlOpts.getMargins().right() + pxlOpts.getMargins().left());
- pageH -= (pxlOpts.getMargins().bottom() + pxlOpts.getMargins().top());
+ // PDFBox seems to double right/bottom margins, so we'll half them before processing
+ int denom = (this instanceof PrintPDF) ? 2 : 1;
+ pageW -= (pxlOpts.getMargins().right()/denom + pxlOpts.getMargins().left());
+ pageH -= (pxlOpts.getMargins().bottom()/denom + pxlOpts.getMargins().top());
} |
Two things to keep in mind here: (1) your sample pdf has its own white space, skewing the observed margins, and (2) this problem only shows up on rasterized print jobs, not all pdf print jobs will have this issue they have the same top/left position and the same sizing, but the rastered version is cut off at the same point as its unscaled counterpart (posted above) |
Hmm, yeah the scale as well as the top and left margins are working as expected.
Well, something is cutting it off... 😄 I don't know how to proceed. I guess we could provide a snippet for the PDFBOX dev group which reproduced this, but I don't feel comfortable writing that code. Edit: I've reached out to the pdfbox dev team to see if they have any advice. They may ask for a minimal snippet to reproduce. |
@tresf Let me know if they need one, and I'll put it together. |
I've been monitoring the PDFBOX mailing list and it's been 2 days without a reply (but several replies to other topics). Yes, let's please get a small example together and I'll send it to them. |
public static void main(String[] args) throws Exception {
PDDocument pdf = PDDocument.load(new URL(args[0]).openStream());
PrinterJob job = PrinterJob.getPrinterJob();
Paper paper = new Paper();
paper.setSize(612, 792); //8.5 x 11 in
paper.setImageableArea(72, 72, 468, 648); //1 inch margins
PageFormat page = job.getPageFormat(null);
page.setPaper(paper);
//Vector print - works as expected, margins applied and scaled properly
job.setPrintable(new PDFPrintable(pdf, Scaling.SCALE_TO_FIT, false, 0, false), page);
job.print();
//Unscaled raster print - works as expected, margins applied and document cut off
job.setPrintable(new PDFPrintable(pdf, Scaling.ACTUAL_SIZE, false, 72, false), page);
job.print();
//Scaled raster print - unexpected results, same scale as vector print, but same cut off as unscaled raster print
job.setPrintable(new PDFPrintable(pdf, Scaling.SCALE_TO_FIT, false, 72, false), page);
job.print();
pdf.close();
} |
I've emailed the list and received no response. I'm pretty sure this is an upstream bug and I'm also not sure if there's anything that can be done on our end until its resolved. Furthermore, it's unrelated to Images and HTML, so I'll review the PR and move the PDF bug to a dedicated topic location. 👍 |
With the latest build of the
|
I believe this crash is occurring while the Since it's a hard crash, IntelliJ doesn't really offer a way to debug. I stepped through the code and the last line that was executed before the crash was here https://github.com/qzind/tray/blob/2.0/src/qz/printer/action/WebApp.java#L147. On that note:
@klabarge According to some of these bug reports, there's a chance this is due to the graphics adapter. Can you test on your physical machine and let us know if it occurs there too? Google points to these, but they don't appear to be related. |
I compiled the latest build from the dpi branch and I do not experience a crash when HTML printing. OS X 10.11.3 |
@klabarge thanks for the testing. So we'll have to remember this hard-crash as we get support submissions, but we should be ok moving forward. I'll squash the commits from the |
Upstream bug report for PDFBOX submitted here: https://issues.apache.org/jira/browse/PDFBOX-3306 |
Fixed via 3680d9f. This will be addressed in the next release (either RC4 or 2.0.0 official) Edit: A patch for this issue has been submitted upstream: https://issues.apache.org/jira/browse/PDFBOX-3306 |
@klabarge wrote:
These printing results are identical between all browsers and platforms.
Update: Upstream PDFBOX bug: https://issues.apache.org/jira/browse/PDFBOX-3306
I got these images using the
sample.html
and leaving all of the default printing options except for adding 2 inches to the margins.Migrated from qzind/qz-print#185
The text was updated successfully, but these errors were encountered: