Recently, a project needs to convert files (such as Word, Excel, txt, and image) to PDF files. After searching the documents, there are many implementation methods, such as calling a virtual printer for conversion,
Use third-party components (such as itextsharp and sharppdf. Now both are used. When HTML is converted to a PDF file, I first intercept HTML as an image and then convert it
Pdf. If you have good suggestions, you can discuss them together.
What are the best implementation methods for converting PDF files to excel files?
First paste some source code,: http://download.csdn.net/source/2646952
// <Summary> <br/> // convert EXCEL to PDF <br/> /// </Summary> <br/> /// <Param name = "file_inputname "> </param> <br/> Public void printsheettopdf (string fileinputname) {try <br/>{< br/> getprintername (ref printername, ref obj_printer_settings, ref otype); printdocument prtdoc = new printdocument (); <br/> currentprintername = prtdoc. printersettings. printername; // get the default printer name <br/> // change the default printer <br/> setdefaprinprinter (printername. trim (); <br/> // notify you of changes <br/> sendpolicymessage (hwnd_broadcast, wm_wininichange, 0, "Windows "); <br/> If (fileinputname = "") <br/>{< br/> return; <br/>}< br/> filepath = filesavepath + "//" + getfilename (fileinputname) + ". PDF "; <br/> otype. invokemember ("init", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, null); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"output", filepath}); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"showsettings", "never"}); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"showpdf", "no"}); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"showprogress", "no"}); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"showprogressfinished", "no"}); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"suppresserrors", "yes"}); <br/> otype. invokemember ("setvalue", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {"confirmoverwrite", "no"}); <br/> otype. invokemember ("writesettings", system. reflection. bindingflags. invokemethod, null, obj_printer_settings, new object [] {true}); <br/> If (file. exists (filepath) = true) <br/>{< br/> file. delete (filepath); <br/>}< br/> Object objmissing = system. type. missing; <br/> Object objvalue = true; <br/> Microsoft. office. interOP. excel. application objexcel = new Microsoft. office. interOP. excel. application (); <br/> Microsoft. office. interOP. excel. workbook objworkbook = objexcel. workbooks. open (filesavepath + "//" + fileinputname, objmissing, objvalue, objmissing, objmissing, missing, fail, objmissing, fail, objmissing ); <br/> objexcel. visible = false; <br/> for (INT I = 1; I <objworkbook. worksheets. count; I ++) <br/>{< br/> _ worksheet active_workbook = (_ worksheet) objexcel. worksheets. get_item (I); <br/> active_workbook.pagesetup.zoom = false; <br/> latency = 1; <br/> active_workbook.pagesetup.fittopagestall = 10; <br/>}< br/> objexcel. activeworkbook. printout (objmissing, objmissing); <br/> for (INT f_intstep = 1; f_intstep <20000; f_intstep +) <br/>{< br/> system. threading. thread. sleep (100); <br/> If (file. exists (filepath) = true) <br/>{< br/> break; <br/>}< br/> objworkbook. close (false, fileinputname, false); <br/> objexcel. quit (); <br/> objworkbook = NULL; <br/> objexcel = NULL; <br/> int K = 0; <br/> intptr T = new intptr (objexcel. hwnd); <br/> getwindowthreadprocessid (T, out k); <br/> system. diagnostics. PROCESS p = system. diagnostics. process. getprocpolicyid (k); <br/> P. kill (); <br/> obj_printer_settings = NULL; <br/> // change the default printer <br/> setdefaprinprinter (currentprintername. trim (); <br/> // notify you of changes <br/> sendpolicymessage (hwnd_broadcast, wm_wininichange, 0, "Windows "); <br/>}< br/> catch (exception e) <br/>{< br/> obj_printer_settings = NULL; <br/> // throw E; <br/>}< br/>}