Serializing Print Documents

H

HaySeed

I need to save print output to the database for future retrieval.

I assumed that the best way to do this was to use a BinaryFormatter to
convert my PrintDocument to a byte array - strore the binary stream - then
deserialize it upon recall.

Unfortunately the PrintDocument is not serializable.

How can I store the completed PrintDocument to the DB?
 
A

Alex Clark

Can't think of any easy way to do it really. There are approaches I can
think of though, and they are as follows:

Rather than serializing an entire PrintDocument, why not serialize the
object(s) that represent the data you printed? Next time you want to
retrieve them for print/print-preview, you just get the serialized objects
from the database, deserialize them and pass them off to your print routine
the same way you did the first time. The advantages are that, if you find
and fix a bug in the output of your printing routine (say it's not
formatting a string properly) then this reprint benefits from the fix.
Alternatively, the disadvantage is that if you totally change your print
routine this may no longer work.

Option #2 would be to print a separate copy to a PDF print driver (you can
get them free), and then save the filestream into the database.

Option #3 is to rewire your routine to use the new uber-cryptic
virtually-documentation-less printing methods of .NET 3.x so that you
effectively build an XPS document. You then serialize that XPS document to
your database and print it as well, meaning you can reproduce your printout
exactly as it was.


Regards,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top