0

I want to printout a complete email to pdf. the standard printer is selected as microsoft Print to PDF. Running the printout method, a saveas window occures and I dont know, how to handle that programatically.

I still know the way to convert via a word object, but that does not work, as screenshots will not be printed and the header is missing. So, this is not an answer for me: Save complete email, body and header, as PDF

Can anybody tell me how to deal with the saveas dialog and the filename of the resulting pdf?

One possibility would be to print the mail to an xps file (print to file - how to do that). After that, I could convert xps to pdf using PDFSharp.

Regards and thanks, Jan

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Jan021981
  • 521
  • 3
  • 28
  • Ok, I managed to save it as a word document by MI.SaveAs(filename, olSaveAsType.olDoc) This document contains all the content and can be easily saved as a pdf. – Jan021981 Dec 14 '21 at 10:51
  • There is no need to save it as a doc and then convert the saved file to a PDF one. Instead, use the Word object model from Outlook to get a PDF from the ground. – Eugene Astafiev Dec 14 '21 at 11:17

2 Answers2

2

The Word editor can be used for saving the message body as a PDF file.

Word.Document doc = mailItem.GetInspector.WordEditor;
doc.SaveAs2(fullPath, FileFormat: Word.WdSaveFormat.wdFormatPDF);

Note, you need to add a COM reference to the Word object model to your project before using its object model in the code.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
0

For anyone like me who was psyched to find the use of SaveAs2 to PDF from Outlook.

***The header of the emails DO NOT GET OUTPUT, only the body.

Instead of this:

enter image description here

You get just this:

enter image description here