0

What I need

I am trying to convert a large PDF file to SVG format. I want the SVG file to be able to highlight words (like I can with the PDF) when I open it up using a web browser for example. This PDF has diagrams and different background boxes for different sections of text etc.

My System

Linux Mint 20 using BASH but I also have access to a Windows PC if there is some Windows only software available for this. I can also install a different distro if for some reason there is an rpm tool or something that isn't available for Mint.

What I tried

I have tried the following options on a single page from the PDF (1.pdf) with the corresponding results.

Inkscape - inkscape --without-gui --file=1.pdf --export-plain-svg=1.svg - Highlighting works. The font gets ruined, spacing between words has problems, some letters disappear.

pdf2svg (https://github.com/dawbarton/pdf2svg) - pdf2svg 1.pdf 1.svg - pdf2svgResults were that the svg looked good but highlighting did not work anymore.

convert (ImageMagick) - convert 1.pdf 1.svg - Results were that the svg looked good but highlighting did not work anymore.

dvisvgm - dvisvgm --pdf --output=1.svg 1.pdf - I also tried using the options --no-styles --exact-bbox --no-fonts as well as running svgcleaner afterwards - Results were always that the svg looked good but highlighting did not work anymore.

pstoedit + xfig - pstoedit -f fig 1.pdf 1.fig - using xfig to open the file I can already see the font is completely messed up with black filling the "e"s and spacing problems etc.

Notes

Maybe there are some Inkscape options I am missing or something but I could not find them looking at the man pages. I do not know what exact font the PDF is using, but it is not some weird one, generally looks normal.

If anyone knows of a tool I didn't try or options I haven't tried for tools I used or anything else I would greatly appreciate any help!
Thank you for your time!

6
  • For Inkscape, I think the option --export-plain-svg creates an SVG that contains your PDF converted to an inline-PNG, Base64 encoded. And that SVG will be optimized for printing, not the web. If you want to create an SVG that is kind of responsive, and can be viewed properly in any browser, you have to create an "optimized" SVG. That's a different option. And even then Inkscape cannot work miracles (convert paths to text)
    – knb
    Nov 15 at 11:36
  • @knb Thank you for explaining this. Unfortunately "optimized" SVG didn't make a difference. I noticed using the inkscape GUI that it asks to either import Cairo/Poppler which makes the text appear as glyphs (which looks good but isn't highligtable) or use Internal import which keeps the text as text (and thus highlightable) but destroys the fonts. So I think my problem is even before saving it as SVG at all but rather just as how the PDF is imported...
    – Oha Noch
    Nov 15 at 13:03
  • yes I suspected, but you didn't say how complex your PDF is. But even if you have created SVG output, you still had to tell Inkscape to convert "inline-style" attributes to "CSS style" attributes and that's what the "optimized" SVG export dialog can do for you. Otherwise the SVG would not display properly inside some browsers.
    – knb
    Nov 15 at 14:16
  • 1
    When I saved the optimized SVG I did have "convert CSS to XML attributes" ticked but that did not help. The page I am trying to convert is not simple but not oo complex. It has background boxes for text and a separate row on the right with text as well. I just chekcked and cloudconvert.com managed to convert it how I needed, so I know its possible. My problem is that I cannot upload my entire PDF file to that service due to circumstances and also I would prefer to be able to do it locally anyways.
    – Oha Noch
    Nov 15 at 15:05
  • Could you elaborate on why SVG is important for you? Are you open other output types? Why is highlighting SVG text important? When you say "highlighting did not work anymore" what do you mean exactly?
    – Ryan
    2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.