Bug 27491 - Printing web pages with images in them doesn't work
Summary: Printing web pages with images in them doesn't work
Status: RESOLVED MOVED
Alias: None
Product: cairo
Classification: Unclassified
Component: postscript backend (show other bugs)
Version: 1.9.6
Hardware: Other All
: medium normal
Assignee: Adrian Johnson
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-06 08:44 UTC by Andrew Benton
Modified: 2018-08-25 13:38 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
postscript file generated by firefox on a system with cairo-1.9.6 (865.82 KB, application/postscript)
2010-04-06 17:17 UTC, Andrew Benton
Details
postscript file generated by midori/webkit on a system with cairo-1.9.6 (993.20 KB, application/postscript)
2010-04-06 17:56 UTC, Andrew Benton
Details
patch (944 bytes, patch)
2010-04-07 02:43 UTC, Adrian Johnson
Details | Splinter Review
Postscript output from Firefox on the system with the patched cairo-1.9.6 (856.57 KB, application/postscript)
2010-04-07 05:44 UTC, Andrew Benton
Details
Postscript output from Midori/webkit-gtk with the patched cairo-1.9.6 (900.55 KB, application/postscript)
2010-04-07 06:44 UTC, Andrew Benton
Details
postscript that cups sends to the printer when printing from Midori/webkit with the patched cairo-1.9.6 (433.74 KB, application/postscript)
2010-04-10 10:58 UTC, Andrew Benton
Details
.ppd for the printer (28.17 KB, text/plain)
2010-04-10 12:21 UTC, Andrew Benton
Details

