# Tag Info

46

My preferred method to export graphics to pdf is to do something like Export["figure.pdf", plot, "AllowRasterization" -> True, ImageSize -> 360, ImageResolution -> 600] This uses vectors for simple graphics, but produces a high resolution rasterized image if the plot becomes too complicated.

39

Before you step into the same traps I once stepped, let me point out some key-points. First of all two things: 1. although I spend some time digging in the subject, my knowledge is far from being complete, keep this in mind. 2. as everyone else around here, I would really like to have a fast, good-looking export of vector graphics too. Unfortunately, we have ...

29

The default style sheets set ShowSyntaxStyles -> False for the "Printout" environment. You could change the notebook to use a style sheet that doesn't set this. Probably the easiest way is to copy the definition from Default.nb, and modify it: Cell[StyleData[All, "Printout"], ShowSyntaxStyles->True]

20

The suggestion to use Antialiasing->False doesn't really solve the problem. I don't have a single solution that's appropriate in all cases, but I think one of the approaches I list on the following web page will work: Avoiding artifacts in shaded contour and density plots Edit: The following method from the linked article solves the problem: Instead ...

16

A simple workaround is to use Export instead of right clicking and choosing Save As ... The result will look like this: Much better. It's not clear to me why this difference exists between saving from the front end or using Export, but there is a significant difference in the quality of the output. Notice that the line widths are different too (the ...

15

Short answer: I hope Export["foo.pdf", plot,Background->None] fixes it. Let's get there step by step. 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. I uncompressed the PDF (thanks pdftk) and a diff on them reveals that one weird object that only appears in your ...

15

I actually like your own solution as a way to generalize the RegionPlot approach, and the answer by @tkott! Edit with improved version of RegionPlot trick Since @tkott's solution was still rough around the edges, I hacked together a version of it that should be able to emulate all the features of ContourPlot - i.e., be usable as a drop-in replacement with ...

15

