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!