Message Boards Message Boards

Export Graphics3D images to PDF preserving a good resolution?

GROUPS:

Let's create image

g = Graphics3D[{Line[{{-2, 0, 2}, {2, 0, 2}, {0, 0, 4}, {-2, 0, 2}}]}]

and then export it by Export["test.pdf", g]. It leads to a very unsatisfactory result snapshot of resulting image in PDF

Option AllowRasterization" -> False does not help. How do I get PDF or EPS file of this image in the vector format?

POSTED BY: Rodion Stepanov
Answer
6 days ago

As a hack you can turn it into a 2D Graphics object, and export that:

g = Graphics3D[{Line[{{-2, 0, 2}, {2, 0, 2}, {0, 0, 4}, {-2, 0, 2}}]}]
Export["out.pdf", Graphics[Inset[g, Automatic, Automatic, Scaled[1]]]]

Works on MacOSX with Mathematica 11.3

POSTED BY: Sander Huisman
Answer
6 days ago

Thank you very much! Your hack works incredibly well. Of course, the file might be huge, but it is worth to some extent.

POSTED BY: Rodion Stepanov
Answer
5 days ago

This looks like a possible bug or perhaps an undocumented limitation. I've just tried a simple example which suggests that the Export function option AllowRasterization" -> False has the expected effect if you export 2D graphics, but appears to have no effect when used to export a Graphics3D expression.

You could use the ImageResolution option with a high DPI value (say ImageResolution->1200). This improves the resolution of the exported graphic, but it remains a raster image.

Maybe it's one for Technical Support?

Hope this helps,

Ian

POSTED BY: Ian Williams
Answer
6 days ago

You can try exporting with ImageResolution -> Infinity. It has worked for me well enough.

POSTED BY: Gianluca Gorni
Answer
5 days ago

Thanks a lot. It also works, but result of Plot3D is different from what I've gotten after turning it into a 2D Graphics object (suggested above by Sander Huisman). With ImageResolution -> Infinity I see a mesh. See the difference enter image description here enter image description here

POSTED BY: Rodion Stepanov
Answer
5 days ago

The Inset trick gives a much better shading than with ImageResolution->Infinity , at the expense of a much larger file size, at least in the example that I tried.

POSTED BY: Gianluca Gorni
Answer
5 days ago

I wonder whether the problem might lie with PDF? I don't know enough about PDF to say for sure, but if it doesn't understand 3D vector graphics then the above Export function is never going to work as intended and the vector graphics will have to be rasterised. Just a thought. Maybe someone who knows more about PDF can confirm.

All the best,

Ian

POSTED BY: Ian Williams
Answer
5 days ago

Image exported in EPS is also raster.

POSTED BY: Rodion Stepanov
Answer
5 days ago

It is documented that PDF only supports 2D graphics so I would use either a high resolution or Sander's conversion to 2D graphics:

from the PDF Export Documentation it says:

Stores text, fonts, images, and 2D vector graphics in a device- and resolution-independent way.

Also, I found in the past that the export resolution depends on the original size of the graphic and that ImageResolution->Infinity undoes this. so I would fix the original size and then rasterize it with:

g = Graphics3D[{Line[{{-2, 0, 2}, {2, 0, 2}, {0, 0, 4}, {-2, 0, 2}}]}, ImageSize -> Large]
Export["out5.pdf", g, ImageResolution -> 1200]

You can move the 1200 up or down to suit your needs/ file size.

Regards,

Neil

POSTED BY: Neil Singer
Answer
5 days ago

Well spotted Neil - I missed that nugget!

POSTED BY: Ian Williams
Answer
5 days ago

If you need to export 3D graphics objects in vector form, you could try using Autodesk's DXF format as per the attached notebook. This works. Although I notice that when I re-import the exported graphic back into Mathematica its attributes and display options such as axes are lost in the process (I think at the export stage).

You can also view, export and print the exported DXF file using one of several free viewers. I use Autocad's "DWG TrueView" which I find works well in most cases.

All the best,

Ian

Attachments:
POSTED BY: Ian Williams
Answer
5 days ago

Group Abstract Group Abstract