winforms - render pdf from memorystream -
i have searched entire day solution, somehow couldn't find it. wanted info database (binary file such pdf) memorystream (which succeeded so), problem when wish preview file webbrowser control.
so code goes:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.data.sqlclient; using system.io; namespace memorystreamtest { public partial class form1 : form { public form1() { initializecomponent(); } memorystream memory = new memorystream(); //byte[] temp; private void form1_load(object sender, eventargs e) { memory = getblobfile(); } private memorystream getblobfile() { memorystream ms = new memorystream(); string sql = "select [snapshotpdf] [dbtest].[dbo].[samplepdf] id = " + 21; sqlconnection conn = new sqlconnection("data source=database;initial catalog=dbtest; user id=test; password=test;"); sqlcommand comm = new sqlcommand(sql, conn); conn.open(); byte [] result = (byte[])comm.executescalar(); conn.close(); if (result != null) { ms.write(result, 0, result.length); ms.position = 0; } homecoming ms; } private void button1_click(object sender, eventargs e) { //webbrowser1.documenttext = "application/pdf"; webbrowser1.documentstream = memory; } } }
actually webbrowser output content memory, image above it's rendered text... how can forcefulness render pdf?
if not possible utilize webbrowser control, there other controls can utilize in winforms preview/render pdf memory.
you have implement async pluggable protocol, e.g. iclassfactory, iinternetprotocol... utilize cointernetgetsession register protocol. when ie calls implementation, can serve image info memory/provide mime type.
it's bit tedious, doable. @ iinternetprotocol , pluggable protocols documentation on msdn.
winforms pdf memorystream
No comments:
Post a Comment