Index: src/sas/sasgui/guiframe/report_dialog.py
===================================================================
--- src/sas/sasgui/guiframe/report_dialog.py	(revision 463e7ffce130ae386f93cd18b87a1120743e88b5)
+++ src/sas/sasgui/guiframe/report_dialog.py	(revision 69a68979fe94b8f135a602e7f02b162e34616d53)
@@ -13,5 +13,5 @@
 if sys.platform == "win32":
     _STATICBOX_WIDTH = 450
-    PANEL_WIDTH = 500 
+    PANEL_WIDTH = 500
     PANEL_HEIGHT = 700
     FONT_VARIANT = 0
@@ -26,9 +26,9 @@
 
 class BaseReportDialog(wx.Dialog):
-    
+
     def __init__(self, report_list, *args, **kwds):
         """
         Initialization. The parameters added to Dialog are:
-        
+
         :param report_list: list of html_str, text_str, image for report
         """
@@ -48,7 +48,6 @@
         self.report_list = report_list
         # wild card
-        # pdf supporting only on MAC
-        if self.is_pdf:
-            self.wild_card = ' PDF files (*.pdf)|*.pdf|'
+        if self.is_pdf:  # pdf writer is available
+            self.wild_card = 'PDF files (*.pdf)|*.pdf|'
             self.index_offset = 0
         else:
@@ -63,5 +62,5 @@
         """
         hbox = wx.BoxSizer(wx.HORIZONTAL)
-        
+
         # buttons
         button_close = wx.Button(self, wx.ID_OK, "Close")
@@ -75,10 +74,10 @@
                           id=button_print.GetId())
         hbox.Add(button_print)
-        
+
         button_save = wx.Button(self, wx.NewId(), "Save")
         button_save.SetToolTipString("Save this report.")
         button_save.Bind(wx.EVT_BUTTON, self.onSave, id=button_save.GetId())
         hbox.Add(button_save)
-        
+
         # panel for report page
         vbox = wx.BoxSizer(wx.VERTICAL)
@@ -87,5 +86,5 @@
         # set the html page with the report string
         self.hwindow.SetPage(self.report_html)
-        
+
         # add panels to boxsizers
         vbox.Add(hbox)
@@ -103,5 +102,5 @@
         previewh = html.HtmlEasyPrinting(name="Printing", parentWindow=self)
         previewh.PreviewText(self.report_html)
-        
+
     def onPrint(self, event=None):
         """
@@ -118,9 +117,9 @@
         """
         self.Close()
-    
+
     def HTML2PDF(self, data, filename):
         """
         Create a PDF file from html source string.
-        Returns True is the file creation was successful. 
+        Returns True is the file creation was successful.
         : data: html string
         : filename: name of file to be saved
@@ -136,6 +135,5 @@
             self.Update()
             return pisaStatus.err
-        except:
+        except Exception:
             logger.error("Error creating pdf: %s" % sys.exc_value)
         return False
-
Index: src/sas/sasgui/perspectives/fitting/report_dialog.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/report_dialog.py	(revision 78312f78ace85630125cafc0f9f54ed8d905db13)
+++ src/sas/sasgui/perspectives/fitting/report_dialog.py	(revision 69a68979fe94b8f135a602e7f02b162e34616d53)
@@ -57,100 +57,58 @@
 
         fName = dlg.GetPath()
+        basename = os.path.splitext(fName)[0]
         ext_num = dlg.GetFilterIndex()
+        dlg.Destroy()
+
+        if ext_num == 0 and self.index_offset == 0:  # has pdf
+            ext = ".pdf"
+        elif ext_num == 1 - self.index_offset:
+            ext = ".html"
+        elif ext_num == 2 - self.index_offset:
+            ext = ".txt"
+        else:
+            logger.warn("unknown export format in report dialog")
+            return
+        filename = basename + ext
+
+        # save figures
+        pictures = []
+        for num in range(self.nimages):
+            pic_name = basename + '_img%s.png' % num
+            # save the image for use with pdf writer
+            self.report_list[2][num].savefig(pic_name)
+            pictures.append(pic_name)
+
+        # translate png references int html from in-memory name to on-disk name
+        html = self.report_html.replace("memory:img_fit", basename+'_img')
 
         #set file extensions
         img_ext = []
