From 8adef93943c36acaa7bdb0ba35361d2b30746cb3 Mon Sep 17 00:00:00 2001 From: Manuel Lera Ramirez Date: Thu, 27 May 2021 15:09:33 +0200 Subject: [PATCH] first commit --- license | 7 +++++++ printSvg2Pdf.sh | 11 +++++++++++ readme.md | 23 +++++++++++++++++++++++ template.html | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 license create mode 100755 printSvg2Pdf.sh create mode 100644 readme.md create mode 100644 template.html diff --git a/license b/license new file mode 100644 index 0000000..56b3e10 --- /dev/null +++ b/license @@ -0,0 +1,7 @@ +Copyright 2021 Manuel Lera-Ramirez + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/printSvg2Pdf.sh b/printSvg2Pdf.sh new file mode 100755 index 0000000..d649d50 --- /dev/null +++ b/printSvg2Pdf.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Path in MacOS +chrome_executable="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + +# Path to the template.html file in this folder +template_file="path/to/template.html" + +sed "s/__targetfile__/${1}/" "$template_file" > printSvg2Pdf_temp.html +"$chrome_executable" --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf=$2 printSvg2Pdf_temp.html +rm printSvg2Pdf_temp.html diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..96b6e3d --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +# PrintSvg2Pdf + +A simple bash script to print an svg to pdf without extra margins using headless chrome. + +## How to use +In the file `printSvg2Pdf.sh` set the following variables: + +* `chrome_executable` to point to the path of your chrome executable. +* `template_file` to point to the path of the file `template.html`, included into the repository. + +Then simply: + +``` +bash printSvg2Pdf.sh input_file.svg output_file.pdf +``` + +## What it does + +`template.html` with an object tag where your image will be referenced in an `object` tag. It has some css to remove all margins, and with javascript it sets the style attribute `@page` to fit exactly the size of the image. + +## Acknowledgements + +This comes from [this inkscape forum question](https://inkscape.org/forums/questions/exporting-svg-with-linkedembedded-images-to-pdf-without-rasterising/#c28675), and from [this answer](https://stackoverflow.com/a/52128129/5622322) on StackOverflow. \ No newline at end of file diff --git a/template.html b/template.html new file mode 100644 index 0000000..936a9fa --- /dev/null +++ b/template.html @@ -0,0 +1,35 @@ + + + + + + + + + + + + \ No newline at end of file