Public classOffice2pdf { Public BOOLDocconverttopdf (stringSourcePath,stringTargetPath) { //StreamReader reader = new StreamReader ("Temp.doc", Encoding.GetEncoding ("gb2312")); //string text = Reader. ReadToEnd (); //Aspose.Words.Document doc = new Aspose.Words.Document (); //Aspose.Words.DocumentBuilder builder = new Documentbuilder (DOC); //Builder. Write (text); //Doc. Save ("Temp.pdf", saveformat.pdf); //Reader. Close (); BOOLresult =false; Word.wdexportformat ExportFormat=Word.WdExportFormat.wdExportFormatPDF; ObjectParammissing =Type.Missing; Word.applicationclass wordapplication=NewWord.applicationclass (); Word.Document worddocument=NULL; Try { ObjectParamsourcedocpath =SourcePath; stringParamexportfilepath =TargetPath; Word.wdexportformat Paramexportformat=ExportFormat; BOOLParamopenafterexport =false; Word.wdexportoptimizefor paramexportoptimizefor=Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Word.wdexportrange Paramexportrange=Word.WdExportRange.wdExportAllDocument; intParamstartpage =0; intParamendpage =0; Word.wdexportitem Paramexportitem=Word.WdExportItem.wdExportDocumentContent; BOOLParamincludedocprops =true; BOOLParamkeepirm =true; Word.wdexportcreatebookmarks Paramcreatebookmarks=Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; BOOLParamdocstructuretags =true; BOOLParambitmapmissingfonts =true; BOOLParamuseiso19005_1 =false; Worddocument=WordApplication.Documents.Open (refParamsourcedocpath,refParammissing,refparammissing,refParammissing,refParammissing,refparammissing,refParammissing,refParammissing,refparammissing,refParammissing,refParammissing,refparammissing,refParammissing,refParammissing,refparammissing,refparammissing); if(Worddocument! =NULL) Worddocument.exportasfixedformat (Paramexportfilepath, Paramexportformat, Paramopenafterexport, Paramexportoptimizefor, Paramexportrange, Paramstartpage, Paramendpage, Paramexportitem, Paramincludedocprops, Paramkeepirm, Paramcreatebookmarks, ParamD Ocstructuretags, Parambitmapmissingfonts, Paramuseiso19005_1,refparammissing); return true; } Catch(Exception ex) {ex. Writelog (ex. ToString ()); return false; } finally { if(Worddocument! =NULL) {Worddocument.close (refParammissing,refParammissing,refparammissing); Worddocument=NULL; } if(Wordapplication! =NULL) {Wordapplication.quit (refParammissing,refParammissing,refparammissing); Wordapplication=NULL; } GC. Collect (); Gc. WaitForPendingFinalizers (); Gc. Collect (); Gc. WaitForPendingFinalizers (); } returnresult; } }
Convert Excel to PDF