convert Html to doc in c# and return it as binary
i have this code to convert a html page to doc, but i have a question
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document();
Object oMissing = System.Reflection.Missing.Value;
wordDoc = word.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
word.Visible = false;
Object filepath = "c:\\pagina.html";
Object confirmconversion = System.Reflection.Missing.Value;
Object readOnly = false;
Object saveto = "c:\\doc.pdf";
Object oallowsubstitution = System.Reflection.Missing.Value;
wordDoc = word.Documents.Open(ref filepath, ref confirmconversion, ref readOnly, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object fileFormat = WdSaveFormat.wdFormatPDF;
wordDoc.SaveAs(ref saveto, ref fileFormat, ref oMissing, ref oMissing, ref oMissing,
开发者_如何学JAVA ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oallowsubstitution, ref oMissing,
ref oMissing);
How can i save in a variable bytes[] , and dont save as in the hdd, is possible?
Im not sure SaveAs method support memorystream, why not try to read the file as byte after save and then delete it from harddrive. The line below will read the file as byte
byte[] pdfFile = System.IO.File.ReadAllBytes((string)saveto);
You can write your document into a MemoryStream and read it from the MemoryStream - the read-method is similar to the one of FileStream. So no hdd involved - and you've got your byte[] and I guess you want to write it into an HTTP-Header for a download.
精彩评论