C#word Convert PDF

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.