Printing exported PDF graphics fails (version 8)

16

6

When I export even simple graphics, say, a DateListPlot to PDF under Windows, it refuses to print on any of the printers at work.
enter image description here

Acrobat (Reader X) throws three modal dialogs in succession: "The document could not be printed", "There were no pages selected to print" and (sometimes) "There was a drawing error".

Strangely, simple graphics (i.e. not a GraphicsGrid) will print correctly if you choose "Save Selection As..." or right-click and choose "Save Graphics As..." and save as a PDF. However PDFs produced using the Export command, or by saving some more complex Grids of graphics, have this printing issue. I cannot see anything different in the properties of the PDFs produced with Export that might cause them not to print, when those produced using the various versions of "Save As..." do print.

There is a work-around, which is to go into the Advanced tab of the print dialog and choose "Print as image".

Since the intention is that colleagues will be running notebooks that automatically update and export PDF-format graphics, I am reluctant to use this work-around. People will forget what to do and blame me. I have already had problems sending graphics to colleagues that they then can't print.

Other than manually exporting things all the time using "Save Selection As" and educating people on print settings, is there anything I can do to avoid printing errors?

System: Windows XP, Mathematica 8.0.4. We're going to Windows 7 very soon, so maybe that will help.

EDIT
I have now uploaded:

  1. The file that does not print (produced using Export)
  2. The file that does print

As you can see, they look identical but there are about 100 extra bytes in the Exported version.

EDIT 2

This bug seems to have been fixed in version 9.

Verbeia

Posted 2012-04-05T03:00:23.050

Reputation: 33 191

Can't reproduce (ie works OK) in Mma 8.0.0 Win XP – Dr. belisarius – 2012-04-05T03:45:29.810

I've experienced the same issue. I reported it many moons ago, but WRI couldn't reproduce on their system. I'm running Win 7, Mathematica 8.0.4. Maybe if enough people report it, WRI will give it another look. – None – 2012-04-05T03:25:20.443

Same issue with Mathematica 8.0.4 and Windows 7. – b.gates.you.know.what – 2012-04-05T06:59:07.887

Experienced the same issue but couldn't figure out what exactly produces this behavior. Gave up basically. – Markus Roellig – 2012-04-05T10:47:24.390

I had no problems printing two Exported pdf's. One was just a ListPlot, the other a GraphicsGrid with two ListPlots and two bitmaps. Win 7/8.04, printer a very old (18 years and counting) Apple Laserwriter 360 postscript printer. – Sjoerd C. de Vries – 2012-04-05T17:43:13.877

BTW I was printing from Adobe Acrobat professional 8.1.6 and Reader 9.1. I just noticed that a few postscript errors were printed on an additional page, but nothing unusual for a printer with just 7MB memory. I get those things occasionally. – Sjoerd C. de Vries – 2012-04-05T17:57:11.817

FWIW, If I export DateListPlot[FinancialData["IBM", "Jan. 1, 2004"]] as a pdf, PDF X-Change Viewer renders only if zoomed out, and the page is blank after printing, but Sumatra PDF displays and prints fine. (W7 32-bit Pro, 8.0.0) – tkott – 2012-04-05T20:59:22.913

@b.gatessucks - I have a business trip next week so if you can report if F'x's answer works for you, it would be very helpful. – Verbeia – 2012-04-05T23:04:16.783

For me, the file that does not print also does not display properly (Adobe reader 9 on Linux initially just displays a white rectangle; hiding and showing the window again then causes the image to appear). – celtschk – 2012-04-05T23:15:39.227

@Verbeia The earliest I can try is Tuesday morning. – b.gates.you.know.what – 2012-04-06T14:13:31.040

I understand this observation probably isn't entirely helpful, but I wouldn't rule out the underlying cause being Adobe Reader's general shoddiness. For instance, SumatraPDF can print your unprintable file without problems. – Oleksandr R. – 2012-04-07T19:13:09.700

As usual when it comes to Windows, I can only guess. I don't see anything wrong with your files. But have you tried to export your PDF with outlined fonts as I suggested the answer to this question about WMF export you asked a while ago? That's my favorite way to cure everything from printing problems to hiccups.

– Jens – 2012-04-09T22:32:32.467

