this article illustrates the way Python implements the transformation of DOC into PDF format documents. Share to you for your reference, as follows:

 coding:utf-8 doc2pdf.py: Python #-*- -*- # script to convert doc to PDF with bookmarks Requires Office SP2 #! # 2007 Requires Python for Win32 extension import sys, OS from win32com.client import Dispatch, constants, gencache def doc2pdf (input, output): w = Dispatch ("Word.Application" try: doc (input) = w.Documents.Open, ReadOnly = 1) and doc.ExportAsFixedFormat (output, constants.wdExportFormatPDF, and Item = constants.wdExportDocumentWithMarkup, CreateBookmarks = constants.wdExportCreateHeadingBookmarks) return 0 except: return 1 finally: w.Quit (constants.wdDoNotSaveChanges) Generate all the support we # can. def GenerateSupport (enable Python COM): # Support for Word 2007 this is generated by: makepy.py -i # "Microsoft Word 12 Object Library gencache.EnsureModule" ('{00020905-0000-0000-C000-000000000046}', 0, 8, 4) def (main): Print (len (sys.argv) (if) LEN (sys.argv) = = 2): input = sys.argv[1] output = os.path.splitext (input [0]+'.pdf' elif (len) (sys.argv) = = 3): input = sys.argv[1] output = sys.argv[2] else: input = u'BA06007013.docx'#word output = u'BA06007013.pdf'#pdf document document name name if (not os.path.isabs (input)): input = os.path.abspath (input) if (not os.path.isabs (output)): output = os.path.abspath (output) try: (GenerateSupport) = doc2pdf (RC input, output return RC except: return -1) if __name__=='__mai N__': Print (Hello) RC = main (if) rc: sys.exit (RC) sys.exit (0) 

php

 < called py; DOCTYPE> < HTML! Xmlns= "http://www.w3.org/1999/xhtml" > < head> < meta http-equiv= "Content-Type" content= "text/html; charset=utf-8 /> < title> project; check detection system < /title> < style type= text/css > html{font-size:16px fieldset{width:1080px;}; margin: 0 Auto; legend{font-weight:bold font-size:14px;}}; label{float:left; width:120px; margin-left:10px;.Left{margin-left:120px};}}} span{color:.Input{width:150px; #666666; < /style> < script language=JavaScript> <! -- InputCheck (CheckForm) / / function / / {/ / if (CheckForm.projectna Me.value = = "") {/ / Alert / / ("please enter a project name!"); / / (CheckForm.projectname.focus); / / return (false);} / / / / if (document.getElementById ("projectsumb") ".Value==") {/ / Alert / / ("please enter the project!"); / / (CheckForm.projectname.focus); / / return (false);}} / / < /script> < /head> < body> < div> < fieldset> < legend> project check detection system < /legend> < form name= "CheckForm" method= "post" action= "index.php" onSubmit= "return InputCheck (this) > < div> < br/> < label for= >" ProjectName "project name: < /label> < input id=" ProjectName "name=" ProjectName "type=" text "style=" width: 400px "/> < divp/> < div> < br/> < label for= "projectsumb" > < /label> project: < textarea name= "projectsumb" id= "projectsumb" style= "height:400px; width:800px; > < /textarea> < div/> < div> < br/> < br/> < input type=" submit "name=" submit "value=" /> detection "; < /div> < div> < br/> < label name=" result "> < /label> test results: < label name= outresult & gt; < /label> < br/> < div/> < /form> < br/> < br/> < /div> < /body> < /html> < PHP? $name=mb_convert_encoding ($_POST['projectname']," GBK "," UTF-8 "); / / $sumb=mb_convert_encoding ($_POST['projectsumb']," GBK "," UTF-8 "); / / $path1=../docTopdf/commFile/test.doc" $program=; "D:/Users/Administrator/Anaconda3/python../docTopdf/DocToPdf/test1.py"; # use absolute path.$name. "".$sumb $output = exec ($program) / / $output = nl2br (shell_exec ($program); echo mb_convert_encoding ($output), "UTF-8", "GBK"); > 

?

more Python related content of interested readers can view this topic station: "Python" _blank "file and directory operations," "skills summary target=" _blank ">Python" , encoding skills summary "Python data structure and algorithm tutorial " and "Python ", summarizes the skills in the use of function "Python " string manipulation skills summary and "Python in the order entry and "

classic tutorial

hope the It is helpful to the design of Python program.

This paper fixed link:http://www.script-home.com/python-implementation-of-the-method-of-converting-doc-into-pdf-format-documents.html | Script Home | +Copy Link

Article reprint please specify:Python implementation of the method of converting doc into PDF format documents | Script Home

You may also be interested in these articles!