大家好,
对于大多数人来说,这不是火箭科学,但我很难弄清楚如何通过URL读取PDF并将其保存到磁盘。 您可以为此使用PDFBox dll,但是对于那些想使用纯.NET的人,下面是一些代码:
The namespaces:
using System.Text;
using System.IO;
剧本:
//sends the request, converts response to s stream
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(pdfURL);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
Stream reqStr = webResponse.GetResponseStream();
//reads the response stream
StreamReader sr = new StreamReader (reqStr,System.Text.Encoding.Unicode);
//writes stream to a PDF file
StreamWriter sw = new StreamWriter(savePathPDF, false, System.Text.Encoding.Unicode);
sw.Write(sr.ReadToEnd());
sw.Close();
希望这会有所帮助。
From: https://bytes.com/topic/net/insights/872859-reading-pdf-web-page-using-url-net