Esempio n. 1
0
        //This requires the HtmlAgilityPack
        //string htmlSource = filename to a *.html/*.htm file with path
        private void GenerateReportFromHtmlToPdf(string htmlSource, string pdfTarget, Placeholders rep)
        {
            var tmpFile = Path.Combine(Path.GetDirectoryName(pdfTarget), Path.GetFileNameWithoutExtension(htmlSource) + Guid.NewGuid().ToString().Substring(0, 10) + ".html");

            GenerateReportFromHtmlToHtml(htmlSource, tmpFile, rep);
            LibreOfficeWrapper.Convert(tmpFile, pdfTarget, _locationOfLibreOfficeSoffice);
            File.Delete(tmpFile);
        }
Esempio n. 2
0
        private void PrintDocx(string templateFile, string printername, Placeholders rep)
        {
            var docx            = new DocXHandler(templateFile, rep);
            var ms              = docx.ReplaceAll();
            var tempFileToPrint = Path.ChangeExtension(Path.GetTempFileName(), ".docx");

            StreamHandler.WriteMemoryStreamToDisk(ms, tempFileToPrint);
            LibreOfficeWrapper.Print(tempFileToPrint, printername, _locationOfLibreOfficeSoffice);
            File.Delete(tempFileToPrint);
        }
Esempio n. 3
0
        private void GenerateReportFromDocxToHtml(string docxSource, string htmlTarget, Placeholders rep)
        {
            var docx    = new DocXHandler(docxSource, rep);
            var ms      = docx.ReplaceAll();
            var tmpFile = Path.Combine(Path.GetDirectoryName(htmlTarget), Path.GetFileNameWithoutExtension(docxSource) + Guid.NewGuid().ToString().Substring(0, 10) + ".docx");

            StreamHandler.WriteMemoryStreamToDisk(ms, tmpFile);
            LibreOfficeWrapper.Convert(tmpFile, htmlTarget, _locationOfLibreOfficeSoffice);
            File.Delete(tmpFile);
        }
Esempio n. 4
0
        private void PrintHtml(string templateFile, string printername, Placeholders rep)
        {
            var htmlContent = File.ReadAllText(templateFile);

            htmlContent = HtmlHandler.ReplaceAll(htmlContent, rep);
            var tempFileToPrint = Path.ChangeExtension(Path.GetTempFileName(), ".html");

            File.WriteAllText(tempFileToPrint, htmlContent);
            LibreOfficeWrapper.Print(tempFileToPrint, printername, _locationOfLibreOfficeSoffice);
            File.Delete(tempFileToPrint);
        }
Esempio n. 5
0
 /// <summary>
 /// Prints the file and optionally generates from placeholders
 /// </summary>
 /// <param name="templateFile">The input file. May be docx, html or pdf</param>
 /// <param name="printerName">optional printername to print on. If this value is empty, the default printer is used</param>
 /// <param name="rep">A collection of placeholders to be applied if the input file is docx or html.</param>
 public void Print(string templateFile, string printerName = null, Placeholders rep = null)
 {
     if (rep != null)
     {
         if (templateFile.EndsWith(".docx"))
         {
             PrintDocx(templateFile, printerName, rep);
         }
         else if (templateFile.EndsWith(".html") || templateFile.EndsWith(".htm"))
         {
             PrintHtml(templateFile, printerName, rep);
         }
         else
         {
             LibreOfficeWrapper.Print(templateFile, printerName, _locationOfLibreOfficeSoffice);
         }
     }
     else
     {
         LibreOfficeWrapper.Print(templateFile, printerName, _locationOfLibreOfficeSoffice);
     }
 }