本文介绍如何使用spire.pdf从url地址中下载pdf文档。
c#
using system.io;
using system.net;
using spire.pdf;
namespace downloadpdffromurl
{
class program
{
static void main(string[] args)
{
//创建pdfdocument对象
pdfdocument doc = new pdfdocument();
//创建webclient对象
webclient webclient = new webclient();
//从url地址下载pdf数据,并保存为流
using (memorystream ms = new memorystream(webclient.downloaddata("http://www.e-iceblue.com/images/sample.pdf")))
{
//加载流
doc.loadfromstream(ms);
}
//保存为pdf文档
doc.savetofile("result.pdf", fileformat.pdf);
}
}
}
vb.net
imports system.io
imports system.net
imports spire.pdf
namespace downloadpdffromurl
class program
shared sub main(byval args() as string)
'创建pdfdocument对象
dim doc as pdfdocument = new pdfdocument()
'创建webclient对象
dim webclient as webclient = new webclient()
'从url地址下载pdf数据,并保存为流
imports(memorystream ms = new memorystream(webclient.downloaddata("http:'www.e-iceblue.com/images/sample.pdf")))
{
'加载流
doc.loadfromstream(ms)
}
'保存为pdf文档
doc.savetofile("result.pdf", fileformat.pdf)
end sub
end class
end namespace