From f37c8c95c79b8f74bcfa1c34194e54125495609c Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 4 Sep 2017 16:27:22 +0200 Subject: [PATCH] Added test code to convert SVG to PDF by calling Inkscape --- Utility/BotCode/PdfProcessor.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Utility/BotCode/PdfProcessor.cs b/Utility/BotCode/PdfProcessor.cs index 6005a68f..531e3bd3 100644 --- a/Utility/BotCode/PdfProcessor.cs +++ b/Utility/BotCode/PdfProcessor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing.Text; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -134,5 +135,35 @@ namespace Swarmops.Utility.BotCode Console.WriteLine(" done."); } + + public static string TemplateToPdf(string svgFileName) + { + if (svgFileName.Contains('\"')) + { + throw new ArgumentException("Filename must not contain double quotes"); + } + if (svgFileName.Contains(' ')) + { + throw new ArgumentException("Filename must not contain whitespace"); + } + + if (!File.Exists(svgFileName)) + { + throw new ArgumentException("File does not exist"); + } + + string tempFolder = @"/tmp/"; + + Guid guid = new Guid(); + + string tempFileName = tempFolder + guid.ToString("D") + ".pdf"; + + Process process = Process.Start("bash", + "-c \"inkscape --without-gui --export-to-pdf=" + tempFileName + " " + svgFileName + "\""); // inkscape is a package-level dependency + + process.WaitForExit(); + + return tempFileName; + } } }