Forum How do I...?

how to export an SVG as a pdf, with same size as source file?

argniest
I am searching in vain, I thought I saw a way to do this. Is there a command line option I can send using prince.exe to tell the pdf file to use the same width and height of the SVG file?

I have been experimenting with prince today, and its looking beautiful. But since my SVG files are generated by users *(using our own custom drawing software)* then I never know the width and height of the SVG file. The width and height will always be different.

So I was hoping there is a command line option to tell Prince.exe to go ahead and just make the PDF file the same size as the SVG incoming/input file

Thank you
mikeday
There is a --page-size option which takes the same syntax as the CSS @page size property, eg.
prince --page-size "10cm 8cm" input.svg -o output.pdf
argniest
Also, I thought I read somewhere about an undocumented method to tell the PDF generator to make the pdf as the same size as the incoming SVG file? Is there a way to do that?

THANKS!!!!!!!!!!!!!!!

I am loving this product just after a few hours of using it. So powerful, so fast, and so lightweight too!
mikeday
There is no option for this, but you can do it with JavaScript:
prince --script size.js input.svg -o out.pdf

where size.js is something like this:
window.onload = function() {
    var svg = document.documentElement;
    var width = svg.getAttribute("width");
    var height = svg.getAttribute("height");
    if (width != null && height != null) {
        var style = document.createElement("style");
        style.textContent = "@page { size: "+width+" "+height+" }";
        svg.appendChild(style);
    }
};

This creates a new <style> element with the appropriate @page rule.
argniest
YOU ARE AMAZING!!!!!!!!!!!!!!!
argniest
I did notice something else, I am wondering about. I see in the svg file that was made by another tool I am working on (this code at the beginning of it)
<svg xmlns="http://www.w3.org/2000/svg" width="4998px" height="2226px" TK="0 0 4998 2226">

So I used this command line to make a pdf file like this:
prince Test1InFile.svg --output Test1OutFle.pdf --pdf-title="Sample Prince SVG to PDF Document" --pdf-author=Scott --no-compress --page-size "4998px 2226px" --log=Prince.log.txt

I don't know how exactly to describe what happened, but it looks like it clipped some of the data on the right side and the bottom off. So it is missing some data in the pdf file.

If I use a command line like this, then it works fine, I am not missing any data, and the PDF looks stellar!

prince Test1InFile.svg --output Test1OutFle.pdf --pdf-title="Sample Prince SVG to PDF Document" --pdf-author=Scott --no-compress --page-size "142cm 71cm" --log=Prince.log.txt

Just FYI - the 142cm x 71cm is in fact the original size of the SVG file that I made in this other program, which is like 55.x inches wide by like 27.x inches tall. It is a special diagram that will be plotted on a poltter.

I thought I was reading somewhere on your website, about some kind of undocumented setting about changing the dpi settings? And I am wondering if that is what is causing the clipping to be happening here on my original SVG data

I attached a zoomed out sample of a sample diagram that was made from my web application, that I want to convert into a PDF file. Just so you can get a visual of what I am talking about here...if you look closely at the top right and bottom left, you can see the clipping

But when use the centimeter for the height and width, then the entire diagram shows up in the pdf file made from your Prince software.

Thanks!!!
  1. samplePDF from SVG using Prince.png2.3 MB
    sample network diagram
mikeday
Does the SVG have a viewBox attribute? If not, Prince will try to determine it automatically, but perhaps it's not quite big enough.
argniest
I just did a search in the SVG file, and there was no match on viewbox.
mikeday
Oh actually set --page-margin=0 first before trying anything else. I forgot about that. :)