PDF printing: Not entire PDF is printed when window is close

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

PDF printing: Not entire PDF is printed when window is close

Postby Phylanx » Thu Nov 16, 2017 8:46 am

Hi!

Our customer reported a new printing issue. We have the following usecase:

Our application uses Chromium to view PDF documents in separate Frames.
So we have a Frame displaying all available documents for a user. If the user selects to view a document and this document is a PDF, a new Window is opened, Chromium is initialized and the PDF is shown.
If the user then wants to print the PDF (via PDFium print button) and immediately closes the window before the printer started printing (and therefore terminates JCEF), the PDF is either not printed at all or the document is printed incomplete.
Sometimes also the printed pages contain error messages like the following:
PCL XL Error
Sub Sytem I/O
Error Input ReaderError
Operator BezierPatch
Position 27323

If the user waits until the printer started printing everything works fine.

So:
Is there a problem in the multi process model? Is one of the processes destroyed while creating the spool/emf file?
Shouldn't the process termination wait until the document spooling is completed?
Same with the window? Shouldn't it be that the window can't be closed until this happened?
Is there a possibility in JCEF/CEF to register a listener or publish an event that spooling finished?

We use JCEF version 3.2704, 32 bit on 64 bit Windows machines.
Logfile with verbose logging attached (Some Loggings are added by us to mark fixes for problems we had, see "MPA_LINZ_Chromium_Patch" and "MPA_CHROMIUM_PATCH" loggings).

// EDIT:
Problem with PDF not printed at all could be reproduced with newest JCEF version.
Logging of the new version (logging is the same, even if printing works or not):
D:\Git\java-cef-newest\src\tools>run.bat win32 Release detailed --log-severity=verbose --log-file=d:\temp\jcef.log
Offscreen rendering disabled
Using:
JCEF Version = 3.3112.168
CEF Version = 3.3112.1658
Chromium Version = 60.0.3112.113
CefApp: INITIALIZING
initialize on Thread[AWT-EventQueue-0,6,main] with library path .\jcef_build\native\Release
Added scheme search://
Added scheme client://
CefApp: INITIALIZED
[1116/161729.684:ERROR:service_manager.cc(142)] Connection InterfaceProviderSpec prevented service: content_plugin from binding interface: memory_instrumentation::mojom::Coordinator exposed by: content_browser
CefApp: SHUTTING_DOWN
shutdown on Thread[AWT-EventQueue-0,6,main]
CefApp: TERMINATED
Attachments
jcefVerbose.log
(349.43 KiB) Downloaded 668 times
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing: Not entire PDF is printed when window is c

Postby magreenblatt » Thu Nov 16, 2017 10:26 am

What happens if you do the same thing in Google Chrome?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: PDF printing: Not entire PDF is printed when window is c

Postby Phylanx » Thu Nov 16, 2017 10:35 am

For test purposes I installed a Google Chrome with about the same version as we use it in our product (Version 51.0.2704.84).
When opening the same PDF in that chrome and printing it the special chrome specific printing dialog opens (which is not used by JCEF, for JCEF the operating system printing dialog opens).

Long story short:

Chrome prints correctly, even if i kill the process before the actual printing starts

//EDIT:
PS: just downloaded the latest version (62.0.3202.94), it also printed correctly.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing: Not entire PDF is printed when window is c

Postby magreenblatt » Thu Nov 16, 2017 11:26 am

OK. Please add a bug. PRs to fix the issue are welcome :)
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: PDF printing: Not entire PDF is printed when window is c

Postby Phylanx » Fri Nov 17, 2017 2:37 am

Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing: Not entire PDF is printed when window is c

Postby Phylanx » Fri Nov 17, 2017 2:50 am

I'm trying to understand what happens and how the termination of the application might cause the problem.

Which processes are how involved in printing?
Which one does the rendering, spooling, print job handling?
How are these processes communicating?
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing: Not entire PDF is printed when window is c

Postby magreenblatt » Fri Nov 17, 2017 10:33 am

The print job is handled in the browser process. The PDF is processed in the utility process. The code lives in libcef/browser/printing.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: PDF printing: Not entire PDF is printed when window is c

Postby Phylanx » Mon Nov 20, 2017 2:22 am

So, as I understand it right now, that's what happens while printing:
Browser Process (my JVM main process that starts JCEF): BP
Utility process (process started for doing actual work): UP

BP starts JCEF and shows PDF in browser
User presses the print button
BP shows operating systems native print dialog, user presses "print"
BP creates a print job and sends it to the UP
UP renders PDF and creates a spool/emf file and gives handle to the BP
BP sends the spool/emf file to the printer
Printer prints

Is that correct for now?
Alternatively it might be possible that the UP and BP exchange the document to print pagewise?

I guess, the GUI becomes responsive again after the native printing dialog is done and the print job is created and sent to the UP.
As far as I see it now, the JCEF processes of our application look like this:
When I start our application, no JCEF_helper.exe process exists.
If I open a PDF document, a new window is opened, jcef is initialized and the PDF is shown in the new window. 4 JCEF_helper.exe processes exist:
[*] 1x --type=ppapi
[*] 2x --type=renderer
[*] 1x --type=gpu-process
Additionally the browser process running as java.exe exists.

Closing the window containing the PDF means, we don't terminate the CefApp (we'll reuse it when needed again later), but all handlers, browser and clients are removed/closed/disconnected.
What happens to the processes: the two renderer processes are terminated, ppapi and gpu-process (and browser process of course) are still running.
After some time, also the ppapi process is terminated, so only the gpu-process remains.

Which of these processes is the "utiltiy process"?
I guess, it is one of the renderer processes that are terminated when the window is closed (or is it the ppapi?).
Does the printing happen page wise, therefore terminating the renderer processes terminates the spool file generation?

//EDIT:
CefApp is terminated when our JVM is terminated.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: PDF printing: Not entire PDF is printed when window is c

Postby magreenblatt » Mon Nov 20, 2017 4:02 pm

Phylanx wrote:So, as I understand it right now, that's what happens while printing:
Browser Process (my JVM main process that starts JCEF): BP
Utility process (process started for doing actual work): UP

BP starts JCEF and shows PDF in browser
User presses the print button
BP shows operating systems native print dialog, user presses "print"
BP creates a print job and sends it to the UP
UP renders PDF and creates a spool/emf file and gives handle to the BP
BP sends the spool/emf file to the printer
Printer prints

Is that correct for now?

Sounds correct.

Phylanx wrote:Which of these processes is the "utiltiy process"?

None of them. The utility process is created only for the lifespan of the print job. The utility process code lives in libcef/utility.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: PDF printing: Not entire PDF is printed when window is c

Postby Phylanx » Tue Nov 21, 2017 5:37 am

ok, thanks so far...
I didn't see a utility process until now (might be it lives only a very short time with my test pdfs?).

So, the utility process renders the PDF to EMF and tells the browser process when he is done.
Does he do that for every page he rendered?
So that the browser process sends every single page to the printer?

When is the utility process terminated?
the plan would be, as soon as the print job has finished, but are there other possibilities?
e.g. if jcef is terminated or it is not terminated and the GUI is disposed?

when the rendering is not finished yet and the browser process terminates, what happens? the utility process doesn't send the pages to the printer, so is this the problem?

Or is it possible that the browser process terminates the utility process (even UP isn't finish yet) when the Chromium GUI is disposed?
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Next

Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 22 guests