Ignore:
Timestamp:
Feb 17, 2015 8:45:44 AM (9 years ago)
Author:
Mathieu Doucet <doucetm@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
e843a1c
Parents:
5dfdfa7
Message:

Move report_dialog.py files to xhtml2pdf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/perspectives/invariant/report_dialog.py

    r79492222 r4ec242e  
    1818import os 
    1919import wx.html as html 
     20import logging 
    2021ISPDF = False 
    2122if sys.platform == "win32": 
     
    246247    def HTML2PDF(self, data, filename): 
    247248        """ 
    248         Create a PDF file from html source string.  
     249        Create a PDF file from html source string. 
     250        Returns True is the file creation was successful.  
    249251         
    250252        : data: html string 
    251253        : filename: name of file to be saved 
    252254        """ 
    253         import ho.pisa as pisa 
    254         f = file(filename, "wb") 
    255         # pisa requires some extra packages, see their web-site 
    256         pdf = pisa.CreatePDF(data, f) 
    257         # close the file here otherwise it will be open until quitting 
    258         #the application. 
    259         f.close() 
    260  
    261         return not pdf.err 
    262  
    263          
    264          
     255        try: 
     256            from xhtml2pdf import pisa 
     257            # open output file for writing (truncated binary) 
     258            resultFile = open(filename, "w+b") 
     259            # convert HTML to PDF 
     260            pisaStatus = pisa.CreatePDF(data, dest=resultFile) 
     261            # close output file 
     262            resultFile.close() 
     263            self.Update() 
     264            return pisaStatus.err 
     265        except: 
     266            logging.error("Error creating pdf: %s" % sys.exc_value) 
     267        return False 
Note: See TracChangeset for help on using the changeset viewer.