I'm working on a UWP application, written in c#, and I need to convert to pdf: - office documents (doc, docx, xls, xlsx, ppt, pptx) - images - Web pages
The application has to work in x86, x64, ARM, ARM64 architectures.
I know there are third party converter libraries on the market but only a few of them work in an ARM64 context or in UWP.
My idea is to use (in Windows 10) the "Microsoft PDF printer" that allows the users to save most of the file formats to PDF.
I found many posts asking for the same question but none of them really contains a helpful answer.
The code I found and tested is the following:
PrintDocument doc = new PrintDocument()
{
//DocumentName = safeDir + fileName,
PrinterSettings = new PrinterSettings()
{
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = safeDir + fileName,
}
};
doc.Print();
The above code generates a valid but empty pdf. How should I set the original file content?
For example, if I have a Word file named myreport.docx, should I convert it to byte array and set it in somewhere?
Thank you in advance.