Skip to main content
Chrome headless requires also the `svg` setting in the `<style>` (`@page` is not enough).
Source Link
Fuhrmanator
  • 2.9k
  • 4
  • 23
  • 33

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --no-pdf-header-footer \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size (A4 or US Letter is default depending on your system?), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

Update with example of putting the CSS for the page size in a <style> block in the SVG:

<svg
   width="154.63478"
   height="213.94911"
   ... >

  <style>
    @page {
      size: 155mm154.63478mm 214mm;213.94911mm;
      margin: 0;
    }
    svg {
      width: 154.63478mm;
      height: 213.94911mm;
    }
  </style>
  <!-- Your SVG content here -->
</svg>

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --no-pdf-header-footer \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size (A4 or US Letter is default depending on your system?), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

Update with example of putting the CSS for the page size in a <style> block in the SVG:

<svg
   width="154.63478"
   height="213.94911"
   ... >

  <style>
    @page {
      size: 155mm 214mm;
      margin: 0;
    }
  </style>
  <!-- Your SVG content here -->
</svg>

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --no-pdf-header-footer \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size (A4 or US Letter is default depending on your system?), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

Update with example of putting the CSS for the page size in a <style> block in the SVG:

<svg
   width="154.63478"
   height="213.94911"
   ... >

  <style>
    @page {
      size: 154.63478mm 213.94911mm;
      margin: 0;
    }
    svg {
      width: 154.63478mm;
      height: 213.94911mm;
    }
  </style>
  <!-- Your SVG content here -->
</svg>
Updates for command-line in 2024, example with a <style> tag in the SVG file to set an arbitrary page size
Source Link
Fuhrmanator
  • 2.9k
  • 4
  • 23
  • 33

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --print-tono-pdf-no-header-footer \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size  (A4 or US Letter is default depending on your system?), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

Update with example of putting the CSS for the page size in a <style> block in the SVG:

<svg
   width="154.63478"
   height="213.94911"
   ... >

  <style>
    @page {
      size: 155mm 214mm;
      margin: 0;
    }
  </style>
  <!-- Your SVG content here -->
</svg>

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --print-to-pdf-no-header \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size(A4 is default), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --no-pdf-header-footer \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size  (A4 or US Letter is default depending on your system?), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

Update with example of putting the CSS for the page size in a <style> block in the SVG:

<svg
   width="154.63478"
   height="213.94911"
   ... >

  <style>
    @page {
      size: 155mm 214mm;
      margin: 0;
    }
  </style>
  <!-- Your SVG content here -->
</svg>

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

 chrome --headless --disable-gpu --print-to-pdf="output.pdf" "input.svg"
chrome \
  --headless \
  --disable-gpu \
  --print-to-pdf-no-header \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size(A4 is default), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

 chrome --headless --disable-gpu --print-to-pdf="output.pdf" "input.svg"

It needs some tweaks to use custom PDF size(A4 is default), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

I'm wondering why it hasn't been mentioned before, but I tested a bunch of different svg->pdf converters and found that the best one is Headless Chrome. It produces the most precise results for me. Before switching to Chrome, I was trying to fight with Inkscape bugs, but many of them are too serious and I can't do much about it (transparency bugs, wrong fonts, etc).

chrome \
  --headless \
  --disable-gpu \
  --print-to-pdf-no-header \
  --print-to-pdf=output.pdf \
  input.svg

It needs some tweaks to use custom PDF size(A4 is default), but I was able to set custom size after some googling and playing with CSS and SVG attributes (check out this answer on stackoverflow)

added 19 characters in body
Source Link
Loading
Source Link
Loading