diff --git a/Utility/BotCode/PdfProcessor.cs b/Utility/BotCode/PdfProcessor.cs index 971a04a0..3f71ace8 100644 --- a/Utility/BotCode/PdfProcessor.cs +++ b/Utility/BotCode/PdfProcessor.cs @@ -85,7 +85,7 @@ namespace Swarmops.Utility.BotCode Console.Write(@"Regenerating document #{0}", startId); Process process = Process.Start("bash", - "-c \"convert -density 600 -background white -flatten " + StorageRoot + firstPart + " " + + "-c \"convert -density 600 -background white -alpha remove " + StorageRoot + firstPart + " " + StorageRoot + firstPart + "-%04d.png\""); // Density 600 means 600dpi means production-grade conversion @@ -110,49 +110,67 @@ namespace Swarmops.Utility.BotCode public static void Rerasterize(Document document, PdfProcessorOptions options = PdfProcessorOptions.None) { - if (document.Description.Length < 32) + using (StreamWriter debugWriter = new StreamWriter("/tmp/pdfregen-debug.txt")) { - throw new InvalidOperationException("Document has no GUID"); + debugWriter.WriteLine("Document description: " + document.Description); + debugWriter.Flush(); + + if (document.Description.Length < 32) + { + throw new InvalidOperationException("Document has no GUID"); + } + + // a ServerFileName looks like "2015/06/22/29c88f2b-44e6-4a05-a6b0-f9aaec835c5b-00000001-0007-01-0019.png" + // 1234567890123456789012345678901234567890123456789012345678901234 + + debugWriter.WriteLine("Document server file name: " + document.ServerFileName); + debugWriter.Flush(); + + if (document.ServerFileName.Length < 64) + { + throw new InvalidOperationException("Server file name has wrong scheme"); + } + + if (!document.ServerFileName.ToLowerInvariant().EndsWith(".png")) + { + throw new InvalidOperationException("Document is not rasterized"); + } + if (document.ForeignId == 0 && ((int) options & (int) PdfProcessorOptions.ForceOrphans) == 0) + { + throw new InvalidOperationException("Document is an orphan"); + } + + int density = 75; + string suffix = string.Empty; + + if (((int) options & (int) PdfProcessorOptions.HighQuality) > 0) + { + density = 600; + suffix = "-hires"; // hires conversion uses different filename + } + + + string firstPart = document.ServerFileName.Substring(0, 64); + + debugWriter.WriteLine("Regenerating... "); + debugWriter.Flush(); + + string commandLine = "convert -density " + density.ToString(CultureInfo.InvariantCulture) + + " -background white -alpha remove " + StorageRoot + firstPart + " " + + StorageRoot + firstPart + + "-%04d" + suffix + ".png"; + + debugWriter.WriteLine("Running \"" + commandLine + "\""); + debugWriter.Flush(); + + Process process = Process.Start("bash", + "-c \"" + commandLine + "\""); + + process.WaitForExit(); + + debugWriter.WriteLine("Done."); + debugWriter.Flush(); } - - // a ServerFileName looks like "2015/06/22/29c88f2b-44e6-4a05-a6b0-f9aaec835c5b-00000001-0007-01-0019.png" - // 1234567890123456789012345678901234567890123456789012345678901234 - - if (document.ServerFileName.Length < 64) - { - throw new InvalidOperationException("Server file name has wrong scheme"); - } - if (!document.ServerFileName.ToLowerInvariant().EndsWith(".png")) - { - throw new InvalidOperationException("Document is not rasterized"); - } - if (document.ForeignId == 0 && ((int) options & (int) PdfProcessorOptions.ForceOrphans) == 0) - { - throw new InvalidOperationException("Document is an orphan"); - } - - int density = 75; - string suffix = string.Empty; - - if (((int) options & (int) PdfProcessorOptions.HighQuality) > 0) - { - density = 600; - suffix = "-hires"; // hires conversion uses different filename - } - - - string firstPart = document.ServerFileName.Substring(0, 64); - - Console.Write("Regenerating document..."); - - Process process = Process.Start("bash", - "-c \"convert -density " + density.ToString(CultureInfo.InvariantCulture) + " -background white -alpha remove " + StorageRoot + firstPart + " " + - StorageRoot + firstPart + - "-%04d" + suffix + ".png\""); - - process.WaitForExit(); - - Console.WriteLine(" done."); } public static string TemplateToPdf(string svgFileName)