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

Support SVG images in multiple formats #1793

Closed
Nutomic opened this issue Dec 8, 2014 · 31 comments
Closed

Support SVG images in multiple formats #1793

Nutomic opened this issue Dec 8, 2014 · 31 comments

Comments

@Nutomic
Copy link

Nutomic commented Dec 8, 2014

I'm testing pandoc's markdown to pdf conversion using this readme and command ~/.cabal/bin/pandoc README.md -o test.pdf. However, I'm getting this error:

pandoc: Unable to convert image `/tmp/tex2pdf.26140/0056733ea8a4c9b7dab70a5b455f59437d34f134.svgz':
Cannot load file
Jpeg Invalid marker used. Failed reading at byte position 2
PNG Invalid PNG file, signature broken. Failed reading at byte position 8
Bitmap Invalid Bitmap magic identifier. Failed reading at byte position 2
GIF Invalid Gif signature : <svg x. Failed reading at byte position 6
HDR Invalid radiance file signature. Failed reading at byte position 11
Tiff Invalid endian tag value. Failed reading at byte position 2

pandoc: Unable to convert image `/tmp/tex2pdf.26140/8ba8f2c25e51f37aa52f6286040bc2a2ca70cda4.svgz':
Cannot load file
Jpeg Invalid marker used. Failed reading at byte position 2
PNG Invalid PNG file, signature broken. Failed reading at byte position 8
Bitmap Invalid Bitmap magic identifier. Failed reading at byte position 2
GIF Invalid Gif signature : <svg v. Failed reading at byte position 6
HDR Invalid radiance file signature. Failed reading at byte position 11
Tiff Invalid endian tag value. Failed reading at byte position 2

! Font T1/cmr/m/n/10=ecrm1000 at 10.0pt not loadable: Metric (TFM) file not fou
nd.
<to be read again> 
                   relax 
l.100 \fontencoding\encodingdefault\selectfont

pandoc: Error producing PDF from TeX source

Additionally, there's a missfont.log generated:

mktextfm ecrm1000
mktextfm ecrm1000

At first I thought this was because of the relative links for images, but replacing them with raw.githubusercontent.com URLs gives the same error.

Pandoc version is 1.3.11, installed from cabal, on Kubuntu 14.10.

@mpickering
Copy link
Collaborator

I can't reproduce this exact error, this is my output.

pandoc: Unable to convert image `/var/folders/3z/_vqy7kmx4pd90sg_v80zpk340000gn/T/tex2pdf.70131/0056733ea8a4c9b7dab70a5b455f59437d34f134.svgz':
Cannot load file
Jpeg Invalid marker used
PNG Invalid PNG file, signature broken
Bitmap Invalid Bitmap magic identifier
GIF Invalid Gif signature : <svg x
HDR Invalid radiance file signature
Tiff Invalid endian tag value

pandoc: Unable to convert image `/var/folders/3z/_vqy7kmx4pd90sg_v80zpk340000gn/T/tex2pdf.70131/8ba8f2c25e51f37aa52f6286040bc2a2ca70cda4.svgz':
Cannot load file
Jpeg Invalid marker used
PNG Invalid PNG file, signature broken
Bitmap Invalid Bitmap magic identifier
GIF Invalid Gif signature : <svg v
HDR Invalid radiance file signature
Tiff Invalid endian tag value

! LaTeX Error: Unknown graphics extension: .svgz.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.63 ...33ea8a4c9b7dab70a5b455f59437d34f134.svgz}}

pandoc: Error producing PDF from TeX source

@Nutomic
Copy link
Author

Nutomic commented Dec 8, 2014

