The latest project requires the ability to browse documents online. Prepare to use FlexPaper with ipv2swf.
The main requirements are:
When there are a large number of documents, the number of pages is several hundred, and the number of pages is thousands.
The size of the corresponding ➔ file is also greater than 50 MB.
Split the function into three parts as needed:
BytesUpload: Supports resumable upload of large files.
BytesFile conversion Service: Convert Pdf to Swf in the background.
BytesOnline browsing: Load by page.
The file upload part is implemented by my colleagues. Here we mainly talk about the background services and online browsing part.
File conversion Service
The general idea is:
When the backend service is set to scan the pdfpathfile, if the hosts file is found, then use ipv2swf.exe to convert the PDF file to a Swf file page by page and save it to the folder corresponding to the file name in SwfPath.
SwfTools tool javas2swf is used here: Download
Main Code:
20172swf call code // PDF converted to SWFprivate void convert1_toswf (string pdfFile) {using (Process p = new Process () {SystemLog. currentLogger. debug (string. format ("processing {0 }... ", pdfFile); string %2swfexe =" %2swf.exe "; string savePath = GetSavePathFromName (pdfFile); string cmd = %2swfexe; string args = "-t \" "+ pdfFile +" \ "-o \" "+ savePath + pdfFile. split ('\\'). last (). replace (". pdf "," ") +" mongo.swf \"- S drawonlyshapes-s flashversion = 9 "; p. startInfo. fileName = cmd; p. startInfo. arguments = args; p. startInfo. useShellExecute = false; // The standard output stream provided by this class is only 2 k. Do not redirect p. startInfo. redirectStandardOutput = false; p. startInfo. createNoWindow = true; p. start (); p. priorityClass = ProcessPriorityClass. high; p. waitForExit (); SystemLog. currentLogger. debug (string. format ("{0} processed. ", PdfFile); if (AppConfiguration. deleteConvertedPdf) {// Delete the Pdf File after the conversion is complete. delete (pdfFile); SystemLog. currentLogger. debug (string. format ("{0} deleted. ", PdfFile);} else {// rename the Pdf File. move (pdfFile, pdfFile + ". bak "); SystemLog. currentLogger. debug (string. format ("{0} has been renamed. ", PdfFile ));}}}
|
A strange Bug occurs when writing services. When publishing as a service, the PDF file used for testing gets stuck every time it is converted to 37 pages, however, when debugging with the command line, everything is OK. Google found that the original output stream problem of Process: the output stream is only 2 kb, while the SWF will produce a large amount of output, and the 2 kb will soon run out. |
During the test, we found that text loss occurs during the conversion process. Here the-s drawonlyshapes parameter is used, and all Pdf files are converted as images. This ensures compatibility, but sacrifices space. The Swf generated as an image is much larger than the text Swf. I wonder if you have any good solutions.
Online browsing
FlexPaper supports paging loading by using the syntax {filename [*, padding], total pages.
Main Code:
FlexPaper paging loading <a id = "viewerPlaceHolder" style = "width: 800px; height: 600px; display: block "> </a> <script type =" text/javascript "> var fp = new FlexPaperViewer ('flexpaperviewer ', 'viewerplaceholder', {config: {SwfFile: 'swffolder/<% = Folder %>/{<% = Folder %> [*, 02.16.swf, <% = PageNum %>} ', localeChain: "zh_CN ", // Scale: 1, ZoomTransition: 'easeout', ZoomTime: 0.5, ZoomInterval: 0.2, FitPageOnLoad: false, FitWidthOnLoad: false, PrintEnabled: true, FullScreenAsMaxWindow: false, success: false, MinZoomSize: 0.2, MaxZoomSize: 5, SearchMatchAll: false, InitViewMode: 'portrait', viewmod=lsvisible: true, effect: true, NavToolsVisible: true, effect: true, SearchToolsVisible: true }}); </script>
|
FlexPaper cannot load Chinese file names. If the circle in the upper-right corner is always transferred, check whether the file name is correct. |
References
C # System. Diagnostics. Process WaitForExit lock problem analysis and solution when calling an external program
FlexPaper + SWFTools implement imitation of Baidu Library and some minor problems
Cmd2swf command line parameters
Solve the Problem of FlexPaper multipart Loading
Source code
Page loading: FlexPaper.zip
File conversion service: PDFtoSWFService.zip