如何使用C#在Windows窗体中将二进制数据显示为pdf文件 [英] how to show binary data to pdf file in windows forms using C#

查看:92
本文介绍了如何使用C#在Windows窗体中将二进制数据显示为pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示pdf文件,首先我将pdf文件转换为二进制文件然后保存在数据库中,现在我想将二进制文件转换为pdf文件。



我的代码如下:





SqlConnection con = new SqlConnection(ObjDb.consrtring);

con。打开();

SqlCommand cm = con.CreateCommand();



//字符串Query = ObjDb.GetDataField(从中选择DocImage tblPdoc其中ID =+ picID,DocImage);



cm.CommandText =从tblPdoc中选择DocImage,其中ID =+ picID;

// cm = new SqlCommand(Query,con);

// cm.CommandText = Query;

// string qq = Query;

byte [] binaryData =(byte [])cm .ExecuteScalar();



File.WriteAllBytes(。pdf,binaryData);



string s = Encoding.UTF8.GetString(binaryData);













this.axAcroPDF1.LoadFile(s);



con.Close();

返回s;



编码文件后显示在此格式中并且pdf文件未显示







?U?Db ? @ \\〜〜 R??? & V wF ?b ??? f FW? F·FTFV6FS7G&V?ЧQƺU? L· P 25 V·tZW5ڑ([B $OύǽR֮K7C} RMUn? ?^< u ? Cy 2h 1 } ?

«; Ƣ :a 1Ic ]k r烙 ? N Y%3En ?4 Z? }?I7

? ???%? ??vA 6 U ] Ժ; } %%?L } % :? RB ?b / \ @ M1i ?? / F 14:; ZLN ??瓦特/ |} ?? Mha m& ?? / eػ ?&?Tz a Yi7U VFp





请告知我该怎么办?

i want to show pdf file ,first i convert the pdf file to binary then i saved in database ,now i want to convert binary to pdf file .

my code is given below


SqlConnection con =new SqlConnection(ObjDb.consrtring);
con.Open();
SqlCommand cm=con.CreateCommand();

//string Query = ObjDb.GetDataField("Select DocImage from tblPdoc where ID=" + picID, "DocImage");

cm.CommandText="Select DocImage from tblPdoc where ID=" + picID;
//cm = new SqlCommand(Query, con);
// cm.CommandText = Query;
// string qq = Query;
byte[] binaryData = (byte[])cm.ExecuteScalar();

File.WriteAllBytes(".pdf",binaryData);

string s =Encoding.UTF8.GetString(binaryData);






this.axAcroPDF1.LoadFile(s);

con.Close();
return s;

after encoding the file is showing in this formate and pdf file is not showing



UDb��@�\~�� �R�&������V�wF�b"�f��FW"�f�FTFV6�FS��7G&VЧ��Qƺ��U L P� ��v���t��ZW�5ڑ�'�([b$�O���ύ�����ǽ�R�֮K��7��c�}��RMUn��^<�u����� ����Cy��ߖ�2h��1����}���
«;�Ƣ:a�1Ic�]k����r烙�����������N��Y%3En��4���֬Z��}I7
��%��vA��6��U�]�Ժ;���}%%L�}��� %����:�RB�b/���\@M���1i���/?�f�����:;�ź�L�N���w�/|�}Mha�m&� /eػ�&Tz�a�Yi7U��VFp����


kindly tell me what should i do?

推荐答案

O ύ ǽ R K 7 c } RMUn ? ?^< u ? Cy 2h 1 } ?

«; Ƣ: a1Ic] KR烙?NY%3EN?4 ֬Z? }?I7

? ???%? ??vA 6 U ] Ժ; } %%?L } %:?RBB / \ @ M1i ?? / F 14:; ZLN? ? w / | } ??Mha m& ?? / eػ ?&?Tz a Yi7U VFp





请告诉我该怎么办?
�O���ύ�����ǽ�R�֮K��7��c�}��RMUn��^<�u����� ����Cy��ߖ�2h��1����}���
«;�Ƣ:a�1Ic�]k����r烙�����������N��Y%3En��4���֬Z��}I7
��%��vA��6��U�]�Ժ;���}%%L�}��� %����:�RB�b/���\@M���1i���/?�f�����:;�ź�L�N���w�/|�}Mha�m&� /eػ�&Tz�a�Yi7U��VFp����


kindly tell me what should i do?


这篇关于如何使用C#在Windows窗体中将二进制数据显示为pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