此代碼工作完美。問題在於該按鈕位於控制更新面板內,並導致一些問題。但我已經修好了,現在可以工作了。Itextsharp下載PDF
Dim documentoPDF As New Document(PageSize.A4, 10, 10, 10, 10)
Dim memStream As MemoryStream = New MemoryStream()
Dim writer As PdfWriter = PdfWriter.GetInstance(documentoPDF, memStream)
documentoPDF.Open()
Dim Paragraph1 As Paragraph = New Paragraph("First paragraph")
documentoPDF.Add(New Paragraph(Paragraph1))
documentoPDF.Close()
Dim bytesInStream As Byte() = memStream.ToArray()
memStream.Close()
'Dim memorystreaam As MemoryStream = New MemoryStream(bytesInStream)
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf")
Response.Buffer = True
Response.Cache.SetCacheability(HttpCacheability.NoCache)
'Response.OutputStream.Write(memStream.GetBuffer(), 0, memStream.GetBuffer().Length)
Response.BinaryWrite(bytesInStream)
Response.End()
您的代碼無法使用哪種方式?即預期的行爲是什麼以及觀察到的行爲是什麼? – mkl
@mkl看,我實現了代碼,問題是pdf永遠不會下載到我的電腦。 –
當您嘗試下載時,究竟會發生什麼?您是否檢查過所有相關的日誌文件?你有沒有在調試器中運行代碼?您是否使用了tcpdump工具來捕獲和分析Web流量? – mkl