以编程方式下载pdf [英] Download pdf programatically
本文介绍了以编程方式下载pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用vb.net或c#?下载pdf并存储到磁盘?
How can I download a pdf and store to disk using vb.net or c#?
该URL(pdf)在最终版本之前进行了一些修改
The url (of the pdf) has some rediection going on before the final pdf is reached.
我尝试下面,但当我尝试在本地打开时,pdf似乎已损坏,
I tried the below but the pdf seems corrupted when I attempt to open locally,
Dim PdfFile As FileStream = File.OpenWrite(saveTo)
Dim PdfStream As MemoryStream = GetFileStream(pdfURL)
PdfStream.WriteTo(PdfFile)
PdfStream.Flush()
PdfStream.Close()
PdfFile.Flush()
PdfFile.Close()
非常感谢,
KS
推荐答案
p>您可以尝试使用WebClient(System.Net命名空间)类来执行此操作,以避免任何流在您身边工作。
You can try to use the WebClient (System.Net namespace) class to do this which will avoid any stream work on your side.
以下C#代码抓取IRS表单并将其保存到C:\Temp.pdf。
The following C# code grabs an IRS form and saves it to C:\Temp.pdf.
using(WebClient client = new WebClient())
{
client.DownloadFile("http://www.irs.gov/pub/irs-pdf/fw4.pdf", @"C:\Temp.pdf");
}
这篇关于以编程方式下载pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文