Convert DOC to PDF Online Based on .NET Technology
Convert DOC to PDF Online Based on .NET Technology
PDF (Portable Document Format) is a development standard published by Adobe for global electronic document publishing. It is a universal file format that supports multiple compression methods. Because its file format has nothing to do with the operating system platform, it has become an ideal file format for electronic document distribution and digital information dissemination on the Internet.
How to use the program from the Web application system to directly generate the DOC document into the PDF document format and publish the electronic document? This problem has become more and more important with the combination of Web application systems and PDF document publishing. Currently, there are two common methods for converting DOC to PDF documents using .NET code.
1. Use .NET call script implementation
By writing the JS file converted to PDF in windows, and then calling the script file in .NET. After actual testing, if the WORD document has more than 100 pages, the conversion will take about 20 minutes. The occupancy rate of the entire CPU is close to 95%-100%. The disadvantage of this method is low conversion efficiency.
2. Via virtual printer
Install a virtual printer, you can use it to print the current document into a PDF document. Of course, you also need to install OFFICE software. The disadvantage of this method is that it cannot realize real-time DOC to PDF conversion.
The following will introduce the method of directly using ASP.NET to generate PDF files from DOC files and publish them during the development of the Web application system. The real-time document conversion efficiency of this method is high and no OFFICE software is required. It simplifies the implementation method and gives simple steps to implement the program code.
.NET Programming Realization
The development environment is VS2008, and the programming language is C#.
2. Secondly, reference the downloaded dll file in your own Web project.
3. Drag and drop a button from the toolbox of the ASP.NET project that you are going to build and add it to the web page, and write the running code under the button.
A. The first step is to load the WORD document to be converted. Generally, it is loaded with a path + file name. After reading the DOC file, it will remain in the memory as a memory stream, waiting for the next call.
B. The second step is to set the DPI, length, width, and other parameters of the converted PDF document.
C. The third step is to create a PDF object, generate a PDF document, and save the PDF document to the specified file directory.
Run Your .NET Project
After writing the above code, click the "Run and Debug" button in VS2008. After running the web page, click the button in the web interface, and the converted PDF document will be generated in the designated storage location and provided to the user. At this point, the conversion of DOC to PDF is complete.
At present, most of the methods for converting DOC to PDF in ASP.NET are offline conversion for users to download. This kind of method is not only more complicated in implementation and application but also cannot reflect real-time performance. Using a third-party PDF converter library can realize real-time conversion without installing Microsoft Office software on the machine. This method is not only simple, but also has better automation in terms of security, stability, scalability, speed, and functions. It is a very good choice.