-        pic_fname = []
-        #PDF
-        if ext_num == (0 + 2 * self.index_offset):
-            # TODO: Sort this case out
-            ext = '.pdf'
+        if ext == ".pdf":
+            # write pdf as a pdf file
+            pdf = self.HTML2PDF(data=html, filename=filename)
 
-            fName = os.path.splitext(fName)[0] + ext
-            dlg.Destroy()
-            #pic (png) file path/name
-            for num in range(self.nimages):
-                im_ext = '_img%s.png' % num
-                #img_ext.append(im_ext)
-                pic_name = os.path.splitext(fName)[0] + im_ext
-                pic_fname.append(pic_name)
-                # save the image for use with pdf writer
-                self.report_list[2][num].savefig(pic_name)
+            # delete images used to create the pdf
+            for pic_name in pictures:
+                os.remove(pic_name)
 
-            #put the image path in html string
-            report_frame = self.report_list[0]
-            #put image name strings into the html file
-            #Note:The str for pic_fname shouldn't be removed.
-            if self.nimages == 1:
-                html = report_frame % str(pic_fname[0])
-            elif self.nimages == 2:
-                html = report_frame % (str(pic_fname[0]), str(pic_fname[1]))
-            elif self.nimages == 3:
-                html = report_frame % (str(pic_fname[0]), str(pic_fname[1]),
-                                       str(pic_fname[2]))
-
-            # make/open file in case of absence
-            f = open(fName, 'w')
-            f.close()
-            # write pdf as a pdf file
-            pdf = self.HTML2PDF(data=html, filename=fName)
-
-            #open pdf
+            #open pdf viewer
             if pdf:
                 try:
-                    #Windows
-                    os.startfile(str(fName))
-                except Exception:
-                    try:
-                        #Mac
+                    if os.name == 'nt':  # Windows
+                        os.startfile(fName)
+                    elif sys.platform == "darwin":  # Mac
                         os.system("open %s" % fName)
-                    except Exception:
-                        #DO not open
-                        pass
-            #delete image file
-            for num in range(self.nimages):
-                os.remove(pic_fname[num])
-            return
-        #HTML + png(graph)
-        elif ext_num == (1 - self.index_offset):
-            ext = '.html'
-            for num in range(self.nimages):
-                img_ext.append('_img4html%s.png' % num)
-            report_frame = self.report_list[0]
-        #TEXT + pdf(graph)
-        elif ext_num == (2 - self.index_offset):
-            ext = '.txt'
-            # changing the image extension actually changes the image
-            # format on saving
-            for num in range(self.nimages):
-                img_ext.append('_img4txt%s.pdf' % num)
-            report = self.report_list[1]
-        else:
-            return
+                except Exception as exc:
+                    # cannot open pdf
+                    logging.error(str(exc))
 
-        #file name
-        fName = os.path.splitext(fName)[0] + ext
-        dlg.Destroy()
+        elif ext == ".html":
+            with open(filename, 'w') as f:
+                f.write(html)
 
-        #pic (png) file path/name
-        for num in range(self.nimages):
-            pic_name = os.path.splitext(fName)[0] + img_ext[num]
-            pic_fname.append(pic_name)
-        #put the image path in html string
-        if ext_num == (1 - self.index_offset):
-            if self.nimages == 1:
-                report = report_frame % os.path.basename(pic_fname[0])
-            elif self.nimages == 2:
-                report = report_frame % (os.path.basename(pic_fname[0]),
-                                         os.path.basename(pic_fname[1]))
-            elif self.nimages == 3:
-                report = report_frame % (os.path.basename(pic_fname[0]),
-                                         os.path.basename(pic_fname[1]),
-                                         os.path.basename(pic_fname[2]))
-        f = open(fName, 'w')
-        f.write(report)
-        f.close()
+        elif ext == ".txt":
+            with open(filename, 'w') as f:
+                f.write(self.report_list[1])
+
         self.Update()
-        #save png file using pic_fname
-        for num in range(self.nimages):
-            self.report_list[2][num].savefig(pic_fname[num])
