Response.ContentType = "application/pdf";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm hf = new HtmlForm();
hf.Controls.Add(GridView1);
//' 有加這一行就不用寫下面的 VerifyRenderingInServerForm 宣告
GridView1.RenderControl(htw);
StringReader sr = new StringReader(sw.ToString());
Document docpdf = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
docpdf.Add(new Paragraph(text,font));
HTMLWorker hw = new HTMLWorker(docpdf);
PdfWriter.GetInstance(docpdf, Response.OutputStream);
docpdf.Open();
hw.Parse(sr);
docpdf.Close();
protected void Button2_Click(object sender, EventArgs e)
{
10 个解决方案
#1
把编码方式设置成默认的或者gbk试试
#2
给你参考:
Dim exptype As ExportFormatType
Dim cttype As String
Dim stm As Stream
Dim fname As String = "sysbugtime"
Dim fext As String
exptype = ExportFormatType.PortableDocFormat
cttype = "application/octet-stream"
fext = ".pdf"
fname = fname & fext
stm = orpt.ExportToStream(exptype)
' If Not (InlineAssignHelper(stm, oRpt.ExportToStream(exptype))) Is Nothing Then
If Not stm Is System.DBNull.Value Then '!!!###
Dim FileSize As Long
FileSize = stm.Length
Dim Buffer As Byte() = New Byte(CInt(FileSize) - 1) {}
stm.Read(Buffer, 0, CInt(FileSize))
stm.Close()
' '读取数据库中保存的内容
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.ContentType = cttype
Response.AddHeader("Content-Length", FileSize.ToString())
Response.AddHeader("Content-Disposition", "attachment;filename=" & fname)
Response.BinaryWrite(Buffer)
Response.Flush()
Response.Close()
Else
lblstatus.Text = "导出失败!"
End If
Dim exptype As ExportFormatType
Dim cttype As String
Dim stm As Stream
Dim fname As String = "sysbugtime"
Dim fext As String
exptype = ExportFormatType.PortableDocFormat
cttype = "application/octet-stream"
fext = ".pdf"
fname = fname & fext
stm = orpt.ExportToStream(exptype)
' If Not (InlineAssignHelper(stm, oRpt.ExportToStream(exptype))) Is Nothing Then
If Not stm Is System.DBNull.Value Then '!!!###
Dim FileSize As Long
FileSize = stm.Length
Dim Buffer As Byte() = New Byte(CInt(FileSize) - 1) {}
stm.Read(Buffer, 0, CInt(FileSize))
stm.Close()
' '读取数据库中保存的内容
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.ContentType = cttype
Response.AddHeader("Content-Length", FileSize.ToString())
Response.AddHeader("Content-Disposition", "attachment;filename=" & fname)
Response.BinaryWrite(Buffer)
Response.Flush()
Response.Close()
Else
lblstatus.Text = "导出失败!"
End If
#3
编码问题,用UTF-8
#4
不然你问题会更多
#5
就是UTF-8了呀
#6
试了,不可以用。。。
#7
大家快来支持下啊,就是不显示中文啊 ,,高手在哪里
#8
utf-8 本来就不支持中文。你可以用gb232!希望有用亲!
#9
这个我也想知道!!
#10
docpdf.Add(new Paragraph(text,font));
是这里的字体引起。
先指定字体类型。
BaseFont _baseFont = BaseFont.CreateFont(@"字体文件", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
例如
BaseFont _baseFont = BaseFont.CreateFont(@"E:\Leo\tab_Tree\452-cai978.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
然后将
docpdf.Add(new Paragraph(text,font));
改为:
docpdf.Add(new Paragraph(text,new Font(_baseFont)));
我用itextsharp 导出PDF一直都是这样用。
是这里的字体引起。
先指定字体类型。
BaseFont _baseFont = BaseFont.CreateFont(@"字体文件", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
例如
BaseFont _baseFont = BaseFont.CreateFont(@"E:\Leo\tab_Tree\452-cai978.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
然后将
docpdf.Add(new Paragraph(text,font));
改为:
docpdf.Add(new Paragraph(text,new Font(_baseFont)));
我用itextsharp 导出PDF一直都是这样用。
#1
把编码方式设置成默认的或者gbk试试
#2
给你参考:
Dim exptype As ExportFormatType
Dim cttype As String
Dim stm As Stream
Dim fname As String = "sysbugtime"
Dim fext As String
exptype = ExportFormatType.PortableDocFormat
cttype = "application/octet-stream"
fext = ".pdf"
fname = fname & fext
stm = orpt.ExportToStream(exptype)
' If Not (InlineAssignHelper(stm, oRpt.ExportToStream(exptype))) Is Nothing Then
If Not stm Is System.DBNull.Value Then '!!!###
Dim FileSize As Long
FileSize = stm.Length
Dim Buffer As Byte() = New Byte(CInt(FileSize) - 1) {}
stm.Read(Buffer, 0, CInt(FileSize))
stm.Close()
' '读取数据库中保存的内容
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.ContentType = cttype
Response.AddHeader("Content-Length", FileSize.ToString())
Response.AddHeader("Content-Disposition", "attachment;filename=" & fname)
Response.BinaryWrite(Buffer)
Response.Flush()
Response.Close()
Else
lblstatus.Text = "导出失败!"
End If
Dim exptype As ExportFormatType
Dim cttype As String
Dim stm As Stream
Dim fname As String = "sysbugtime"
Dim fext As String
exptype = ExportFormatType.PortableDocFormat
cttype = "application/octet-stream"
fext = ".pdf"
fname = fname & fext
stm = orpt.ExportToStream(exptype)
' If Not (InlineAssignHelper(stm, oRpt.ExportToStream(exptype))) Is Nothing Then
If Not stm Is System.DBNull.Value Then '!!!###
Dim FileSize As Long
FileSize = stm.Length
Dim Buffer As Byte() = New Byte(CInt(FileSize) - 1) {}
stm.Read(Buffer, 0, CInt(FileSize))
stm.Close()
' '读取数据库中保存的内容
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.ContentType = cttype
Response.AddHeader("Content-Length", FileSize.ToString())
Response.AddHeader("Content-Disposition", "attachment;filename=" & fname)
Response.BinaryWrite(Buffer)
Response.Flush()
Response.Close()
Else
lblstatus.Text = "导出失败!"
End If
#3
编码问题,用UTF-8
#4
不然你问题会更多
#5
就是UTF-8了呀
#6
试了,不可以用。。。
#7
大家快来支持下啊,就是不显示中文啊 ,,高手在哪里
#8
utf-8 本来就不支持中文。你可以用gb232!希望有用亲!
#9
这个我也想知道!!
#10
docpdf.Add(new Paragraph(text,font));
是这里的字体引起。
先指定字体类型。
BaseFont _baseFont = BaseFont.CreateFont(@"字体文件", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
例如
BaseFont _baseFont = BaseFont.CreateFont(@"E:\Leo\tab_Tree\452-cai978.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
然后将
docpdf.Add(new Paragraph(text,font));
改为:
docpdf.Add(new Paragraph(text,new Font(_baseFont)));
我用itextsharp 导出PDF一直都是这样用。
是这里的字体引起。
先指定字体类型。
BaseFont _baseFont = BaseFont.CreateFont(@"字体文件", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
例如
BaseFont _baseFont = BaseFont.CreateFont(@"E:\Leo\tab_Tree\452-cai978.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
然后将
docpdf.Add(new Paragraph(text,font));
改为:
docpdf.Add(new Paragraph(text,new Font(_baseFont)));
我用itextsharp 导出PDF一直都是这样用。