You can print to the Windows 10 PDF printer, by using the PrintOut
method and specifying the fourth output file name parameter, as in the following example:
/// <summary>
/// Convert a file to PDF using office _Document object
/// </summary>
/// <param name="InputFile">Full path and filename with extension of the file you want to convert from</param>
/// <returns></returns>
public void PrintFile(string InputFile)
{
// convert input filename to new pdf name
object OutputFileName = Path.Combine(
Path.GetDirectoryName(InputFile),
Path.GetFileNameWithoutExtension(InputFile)+".pdf"
);
// Set an object so there is less typing for values not needed
object missing = System.Reflection.Missing.Value;
// `doc` is of type `_Document`
doc.PrintOut(
ref missing, // Background
ref missing, // Append
ref missing, // Range
OutputFileName, // OutputFileName
ref missing, // From
ref missing, // To
ref missing, // Item
ref missing, // Copies
ref missing, // Pages
ref missing, // PageType
ref missing, // PrintToFile
ref missing, // Collate
ref missing, // ActivePrinterMacGX
ref missing, // ManualDuplexPrint
ref missing, // PrintZoomColumn
ref missing, // PrintZoomRow
ref missing, // PrintZoomPaperWidth
ref missing, // PrintZoomPaperHeight
);
}
The OutputFile
is a full path string of the input document you would like to convert, and the doc is a regular document object. For more info about the doc please see the following MSDN links for _Document.PrintOut()
The PrintOut
in the example results a silent print, when you print through the specified inputFile
to the OutputFileName
, which will be placed in the same folder as the original document, but it will be in PDF format with the .pdf
extension.