ASP. NET calls COM Word to Convert Pdf-zt

Source: Internet
Author: User

The function of converting word to pdf is used in the project. The initial requirement is to create an application to convert the main Code as follows:
Copy and save

UsingPDF = paimakerapilib;StringWordPath =String. Empty;StringPdfPath =String. Empty; PDF. PDFMakerApp app =NewInclumakerapilib. inclumakerapp ();IntIReslut = app. CreatePDF (wordPath, pdfPath, PDF. PDFMakerSettings. kConvertAllPages,True,False,True, System. Type. Missing );If(IReslut = 0 ){This. LblInfo. Text ="Conversion successful! ";}Else{// Conversion failed!    This. LblInfo. Text = Enum. GetName (Typeof(PDF. PDFMakerRetVals), iReslut );}



Later, ASP. NET was required to call the code. Could it be okay to copy the code to the Web form?
When webdev.webserver.exe is used, OK. When IIS is used, the conversion fails. It took some time to find that two users are different. One is the administrator, for an Asp.net account or network Service, check whether IIS is 5.0 or 6.0. I want to solve this problem by changing the setting permissions. I have changed a lot. The effect is from one error to another!
Later, I checked the information on the Internet and was inspired by the following code: (I like to use VB. NET to perform a COM test .)
Copy and save

ImportsWord = Microsoft. Office. Interop. WordImportsPDF = nvidistxlibDimRangeAs New Object() Range = Word. WdPrintOutRange. wdPrintAllDocumentDimItemAs New Object() Item = Word. WdPrintOutItem. wdPrintDocumentContentDimPageTypeAs New Object() PageType = Word. WdPrintOutPages. wdPrintAllPagesDimManualDuplexPrintAs New Object() ManualDuplexPrint =FalseDimOutPutFileNameAs String="C: \ Topdf \ 123456.ps"DimWordAppAs NewWord. Application () wordApp. Documents. Open ("C: \ Topdf \ 123456.doc",False,False,False,"","",False,"","", Word. WdOpenFormat. wdOpenFormatAuto ,,,,,,"") WordApp. Documents. Save () wordApp. ActivePrinter ="Adobe PDF"WordApp. PrintOut (False, Range, OutPutFileName, Item, 1,"", PageType,False,True,"",,False, 0, 0, 0, 0) wordApp. Quit ()DimExport test =NewPDF. nvidistiller () using test. bShowWindow = 01_test. FileToPDF (OutPutFileName,"C: \ Topdf \ 123456.133","") Export test =Nothing''Continuous calling may cause errors. You can kill the process first.


The idea is to first use Word to convert doc to ps, and then use nvidistiller to convert ps to pdf. After testing, it can be successfully executed under IIS.
Write the code here. If you encounter such problems, you can avoid detours!
Of course, it is best not to call COM. The method is to find out, that is, to spend money. Use it first!

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.