Added test code to convert SVG to PDF by calling Inkscape

This commit is contained in:
Rick Falkvinge
2017-09-04 16:27:22 +02:00
parent 3279b9af1d
commit f37c8c95c7
+31
View File
@@ -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;
}
}
}