@Verbeia F'x's solution doesn't work for me. The messages I get are : "The document could not be printed", then "There were no pages selected to print" then "A drawing error occurred". – b.gates.you.know.what – 2012-04-10T08:28:50.623

I think you could add something like plot = Plot[Sin[x], {x, 0, 6 Pi}]; to make the snippet complete. Also, for what version of Mathematica is this valid? (I'm having this problem on mma 8.0.1 win7)? – Ajasja – 2012-08-22T12:12:38.107

Under Mac OS X, I have found that creating PDFs using the "Print.." menu option and then "Save as PDF", produces better PDFs. Maybe you could try to run an AppleScript to do that when the user clicks the button you are creating http://www.jaimerios.com/?p=171

– Gustavo Delfino – 2012-08-22T12:35:33.280

Per F'x's answer to my question try Background->None and see if it works.

– Verbeia – 2012-08-22T23:33:37.610

Background->None doesn't work for me. – Mike Honeychurch – 2012-08-24T23:18:19.530

Answers

10

You might also have luck if you specify the ImageSize

Export[filename, plot, "PDF", ImageSize -> 8*72]

I have also been able to print files when using the Print As Image option (under Advanced from the Print menu of Adobe).

chuy

Posted 2012-04-05T03:00:23.050

Reputation: 10 147

+1 this certainly works under Windows 7 using Mathematica 8.0.4 and Adobe Acrobat Pro X, at least for the test plot in the OP. – Verbeia – 2012-08-23T09:27:18.140

15

Short answer: I hope Export["foo.pdf", plot,Background->None] fixes it.


Let's get there step by step.

  1. First, Acrobat X Pro on my Mac reports that both your PDF files are fine. They print fine, and pass all tests with flying colors.
  2. I uncompressed the PDF (thanks pdftk) and a diff on them reveals that one weird object that only appears in your “export” PDF (i.e. the semi-broken one):

    -2147483648 -2147483648 m
    -2147483648 2147483647 l
    2147483647 2147483647 l
    2147483647 -2147483648 l
    W* n
    

    The numbers are INT_MIN and INT_MAX, the smallest negative 32-bit integer and the largest positive 32-bit integer. So, an infinitely large rectangle is being drawn.

  3. Then, I imported the PDFs and put them over a colored background:

    enter image description here

    The conclusion is: “export” gives the PDF a white background (why not), and it does this by drawing a white rectangle of infinite size below all other objects (weird!).

  4. Searching the documentation for “PDF export background” brings up the doc for EPS export, which has an option:

    Background           Automatic           background color shown in transparent image regions

    Now, I tried to use it as Export["foo.pdf", plot, Background->None] on my Mac, and it works only half-way: the white background is gone, but there still is an infinite invisible rectangle behind. So, I hope this is enough to fix your issue.


As a side note, I'll just state that as far as I understand the PDF Reference, having an object (even of very large size) outside the page box is not invalid. So, one could probably argue that the PDF is valid, and either the viewer application or your driver (on some systems, PDF printing directly sends the PDF to the printer driver) is at fault for not dealing with it properly.

F'x

Posted 2012-04-05T03:00:23.050

Reputation: 10 517

7

I thought this might be useful information for users. WRI tech support say this is a bug. However if you open the exported PDF in the open source PDF reader Evince then you can print.

Mike Honeychurch

Posted 2012-04-05T03:00:23.050

Reputation: 36 211

1Note that Background->None was not a fix for my problem. – Mike Honeychurch – 2012-08-24T23:16:24.913

4

This problem of not printing Exported PDFs originated when upgrading from version 7 to version 8. In version 7 it worked fine. In February 2011, I complained to Wolfram Research, as a Premier Service Member, but they could not fix this at the time.

By trial and error I have stumbled upon a workaround. Export the graphics as a Postscript file:

Export["Math/output/file.eps", graphics, "EPS"]

and then use the Unix convert to make PDF

convert file.eps file.pdf

I can open this in Mac Preview and now it prints fine on my old Epson CX21 laserprinter. I use Mathematica 8.0.1 on Mac OSX 10.6.8.

I hope this helps.

Romke Bontekoe

Posted 2012-04-05T03:00:23.050

Reputation: 1 543

6Note however that convert produces a pixel format. If you want to keep a vector format, use epstopdf instead. – celtschk – 2012-05-04T13:59:00.157