Description Andrew Benton 2010-04-06 08:44:20 UTC
Printing some web pages (eg, http://news.bbc.co.uk/) with either Firefox or Midori (a webkit-gtk browser) doesn't work with cairo-1.9.6. The printer whirrs, the paper moves through it but nothing gets printed. The pages are blank if they contain any images. Reading through the cups error log was unenlightening. Ghostscript seems to be having problems

D [06/Apr/2010:14:10:31 +0100] [Job 14] Error: /nocurrentpoint in --show--
D [06/Apr/2010:14:10:31 +0100] [Job 14] Operand stack:
D [06/Apr/2010:14:10:31 +0100] [Job 14] (\022)
D [06/Apr/2010:14:10:31 +0100] [Job 14] Execution stack:
D [06/Apr/2010:14:10:31 +0100] [Job 14] %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1878   1   3   %oparray_pop   1877   1   3   %oparray_pop   1861   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue
D [06/Apr/2010:14:10:31 +0100] [Job 14] Dictionary stack:
D [06/Apr/2010:14:10:31 +0100] [Job 14] --dict:1157/1684(ro)(G)--   --dict:3/20(G)--   --dict:119/200(L)--
D [06/Apr/2010:14:10:31 +0100] [Job 14] Current allocation mode is local
D [06/Apr/2010:14:10:31 +0100] [Job 14] Last OS error: 2
D [06/Apr/2010:14:10:31 +0100] [Job 14] GPL Ghostscript 8.71: Unrecoverable error, exit code 1
D [06/Apr/2010:14:10:31 +0100] [Job 14] renderer exited with status 0

If I recompile firefox without the option --enable-system-cairo then it uses it's own version of cairo and printing once again works fine. This is what makes me think this is a cairo bug. Firefox and Midori have different backends but they both use cairo. Midori I don't know how to fix - it uses webkit-gtk for its rendering which uses the system cairo.
Printing doesn't work with Thunderbird (also compiled with --enable-system-cairo) if the email has any images in it but it will print if the email is just text.
Printing works fine in every other app I've tried, epdfview and xpdf can print pdfs with images in them. The gimp can print images.
Midori and the broken version of firefox can both print a local html file that is just text. They can also print plain text downloaded from the web. It seems to be web pages with images in them that cause the bug. The images are rendered fine on the screen, the bug happens when they get sent to ghostscript
Comment 1 Adrian Johnson 2010-04-06 14:44:24 UTC
Can you print to a file, preferably with the simplest possible test case, and attach the PostScript file here. Also check that the file crashes Ghostscript directly with "gs file.ps" as well as via CUPS with "lpr file.ps".
Comment 2 Andrew Benton 2010-04-06 17:17:36 UTC
Created attachment 34735 [details]
postscript file generated by firefox on a system with cairo-1.9.6

This postscript file displays fine with gs file.ps. If I try to print it with lpr file.ps it's just the same as if I try to print it directly from firefox, the first page is blank and the second page prints OK. Actually the second page has got some small images on it that have printed so it's not as simple as I thought, it is able to print some images. I've just recompiled my system using cairo-1.8.10 and the bug is gone. Firefox compiled with --enable-system-cairo can print again
Comment 3 Andrew Benton 2010-04-06 17:56:26 UTC
Created attachment 34741 [details]
postscript file generated by midori/webkit on a system with cairo-1.9.6

This file was created with Midori/webkit-gtk on a system with cairo-1.9.6. This one crashes ghostscript like so:

andy:~$ gs file.ps
GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /nocurrentpoint in --show--
Operand stack:
   (\001)
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1862   1   3   %oparray_pop   1861   1   3   %oparray_pop   1845   1   3   %oparray_pop   1739   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue
Dictionary stack:
   --dict:1143/1684(ro)(G)--   --dict:2/20(G)--   --dict:111/200(L)--
Current allocation mode is local
Last OS error: 2
Current file position is 285891
GPL Ghostscript 8.64: Unrecoverable error, exit code 1

Trying to print it with lpr file.ps produces nothing, not even a blank page

If I boot into the system with cairo-1.8.10 then Midori can print fine
Comment 4 Adrian Johnson 2010-04-07 02:43:56 UTC
Created attachment 34756 [details] [review]
patch

This patch should fix the problem. Could you try it with your test case.
Comment 5 Andrew Benton 2010-04-07 03:58:07 UTC
The patch is a slight improvement, Midori no longer crashes ghostscript, it now behaves exactly the same as Firefox. gs file.ps shows the file without crashing. When I print the first page goes through the printer but nothing gets printed, the second page is printed. No change in the behavior of Firefox.
Comment 6 Adrian Johnson 2010-04-07 05:30:42 UTC
When printing, CUPS converts the PS to PDF then back to PS using these commands:

ps2pdf13 file.ps         # ghostscript
pdftops file.pdf file2.ps # poppler
gs file2.ps

The problem may be with cairo, gs, or poppler. Can you attach the new PS output from Firefox and I'll check if I can reproduce the problem.
Comment 7 Andrew Benton 2010-04-07 05:44:13 UTC
Created attachment 34761 [details]
Postscript output from Firefox on the system with the patched cairo-1.9.6
Comment 8 Adrian Johnson 2010-04-07 06:00:11 UTC
I'm unable to reproduce the bug with the attachment in comment 7 using either:

lpr file.ps

or

ps2pdf13 file.ps
pdftops file.pdf file2.ps
gs file2.ps


I'm using gs 8.70 and pdftops 0.13.1.
Comment 9 Andrew Benton 2010-04-07 06:44:00 UTC
Created attachment 34764 [details]
Postscript output from Midori/webkit-gtk with the patched cairo-1.9.6

Interesting.
I compile cups before poppler or xpdf (pdftops is provided by xpdf-3.02pl4 on my system). I see cups checks for pdftops during configure but it normally runs fine without it. I'm just in the process of running my build scripts on my kitchen computer to rebuild with cairo-1.8.10. It hasn't got as far as compiling poppler or xpdf so there isn't (yet) a pdftops on that system yet printing works fine. Cups doesn't seem to need pdftops. 
On my main computer I've booted into the partition with the patched cairo-1.9.6 and reinstalled cups-1.4.2. It now sees that pdftops is installed and printing from Firefox is working again but Midori still outputs a blank page. 
Try lpr file.ps with this new attachment
Comment 10 Adrian Johnson 2010-04-07 07:25:22 UTC
CUPS may have multiple options for converting PS to PDF. My experience is based on what my Ubuntu system does.

To debug this problem you will need to figure out what is happening to your PS file when you print it. I can only help with cairo or poppler problems.
Comment 11 Adrian Johnson 2010-04-10 07:05:45 UTC
I've pushed the patch out to master. Printing the file in comment 9 works for me.

You didn't mention what printer you are using. If it is a PostScript printer you can capture the PS that CUPS sends to the printer and check if it works with ghostscript.

To capture the output sent to the printer:

 Run the command:

  cupsctl FileDevice=yes

 Then create a clone of your print queue. I use system-config-printer to do this.
 Then run (assuming the copy of your queue is named "copy"):

  lpadmin -p copy -E -v file:/tmp/printout.ps

 Then print to "copy" and the output is in /tmp/printout.ps

You can send printout.ps directly to your printer bypassing all filtering with:

 lpr -l printout.ps
Comment 12 Andrew Benton 2010-04-10 10:58:15 UTC
Created attachment 34878 [details]
postscript that cups sends to the printer when printing from Midori/webkit with the patched cairo-1.9.6

I couldn't figure out how to clone the print queue so I ran the lpadmin command on the default print queue, which produced this file.
Trying to view it with ghostscript crashes gs

andy:~$ gs printout.ps
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefined in $PJL
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1878   1   3   %oparray_pop   1877   1   3   %oparray_pop   1861   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1149/1684(ro)(G)--   --dict:0/20(G)--   --dict:70/200(L)--
Current allocation mode is local
Current file position is 332
GPL Ghostscript 8.71: Unrecoverable error, exit code 1

If I try to print it the output is just as before: the first page is blank. If I do the same thing with Firefox it produces a postscript file that is twice as big which make sense, 'cos when I print that file it prints both pages.
My printer is a Samsung ml-1210 postscript laser printer. I'm using cups-1.4.2
Comment 13 James Cloos 2010-04-10 12:11:29 UTC
> Error: /undefined in $PJL

Attachment #34878 [details] is not PostScript, but rather PJL.  Probably PCL
bitmaps.

What does the print spool's ppd look like?
Comment 14 Andrew Benton 2010-04-10 12:21:43 UTC
Created attachment 34880 [details]
.ppd for the printer

This is the .ppd file I use for the printer. It normally works well.
Comment 15 James Cloos 2010-04-11 10:47:58 UTC
That ppd uses ghostscript and the gs driver at:

 http://www.openprinting.org/download/printing/samsung-gdi/

to render the ps to the PJL-enclosed bitmaps the printer supports.
Comment 16 Andrew Benton 2010-04-11 16:21:33 UTC
The Samsung-gdi driver was added to ghostscript years ago. I can vaguely remember using those patches but it was a log time ago. The printer works perfectly if I use cairo-1.8.10
Comment 17 Adrian Johnson 2010-05-05 05:21:13 UTC
Mozilla bug #563255 reported a similar problem. The much smaller test case made it possible to find a mismatched save/restore in the PS output.

I'm hoping the patch will also fix this bug:

http://cgit.freedesktop.org/cairo/commit/?id=fa937913e06bc295750538be45aa83eb42332fb4
Comment 18 GitLab Migration User 2018-08-25 13:38:58 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/116.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.