PDF printing with JCEF/Chromium - fit in page

Having problems with building or using the JCEF Java binding? Ask your questions here.

PDF printing with JCEF/Chromium - fit in page

Postby Phylanx » Fri Dec 23, 2016 5:52 am

Hi all!
We are using JCEF - thx for all the great work you've done so far - to embed all kinds of web content in our product.
That covers normal HTML pages, SWF and showing PDF documents.

Currently we use cef version "3.2704".

Now we got complaints of customers who wanted to print PDFs.
The PDFs are documents delivered by third party companies.
When printing these PDFs are now sliced on the right and left side from the printer, so tables, images,... are cut.
Long story short:
Is there an easy way to tell JCEF/CEF/Chromium to execute a "fit in page" action or something like that?
I just found out that PrintHandlers/PrintSettings aren't yet supported for Windows OS, so we can't even implement a custom print dialog or set a border/margin/sth on the print settings.

Thanks for your help in advance!
Johann
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing with JCEF/Chromium - fit in page

Postby magreenblatt » Mon Jan 09, 2017 12:21 pm

How does it behave when you print those PDFs in Google Chrome?

Since the file is already a PDF you could print using some external tool, instead of using JCEF.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: PDF printing with JCEF/Chromium - fit in page

Postby Phylanx » Tue Jan 10, 2017 5:54 am

For now we found out following things:

Chrome and the Chromium Browser have a custom print dialog that automatically has checked a "fit in page" checkbox.
So the PDF is automatically corrected before printing.

CEF/JCEF does not open this print dialog, i guess they send the print command directly to the Operating system print dialog.
Is the print dialog implemented in chromium but not supported by CEF?


We could use external tools to print PDFs, but the PDF is viewed in Chromium/CEF/JCEF and our customer presses the "print" buttin directly supported by PDFium.

// EDIT:
Are there any workarounds/hacks we could do to make our situation better?
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing with JCEF/Chromium - fit in page

Postby magreenblatt » Tue Jan 10, 2017 12:11 pm

It looks like the default OS print dialog doesn't provide a "fit in page" option, so it would be necessary for the client to implement a custom print dialog. That would likely require https://bitbucket.org/chromiumembedded/cef/issues/1283.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: PDF printing with JCEF/Chromium - fit in page

Postby Phylanx » Thu Jan 12, 2017 3:32 am

Posted in the referenced issue:
As mentioned above, we would need that mechanism for the WinOS too. Is there anything planned in near future?
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing with JCEF/Chromium - fit in page

Postby Phylanx » Thu Feb 09, 2017 10:48 am

We did further analysis and found out following:
The problem lies in the file ".\chromium\src\printing\printed_document_win.cc"

The page that should be printed is rendered there for the specific printer, as far as I saw it now.
A "SimpleModifyWorldTransform" call is done where the page is prepared for the printable page size.
An offsetX and offsetY is calculated and a shrinkFactor, so that the page is fit in page and placed in the middle of the page.

Now for our cases the calculated offsets used by a real printer are -100 for X and Y, also the shrinkFactor is about 0.15 (using a XPS printer, ofssets are 0, shrinkFactor is 0.15, so nearly the same)
So the printer wants to print the calculated page on -100/-100 which normally is no problem, because the most things to print don't fill the whole page and leave some white space.

After a bit tryarounds I had following conclusions:
If offsets are set to 0 and the shrinkFactor is untouched, the left border is printed correct, but the right border is out of the printable area.
If also the shrinkFactor is increased to 0.1575 (about 5% more), it's printed fine.

For now that's fine for me, I'll try to get more informations about how to calculate the sizes correctly (offsets shouldn't be negative).
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing with JCEF/Chromium - fit in page

Postby Phylanx » Wed Feb 15, 2017 4:03 am

We couldn't find the real bug for this problem.
For us, we just edited the code in the following way:

In printed_document_win.cc we prevent the negative offsets passed to the SimpleModifyWorkTransform call and also shrink the content for additional 5 percent (shrinkFactor = shrinkFactor * 1.05f).
This works for us, hopefully there will be a fix in the future.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 17 guests