Show
Ignore:
Timestamp:
11/28/07 20:48:45 (16 years ago)
Author:
jerome
Message:

Finalized support for MS documents.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/mscrap.py

    r527 r529  
    2424 
    2525import os 
    26 import urllib2 
     26import tempfile 
    2727 
    2828import pdlparser 
     
    5656             
    5757    def getJobSize(self) : 
    58         """Counts pages in a Microsoft Word (r) (tm) (c) (etc...) document.""" 
    59         return 0 
     58        """Counts pages in a Microsoft Word (r) (tm) (c) (etc...) document. 
     59 
     60           First we convert from .doc to .ps, then we use the PostScript parser. 
     61        """ 
     62        doctops = 'xvfb-run -a abiword --import-extension=.doc --print="%(outfname)s" "%(infname)s"' 
     63        workfile = tempfile.NamedTemporaryFile(mode="w+b") 
     64        try : 
     65            outfname = workfile.name 
     66            infname = self.filename 
     67            status = os.system(doctops % locals()) 
     68            if status or not os.stat(outfname).st_size : 
     69                raise pdlparser.PDLParserError, "Impossible to convert input document %(infname)s to PostScript" % locals() 
     70            psinputfile = open(outfname, "rb") 
     71            try : 
     72                (first, last) = self.parent.readFirstAndLastBlocks(psinputfile) 
     73                import postscript 
     74                return postscript.Parser(self.parent,  
     75                                         outfname,  
     76                                         (first, last)).getJobSize() 
     77            finally : 
     78                psinputfile.close() 
     79        finally :     
     80            workfile.close() 
     81        raise pdlparser.PDLParserError, "Impossible to count pages in %(infname)s" % locals()