Long ago Insus.net in the realization of the "Flexpaper realization document online Browsing" http://www.cnblogs.com/insus/archive/2011/07/21/2112369.html. It was just a display, and there was no online conversion function.
Now, Insus.net has turned to ASP. NET MVC application development from ASP. So you want to implement the functionality of the document library with an MVC application. Since the new version of Flexpaper cannot mask the print functionality, it is still used back to the original Flexpaper component, which also means using some of the class libraries and files from the previous article. However, after downloading, you cannot use it directly, you need to modify some paths and parameters.
In an MVC application, it is not possible to use the literal control to pass parameters like ASP., you need to take into account the passing parameters to the JS class, in order not to directly pass the real file name to JS, but also need to do additional processing. This is done so that the user sees the point to the address and uses the address to download the document.
OK, let's get started, but we have to get ready.
Whether a user uploads a PDF file in a database or in a folder in the application, we first get the ID that finds it, which can be either an integer or a string, but only a uniqueness.
From a previous download to the source program, put it in an MVC application, such as:
In order to block the printing function, please highlight this file in use. If you don't want to block it, it is recommended to download the latest version directly from the website. In addition insusdocumentvieewer.swf this frame display format file, also moved to JS this directory, convenient software maintenance and management, different from the previous article is placed in the SWF directory. Also open it, modify the parameters inside the path:
In addition, the Pdf2swf.exe file is placed under the Bin directory:
This pdf2swf.exe you can use the latest version of the. The old certainly has no problem. It is downloaded from the Swftools website. Under Download, it is not possible to install under the 64-bit Windows 8 and Windows R2. But you can install it under a client XP or Windows7, then install the directory and copy the Pdf2swf.exe.
One more preparation is to create a temp directory under the MVC application. This directory is a SWF file that stores temporary conversions, or if your PDF is a binary data stream, when the PDF is generated, it is also done in this temp temporary directory.
Ready, this demo, insus.net is stored in a PDF file in a folder, but some of its basic information is present in the database table.
Create a model first:
This model has two properties, one is ID, and the other is swffile. The former is the ID that the user sees in the address bar, which can be used to find the path to the PDF in the table or the binary stream data stored in the database. The latter is the file name that will be converted to SWF format.
Under the Entities directory, create an entity:
This entity, which is the ability to convert a PDF file or a binary database to a SWF document format.
In #14 and #15 line code, you can understand.
#16行是一空行, if your PDF file is a binary data stream, you should first convert the binary data into a PDF document and store it in the temp directory. Do not know how to turn, you can refer to this "Data flow creation file" http://www.cnblogs.com/insus/archive/2011/04/11/2012733.html
#17行, a file name is randomly generated with no suffix.
In this demo, Insus.net has copied a PDF document into the temp directory, and if your PDF document is in another directory, you are pointing to it.
#18和 #19 is to find the PDF document with the SWF file (not actually generated at this time).
#21至 #36 is the conversion SWF document. More parameter settings, can refer to the official website help.
#38至 (s) is to get the converted SWF file name and add it to the list. It is used by the controller of MVC in the future.
Next, create a actionresult and a Jsonresult method under Controllers HomeController.
Under the Views\home directory, create a view, the view name, which is the ActionResult method name in the controller:
Here is the View code:
#1部分是样式代码, in the previous article, it is a style file that is now moved directly to the view.
#2部分, refer to the jquery library and note that no, the latest version of the jquery library is available.
#3部分, is the reference to the relevant JS library.
#5部分, is completely copy the old, not the slightest change.
#4部分:
In the success method, there are two places where JavaScript is added to the head. To assign the SWF file to the Swffile variable first, the second is to add the Insusdocumentview.js class library to the head.
It's done. Look at the effect at run time: