PDF
(Adding message template to the top of the page)
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{message|Write the content here to display this box}}
<message>Write the content here to display this box</message>
MDriven reports are created with open document text (odt) or open document spreadsheet formats (ods).
MDriven reports are created with open document text (odt) or open document spreadsheet formats (ods).


Line 6: Line 6:
'''Please note''' that this solution with automating Microsoft Word only works well in a client that can access Word locally, like the WPF client. If you want to convert to PDF server-side in Turnkey or the MDrivenServer, we recommend an online service or a .net component rather than trying to call Word. This is because Word components don't work well being called from inside IIS.
'''Please note''' that this solution with automating Microsoft Word only works well in a client that can access Word locally, like the WPF client. If you want to convert to PDF server-side in Turnkey or the MDrivenServer, we recommend an online service or a .net component rather than trying to call Word. This is because Word components don't work well being called from inside IIS.


Here is an example of using a [[Serverside PDF|third-party component]]:
Here is an example of using a [[Documentation:Serverside PDF|third-party component]]:
     Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();         
     Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();         
     foreach (var file in files)         
     foreach (var file in files)         
Line 32: Line 32:
         app.Quit();
         app.Quit();
       }
       }
To use C# code in Turnkey, look at [[Training:CodeDress|CodeDress]].
To use C# code in Turnkey, look at [[Documentation:CodeDress|CodeDress]].
[[Category:Reports]]
[[Category:Reports]]
{{Edited|July|12|2024}}
{{Edited|July|12|2025}}

Latest revision as of 05:56, 19 February 2025

This page was created by Hans.karlsen@mdriven.net on 2018-05-14. Last edited by Stephanie@mdriven.net on 2025-02-19.

MDriven reports are created with open document text (odt) or open document spreadsheet formats (ods).

If you need to convert the odt to PDF, there are online services available. If you would rather do this yourself, you can buy a third-party library that has this ability or you can simply automate Word (for odt) and have it save your odt as a PDF.

Please note that this solution with automating Microsoft Word only works well in a client that can access Word locally, like the WPF client. If you want to convert to PDF server-side in Turnkey or the MDrivenServer, we recommend an online service or a .net component rather than trying to call Word. This is because Word components don't work well being called from inside IIS.

Here is an example of using a third-party component:

   Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();        
   foreach (var file in files)        
   {          
     if (System.IO.Path.GetExtension(file.FileName.ToLower()) == ".odt" )          
     {            
            if (File.Exists(file.FileName)) // Protect againts doublettes
            {
              _Document doc = word.Documents.Open(file.FileName);
              doc.Activate();
              string newfile;
              if (pdf)
              {
                newfile = System.IO.Path.ChangeExtension(file.FileName, ".pdf");
                doc.SaveAs2(newfile, WdSaveFormat.wdFormatPDF);
              }
              object oMissing = System.Reflection.Missing.Value;
              doc.Close(ref oMissing, ref oMissing, ref oMissing);
              File.Delete(file.FileName);
              file.FileName = newfile;
            }
        
        }
        Microsoft.Office.Interop.Word._Application app = word.Application;
        app.Quit();
      }

To use C# code in Turnkey, look at CodeDress.