public async Task ConvertOfficeFile(string inFilePath, string outFilePath) { string errText = "NONE"; try { PDFDoc pdfDoc = new PDFDoc(); OfficeToPDFOptions options = null; //string pathToPdfTronFontResources = "C:\\Users\\hliao\\Documents\\Github\\FieldMobileApp\\App\\Field.Mobile\\Field.Mobile.Droid\\obj\\Debug\\100\\designtime\\Resource.designer.cs"; //options.SetLayoutResourcesPluginPath(pathToPdfTronFontResources); pdftron.PDF.Convert.OfficeToPDF(pdfDoc, inFilePath, options); await pdfDoc.SaveAsync(outFilePath, SDFDocSaveOptions.e_remove_unused); } catch (Exception ex) { pdftron.Common.PDFNetException pdfNetEx = new pdftron.Common.PDFNetException(ex.HResult); if (pdfNetEx.IsPDFNetException) { errText = string.Format("Exeption at line {0} in file {1}", pdfNetEx.LineNumber, pdfNetEx.FileName); errText += Environment.NewLine; errText += string.Format("Message: {0}", pdfNetEx.Message); } else { errText = ex.ToString(); } } if (!errText.Equals("NONE")) { //look at the error text var x = errText; } }
static void FlexibleConvert(String input_filename, String output_filename) { // Start with a PDFDoc (the conversion destination) using (PDFDoc pdfdoc = new PDFDoc()) { OfficeToPDFOptions options = new OfficeToPDFOptions(); options.SetSmartSubstitutionPluginPath(input_path); // create a conversion object -- this sets things up but does not yet // perform any conversion logic. // in a multithreaded environment, this object can be used to monitor // the conversion progress and potentially cancel it as well DocumentConversion conversion = pdftron.PDF.Convert.StreamingPDFConversion( pdfdoc, input_path + input_filename, options); // actually perform the conversion // this particular method will not throw on conversion failure, but will // return an error status instead if (conversion.TryConvert() == DocumentConversionResult.e_document_conversion_success) { int num_warnings = conversion.GetNumWarnings(); // print information about the conversion for (int i = 0; i < num_warnings; ++i) { Console.WriteLine("Warning: " + conversion.GetWarningString(i)); } // save the result pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized); // done Console.WriteLine("Saved " + output_filename); } else { Console.WriteLine("Encountered an error during conversion: " + conversion.GetErrorString()); } } }