wxPostscriptDC problems

Quoting Andrew Jones <arjones6@gmail.com>:

I have an application where I create a graph that I need to be able to print
to postscript in order to collate it with some other postscript I generate.
On linux I was able to get this to work by going through the print framework
to print to a file without prompting the user. When I port this to windows
however, the print framework uses a wx.PrinterDC instead of the
wx.PostscriptDC so instead of postscript I get some unusable printer code.
I'm trying to just create my own wx.PostscriptDC and plot directly to that,
but I keep getting an error message complaining of an 'invalid postscript
dc'. Does anybody know how to either force windows to use the PostScriptDC,
or how to use a PostScriptDC directly?

Here is my attempt to use a PostscriptDC directly:

def OnPrint(s, evt):
    printData = wx.PrintData()
    printData.SetPaperId(wx.PAPER_LETTER)
    printData.SetPrintMode(wx.PRINT_MODE_FILE)

    tf = tempfile.mktemp(".ps")
    printData.SetFilename(tf)
    dc = wx.PostScriptDC(printData)

    dc.StartPage()
    s.Plot(dc)
    dc.EndPage()
    s.disp.ViewPSFile(tf)

The wx.PostScriptDC requires that you call dc.StartDoc. That's where
it creates the output file (and assigns it to the m_pstream variable
you see mentioned in the exception message.) Call EndDoc when you are
done, to write the last bits to the file and close it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

That fixed it. Thanks a lot!

Andrew

···

On Thu, Apr 24, 2008 at 8:56 PM, Robin Dunn robin@alldunn.com wrote:

Quoting Andrew Jones arjones6@gmail.com:

I have an application where I create a graph that I need to be able to print

to postscript in order to collate it with some other postscript I generate.

On linux I was able to get this to work by going through the print framework

to print to a file without prompting the user. When I port this to windows

however, the print framework uses a wx.PrinterDC instead of the

wx.PostscriptDC so instead of postscript I get some unusable printer code.

I’m trying to just create my own wx.PostscriptDC and plot directly to that,

but I keep getting an error message complaining of an 'invalid postscript

dc’. Does anybody know how to either force windows to use the PostScriptDC,

or how to use a PostScriptDC directly?

Here is my attempt to use a PostscriptDC directly:

def OnPrint(s, evt):

printData = wx.PrintData()

printData.SetPaperId(wx.PAPER_LETTER)

printData.SetPrintMode(wx.PRINT_MODE_FILE)



tf = tempfile.mktemp(".ps")

printData.SetFilename(tf)

dc = wx.PostScriptDC(printData)



dc.StartPage()

s.Plot(dc)

dc.EndPage()

s.disp.ViewPSFile(tf)

The wx.PostScriptDC requires that you call dc.StartDoc. That’s where

it creates the output file (and assigns it to the m_pstream variable

you see mentioned in the exception message.) Call EndDoc when you are

done, to write the last bits to the file and close it.

Robin Dunn

Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users