exportgraphics with ContentType vector does not work properly

27 views (last 30 days)
I am trying to export a large figure as a PDF, through
exportgraphics(h,'Figure.pdf','ContentType','vector')
Matlab creates a file called "Figure.pdf" in the designated folder but:
  • If you try to open that pdf file, an error window comes out: "An error occurred while opening this document. The file is corrupted and cannot be repaired".
  • At the same time, Matlab keeps running the same code, and you cannot either pause it or stop it, unless you force the computer to stop Matlab.
So far I can only see
exportgraphics(h,'Figure.pdf','ContentType','image')
as possible alternative to export my figure, even though, to the best of my undestaing, this is not a vector-type image.
Are there some alternative to still get a vector image in my case?

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 6 Feb 2024
Based on your description of the issue, my guess is that:
  • Your figure is fairly complicated.
  • Which means that exporting into a vector format is going to both take a really long time, and potentially create a really large PDF file.
  • This means that exportgraphics is going to run fairly slowly.
  • And you are probably trying to open the resulting PDF file before it is done being generated.
  • If you force MATLAB to stop early, it is leaving a partially written (and thus corrupt) PDF.
But, this is all speculation without knowing more details about what is in your figure.
What do you have plotted in your figure that you are exporting?
Can you describe (in as much detail as you want);
  • What objects are you plotting (surfaces, patches, lines, scatter plots, etc.)?
  • How many objects are you plotting?
  • Roughly how many data points are you plotting?
Actual reproduction steps would be better, but not necessary.
A screenshot of your figure could also really help.
  1 Comment
Sim
Sim on 8 Feb 2024
Edited: Sim on 8 Feb 2024
Thanks a lot @Benjamin Kraus, your guesses are correct and I had to wait a very long time to export the figure :-)
My Figure was a map containing shapefiles (around 9000) and lines (around 200), and a small text...

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!