ASP. NET calls com word to Convert PDF

Source: Internet
Author: User
Turn: http://www.cnblogs.com/DotNet1010/archive/2007/08/29/873826.html
The word-to-PDF function is used in the project. The requirement at the beginning is to make an application. Program Main Code As follows:

Using PDF = Pdfmakerapilib;
String Wordpath =   String . Empty;
String Pdfpath =   String . Empty;

Pdf. Unzip makerapp app =   New Inclumakerapilib. inclumakerapp ();
Int Ireslut = 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 .)

Imports Word = Microsoft. Office. InterOP. Word
Imports PDF = Acrodistxlib Dim Range As   New   Object ()
Range = Word. wdprintoutrange. wdprintalldocument
Dim Item As   New   Object ()
Item = Word. wdprintoutitem. wdprintdocumentcontent
Dim Pagetype As   New   Object ()
Pagetype = Word. wdprintoutpages. wdprintallpages
Dim Manualduplexprint As   New   Object ()
Manualduplexprint =   False
Dim Outputfilename As   String   =   " C: \ topdf \ 123456.ps "

Dim Wordapp As   New Word. 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 ()



Dim Revoke Test =   New Pdf. nvidistiller ()
Using test. bshowwindow =   0

Using test. filetopdf (outputfilename, " C: \ topdf \ 123456.pdf " , "" )
Revoke 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.