Yeah apparently the font error is a seperate problem (I'm also getting it for .md files without images).

@mpickering
Copy link
Collaborator

Can you compile normal tex documents?

@Nutomic
Copy link
Author

Nutomic commented Dec 8, 2014

It works using pdflatex in the shell. Although I don't know what pandoc uses.

@mpickering
Copy link
Collaborator

Pandoc uses pdflatex with the following arguments from what I can see "-halt-on-error", "-interaction", "nonstopmode","-output-directory"

@iliakan
Copy link

iliakan commented Jan 11, 2015

Same with epub/html to pdf.
Apparently, the problem is with SVG images <img src="image.svg"> which I use in the text.

@iliakan
Copy link

iliakan commented Jan 11, 2015

P.S. Just to note: there's no svgz in my HTML page that I try to convert, only svg, which is sent compressed-on-the-fly by the server though, headers:

Content-Encoding:gzip
Content-Type:image/svg+xml

@mpickering
Copy link
Collaborator

Can you please post the exact output you are getting in a new ticket?

@jgm
Copy link
Owner

jgm commented Apr 13, 2015

I don't think svg is supported by pdflatex. The svg (or svgz) would need to be converted to a supported image format. We use JuicyPixels for bitmap image format conventions, but it won't help with svg.

I've improved the confusing error messages in a recent commit, but I don't think there's much else that can be done now.

Your path forward is to convert the svgs to pdfs with an external program.

@Twinside
Copy link
Contributor

As a matter of fact, there is a possibility to render SVG, not directly through JuicyPixels, but I have a library called rasterific-svg for this. I was thinking of putting together a proposition to allow the use of SVG in pandoc, but I don't really know where to start.

@lierdakil
Copy link
Contributor

@Twinside, rasterizing svg for pdf output seems somewhat suboptimal, when it could be converted straight to pdf (both being vector formats and all). But I don't think there are libraries for that...

@Twinside
Copy link
Contributor

I think it's doable, I'll have a shot at it.

@Twinside
Copy link
Contributor

rasterific-svg 0.2.3 now support PDF output (for a better function documentation see renderSvgDocument, it uses the same parameters).

@tarleb
Copy link
Collaborator

tarleb commented Aug 13, 2016

@Twinside Do you think SVG support could be added to pandoc using your library?

@Twinside
Copy link
Contributor

There is #2211 proposed a long time ago, providing svg rasterization or svg conversion to PDF depending on the need. Conversion to PDF didn't handle inclusion of images though.

@tarleb
Copy link
Collaborator

tarleb commented Aug 14, 2016

I'm sorry, I hadn't noticed. Thanks for the pointer. Looks like the main obstacle is the indirect dependency on lens. @jgm and @mpickering both have raised their concern on the size of the lens library, maybe this discussion can be revisited to a definite conclusion?

From a quick look at the PR, it looks to me like gif and png would no longer be supported. Did I misread the change? I'll try to spend more time on this, it would be nice if we could get the issue at hand resolved.

@Twinside
Copy link
Contributor

PNG & gif are still supported, it's the way to determine their DPI that would change, by using JuicyPixels's metadata information. But maybe I missed something (it was a loooong time ago).

@tarleb
Copy link
Collaborator

tarleb commented Aug 15, 2016

Figured I'd be missing something there, thanks.

it was a loooong time ago

😔

@jgm jgm changed the title Unable to convert image, cannot load file Support SVG images in multiple formats Mar 2, 2017
@JamesH65
Copy link

+1 for SVG conversion. Having real trouble finding a way of converting github markdown to PDF because of the lack of SVG support in pandoc.

@jgm jgm added this to the pandoc 2.0 milestone Mar 14, 2017
@jgm
Copy link
Owner

jgm commented Mar 14, 2017

Putting this in the pandoc 2.0 milestone, so I don't forget about it.
Not promising to implement it (the lens issue is still one to consider), but at least a decision should be made.

@mb21
Copy link
Collaborator

mb21 commented Mar 15, 2017

This would also be solved by switching the default PDF engine to ConTeXt or wkhtmltopdf...

@JamesH65 you can already use pandoc -t html5 -o foo.pdf (to use wkhtmltopdf) or pandoc -t context -o foo.pdf (to use ConTeXt) for PDF generation now.

@jgm
Copy link
Owner

jgm commented Mar 15, 2017 via email

@ickc
Copy link
Contributor

ickc commented Apr 6, 2017

Another approach is to rely on an external dependencies, if including a big library is a concern. And since LaTeX is already an external dependency of pandoc, I guess this will be fine for many potential users of this feature.

e.g. in graphics - How to include SVG diagrams in LaTeX? - TeX - LaTeX Stack Exchange, it's mentioned that there's a LaTeX package relying on external dependencies that automatically choose from a few external dependencies depending on availabilities of the system.

This way, pandoc can still provide a native support without committing to a large dependency.

@jgm
Copy link
Owner

jgm commented Aug 9, 2017

Did some tests. Had good results with rsvg-convert (installed with librsvg), converting to both png and pdf. Bad results with svg2pdf. Bad results with rasterific. Tempted to shell out to rsvg-convert.
I'd rather not use the svg package since that requires -shell-escape.

@jgm jgm closed this as completed in 6b72c5e Aug 9, 2017
@Twinside
Copy link
Contributor

Did you had specific bad example files?

@jgm
Copy link
Owner

jgm commented Aug 11, 2017 via email

@Twinside
Copy link
Contributor

Thanks, I've fixed rasterific-svg to render it correctly, even if it doesn't matter in this case.

@jgm jgm mentioned this issue Nov 9, 2017
@agusmba
Copy link
Contributor

agusmba commented Nov 9, 2017

would it make sense to use the same approach for Docx output?

@perlun
Copy link

perlun commented Mar 23, 2021

I don't think I'd want to change the default. But it's good to emphasize that people who use SVGs can already use -t context or -t html with -o output.pdf and use these engines, which support SVG already.

Worth mentioning: -t html gives me errors like this, since wkhtmltopdf disables local file access by default since 0.12.6:

  Defaulting to 'my_file_name' as the title.
  To specify a title, use 'title' in metadata or --metadata title="...".
Loading page (1/2)
Warning: Blocked access to file /home/per/some-file.svg
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Printing pages (2/2)                                               
Done                                                           
Exit with code 1 due to network error: ProtocolUnknownError
Error producing PDF.

-t context worked better for me (with librsvg2-bin and inkscape installed) for converting Markdown with embedded .svg images.

@hoijui
Copy link

hoijui commented Jun 13, 2021

I updated pandoc to version 2.14(.1), and got this same error again.
Reverting back to 2.13 solved it for me.

Can this be reopened, or should I make a new issue?

@jgm
Copy link
Owner

jgm commented Jun 13, 2021

@hoijui There was a regression in 2.14 with SVGs in creating PDFs.
You can find out about it by searching closed issues. It is fixed in master.

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