Skip to content
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

Incorrect rendering of PDF plot produced by ggplot2 #6981

Closed
DarwinAwardWinner opened this issue Feb 12, 2016 · 9 comments
Closed

Incorrect rendering of PDF plot produced by ggplot2 #6981

DarwinAwardWinner opened this issue Feb 12, 2016 · 9 comments

Comments

@DarwinAwardWinner
Copy link

I've encountered a PDF that renders incorrectly in pdf.js. It is a plot produced by ggplot2 in R and saved to PDF using the pdf function in R. I have prepared several files in a Dropbox folder that you should be able to access here: https://www.dropbox.com/sh/8azllvpnwynuf5r/AABPC9winwBhlYN_LQWWDJbwa?lst=

First, is pcoa-original.pdf, the original unmodified PDF file, and pcoa-rendered-by-osx-preview.png, which is a screenshot of how it looks in OSX Preview, which renders it correctly. Then there is pcoa-rendered-by-pdfjs-in-firefox.png, a screenshot of the same PDF file viewed in Firefox 44.0. Then there is pcoa-saved-by-pdfjs.pdf, which is the result of clicking the "print" button in pdf.js, and then using the OSX print dialog to save a PDF file. Lastly, there is pcoa-saved-by-pdfjs-rendered-in-preview.png, which is a screenshot of Preview's rendition of that saved PDF file.

As shown in the first screenshot, there are circular points and circular crosshairs plotted, both in varying colors and sizes. The second screenshot shows that pdf.js renders the circles as ovals, and shifts their centers downward slightly. The "cross" part of the crosshairs, as well as the chart background, labels, and scales, all seem to be rendered correctly. The third screenshot shows that in the saved PDF output, the circles are still ovals, but in addition the circular portions of the crosshairs are massively enlarged and shifted up and to the right.

@timvandermeij
Copy link
Contributor

I cannot reproduce the issue with the pcoa-original.pdf file using Windows 10 x64, Firefox 44.0.2 and the latest PDF.js development version. Could you try opening the file with https://mozilla.github.io/pdf.js/web/viewer.html (Open File button in the toolbar) to see if the latest version of PDF.js fixes the issue?

@yurydelendik
Copy link
Contributor

I see it on Mac OSX:

screen shot 2016-02-12 at 2 48 03 pm

@timvandermeij
Copy link
Contributor

I have to fix my previous statement a bit: I cannot reproduce the oval rendering, but I can reproduce the circles not having the right radius.

@yurydelendik
Copy link
Contributor

Those are not circles, but bullet character filled or stroked (we might have not exact substitution for what was used in ggplot2 -- ZapfDingbats). The PDF has no embedded fonts, that causes result to be different.

@Snuffleupagus
Copy link
Collaborator

The circles rendering as ovals was most likely fixed by PR #6651. Unfortunately, they are now rendered too small instead. I guess that this is simply an issue with non-embedded ZapfDingbats fonts.

@DarwinAwardWinner
Copy link
Author

Ok, using https://mozilla.github.io/pdf.js/web/viewer.html on FF 44.0.2 on OSX (it just updated), I see the same thing as @yurydelendik. Doing the same thing on FF 44.0.1 on Ubuntu 15.10, the same PDF appears to render correctly.

@DarwinAwardWinner
Copy link
Author

Also, it might be relevant that the Linux machine I used for viewing is the same machine that produced that PDF.

@timvandermeij
Copy link
Contributor

@DarwinAwardWinner So the problem is that your Linux machine has fonts installed that were not embedded into the PDF. This causes rendering issues when the PDF is viewed on a machine that does not have these fonts installed, because in that case font substitution will occur, causing the artefacts you see in your images. Not embedding fonts in PDF files is a deprecated practice, so if you have the possibility you should always generate PDF files that have the necessary fonts embedded, such that they can be viewed correctly on any device.

There are already multiple open issues for dealing with PDFs with non-embedded fonts, but we can keep this open for further reference.

Edit: I don't know anything about R, but you might want to check out https://www.google.nl/#q=ggplot2+embed+fonts for generating PDFs with embedded fonts. Hopefully it helps.

@Snuffleupagus
Copy link
Collaborator

Duplicate of #4244

@Snuffleupagus Snuffleupagus marked this as a duplicate of #4244 Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants