First of all, create a folder in the project Wordpath, this folder is stored in your Word and PDF.
First, prepare a word to put in (. doc).
This also needs to be referenced, this reference 2015 has a reference-add reference-extension Microsoft.Office.Interop.Word.dll
And then, prepare the copy code.
Public BOOLWordtopdf (stringSourcePath) { BOOLresult =false; Word.Application Application=NewWord.Application (); Word.Document Document=NULL; Try{application. Visible=false; Document=application. Documents.Open (SourcePath); stringPdfpath = Sourcepath.replace (". doc",". pdf");//PDF Storage Location if(! File.exists (@PDFPath))//PDF exists, no further conversions required{document. ExportAsFixedFormat (Pdfpath, Word.WdExportFormat.wdExportFormatPDF); } result=true; } Catch(Exception e) {Console.WriteLine (e.message); Result=false; } finally{document. Close (); } returnresult; }
After pasting you will find that your reference does not add error, so add a reference, like this using Word = Microsoft.Office.Interop.Word;
After you add the quote you will find that Emma should have no problem, if there is a problem you can Baidu check. Hahaha ...
The second is to find a place to call, here, in the Page_Load called the
if(!IsPostBack) { stringStrword = Server.MapPath ("/wordpath/***.doc");//Document Pathwordtopdf (Strword); stringBrowserType = Page.Request.Browser.Type;//Browser type judgment if(BrowserType! ="IE6"&& BrowserType! ="IE7") {//here is the generated good PDF is to do a show, before this step the PDF has been generatedResponse.Write ("<script language= ' javascript ' >window.open ('/wordpath/***.pdf ');</script>"); } }
is to use Microsoft's method to save the document in PDF or XPS format.
If you need an extension, you can visit the website
https://docs.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-2010/bb398522 (v=vs.100)
C#word Convert PDF