So, I have a winform that must search some document to print.
It can be in .rtf, .doc(and docx) or pdf.
The document are stored in a dataBase in BLOB format, and in another field, I got the extension in varchar2 format, and I get them in byte format on my winform.
These documents can be pdf, rtf, doc or docx. Then, when I take them from the DataBase, they are byte[], and I know their format with a field in the DB that contains .pdf, .rtf etc...
And to print them, I want to register them in my desk, in their actual format (known with Extension properties stored in the DB. And then, when they are in my desk, I want to print them.
So, when I got a Blob in DB with Extension .pdf , I want to register this documents as a pdf in my desk, and print it.
I sucessfully do it with rtf, but with the others, I always got ìncorrect format`errors on this code :
fichierSortie = new FileStream(fullPath + echange.Extension, FileMode.Create); ;
enregistreurFichier = new StreamWriter(fichierSortie);
string pmessage = "";
byte[] text = echange.DocEchange;
using (var file = new MemoryStream(text))
using (var reader = new StreamReader(file))
{
reader.BaseStream.Seek(0, SeekOrigin.Begin);
while (!reader.EndOfStream)
{
pmessage += reader.ReadLine();
}
}
enregistreurFichier.Write(pmessage);
enregistreurFichier.Close();
fichierSortie.Close();
ANd the printing part :
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = true;
PrinterSettings settings = new PrinterSettings();
foreach (string printer in PrinterSettings.InstalledPrinters)
{
settings.PrinterName = printer;
if (settings.IsDefaultPrinter)
{
settings.Duplex = Duplex.Simplex;
}
}
wordApp.Documents.Open(fullPath + echange.Extension); //for VS 2008 and earlier - just give missing for all the args
wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
wordApp.ActiveDocument.PrintOut(false); //as before - missing for remaining args, if using VS 2008 and earlier
wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges); //ditto
So, it seems I must use some if/else to deal with all format.
But I do not found any way to register my byte, open it and print it for doc and pdf.
Can somebody help me sove those problems?
Thank you.