This is because Mathematica exports to PDF in the Printout screen environment. If you change this to the working environment, it'll keep the syntax highlighting, but will also make everything a bit bigger: SetOptions[$FrontEnd, PrintingStyleEnvironment -> "Working"] You can also change this setting from the GUI using Format -> Option Inspector... ... 13 Merging polygons in ContourPlot A seven-hour train ride and a coach with an electric outlet gave me an opportunity to implement a ContourPlot fixer. This method heavily relies on the precise structure of the output that ContourPlot produces. It relies on version 8 features, and I won't be surprised if it break in future versions. But it works pretty well ... 12 Mathematica will normally embed the fonts correctly in a PDF. But this only works if the font exists. Papyrus does not have a bold weight. Try with FontWeight->"Bold" deleted and see if this works. I don't have Papyrus on my Windows machine, but I checked that Kristen ITC does not embed if it is bold, and does if the FontWeight option is removed. 12 For 3D graphics, I truly don't think it's worth the effort to attempt exporting as vector graphics. The valiant attempts to keep at least the axes and labels as vector graphics are in my opinion not something an everyday user would consider. With PDF for 3D graphics, you're fighting two problems: not just the file size but also the slow rendering when your ... 12 I had the same problem after switching to Mathematica 10. The issue here is the following: Export uses Rasterize to create the png image. The StyleEnvironement, which is used in Rasterized, cannot be specified as an option but is given by the$FrontEnd object (not by the EvaluatingNotebook[]!). You can change the StyleEnvironement by SetOptions[$FrontEnd, ... 11 Surely this is a manifestation of the problem described in: Antialiasing option behaves weird (polygon edges visible in ContourPlot) Therefore, you should try using Style[plot, Antialiasing -> False] or other methods to disable anti-aliasing. Somehow I had missed a closely related question witch Jens directed me to. I believe it is a solution to ... 11 The "OperatorSubstitution" option does prevent the use of Mathematica fonts, but only for those cases where there were ASCII equivalents. So if your graphic contains expressions which use, for example, parentheses, brackets, braces, or various ASCII operators (plus, minus, asterisk, etc.), then the "OperatorSubstitution" is exactly what you want and you are ... 10 One possible solution is to do as I suggested in this MathGroup post (see also the follow-ups). I think one can simplify it by doing the following: g = Graphics[{Inset[ Plot[10^5 x^2, {x, -2, 2}, Frame -> True, Axes -> None], ImageScaled[{0, 0}], ImageScaled[{0, 0}], ImageScaled[1]]}, ImageSize -> {400, 400}, PlotRange -> {{0, 1}, {0, ... 10 To get nice looking PDF export in this case is not easy. Export is really doing something wrong here. The best option I think would be to do the following: regionplot = RegionPlot[x^2 + y^2 < 1, {x, -1, 1}, {y, -1, 1}, PlotStyle -> Opacity[0.5, Black]]; Export["region.pdf", Show[regionplot, Prolog -> {Opacity[0], Texture[{{{0, 0, 0, ... 9 You can adjust page size, page number style, headers, footers, etc from items under File -> Printing Settings menu. Or you can programmatically modify them by manipulating Notebook's options: PrintingCopies, PrintingStartingPageNumber, PrintingPageRange, PageHeaderLines, PageFooterLines, PrintingOptions. Note: It seems "PaperSize" and "PrintingMargins" ... 9 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). 9 If it's really scanned images, then you could try this: pages = Import["yourfile.pdf", {"PDF", "Images"}] Otherwise, I'd suggest running the file through ghostscript or another distiller to clean up the potentially malformed PDF code first. The command would look like this: gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=newfile.pdf ... 9 You should investigate in the Scaled function: lots = GraphicsGrid[ Table[With[{a = RandomInteger[{1, 17}], b = RandomInteger[{1, 17}]}, ParametricPlot[Sin[t^2] {Cos[a t], Sin[b t]}, {t, 0, 2 \[Pi]}, PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True, ImageSize -> Scaled[1]]], {15}, {7}]]; Export["lots.pdf", lots] 9 I suggest exporting to a raster format with high resolution. The ImageResolution option is very useful for controlling the resolution. I wrote a little tutorial on how to export images for LaTeX in this answer (since I would just repeat the same thing here, I am linking to it instead). Note: High resolution raster images will take up a lot of space, but ... 9 One workaround I've discovered is to export as SVG, open in Inkscape, and save as PDF. The default parameters there (which I have not explored thoroughly) result in a PDF file size of 324KB. 9 Proof of the Szabolcs's idea: Graphics[{PointSize[0.001], Point@RandomReal[1, {1000, 2}]}, ImageSize -> 30] After Save As (28x28 grid): After Export Another workaround is printing the graphic to a file. 8 You can export animations to SWF: movie = Animate[Plot[Sin[x + a], {x, 0, 10}], {a, 0, 5}]; Export["movie.swf", movie] You can import them in LaTeX (see TeX SE): \documentclass{article} \usepackage{media9} \begin{document} \includemedia[ activate=pageopen, width=405pt,height=292pt, ]{}{movie.swf} \end{document} (I had to insert ... 8 What Verbeia said in her answer is not entirely correct — Mathematica indeed does embed the font, regardless of whether a particular font weight/slant exists or not. The real culprits are the PDF viewers on Macs, which do not use the base font if the specified weight is not available. It took some digging around to get to the reason though. The clues that ... 8 Please let me compile answers from the comments so that this topic can be marked as answered. Yes, this is a bug. A better solution than having rectangles of slightly different sizes and slightly larger than desired is to export the figure as EPS first and then convert it to PDF later. The cut corners are still there though. 8 To make nicer PDFs, you could adapt the answer here as follows. Before making any plots, execute the command Map[SetOptions[#, Prolog -> {{EdgeForm[], Texture[{{{0, 0, 0, 0}}}], Polygon[#, VertexTextureCoordinates -> #] &[{{0, 0}, {1, 0}, {1, 1}}]}}] &, {Graphics3D, ContourPlot3D, ListContourPlot3D, ListPlot3D, ... 8 This is a problem with Preview, the PDF reader included in OS X. The problem does not show when using other PDF readers (not based on PDFKit) such as Adobe Reader. To prevent blurring you just need to untick the "Smooth text and line art" checkbox under "Viewing documents" in Preview's preferences: However, this will lower the quality of text and line ... 8 Please try adding some space around the plot: Plot[2 Sin[x] + x, {x, 0, 15}, Filling -> Bottom, ImageMargins -> 10] ImageMargins gives a margin around the existing plot that can be seen by selecting the graphic (the outer orange frame): By comparison ImagePadding is used by Plot itself to make room for the axes labels (the inner orange frame). 8 I could not get it to work with$FrontEnd, but setting the ScreenStyleEnvironment on $FrontEndSession worked for me. Here text cells get two different backgrounds and font sizes, depending on the environment. ("Printout" is pink and large.) sseOpt = Options[$FrontEndSession, ScreenStyleEnvironment]; SetOptions[\$FrontEndSession, ScreenStyleEnvironment ...

Only top voted, non community-wiki answers of a minimum length are eligible