473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,378 developers and data experts.

Reading a PDF from web page using URL (.NET)

Hello all,

This isn't rocket science to most, but I had a hard time figuring out how to read a PDF via URL and saving it to disk. You can use the PDFBox dll for this, but for those who want to use pure .NET, here's some code:
Expand|Select|Wrap|Line Numbers
  1. The namespaces:
  2.  
  3. using System.Text;
  4. using System.IO;
  5.  
the script:
Expand|Select|Wrap|Line Numbers
  1. //sends the request, converts response to s stream
  2. HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(pdfURL);
  3. HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
  4. Stream reqStr = webResponse.GetResponseStream();
  5.  
  6. //reads the response stream
  7. StreamReader sr = new StreamReader (reqStr,System.Text.Encoding.Unicode);
  8.  
  9. //writes stream to a PDF file
  10. StreamWriter sw = new StreamWriter(savePathPDF, false, System.Text.Encoding.Unicode);
  11. sw.Write(sr.ReadToEnd());
  12. sw.Close();
Hopes this helps.
Aug 14 '09 #1
0 10998

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Brett | last post by:
I am writing a program that will allow a user to enter a webpage address into a form. Then it will download and display the webpage below the current one. example...
8
by: Chad A. Beckner | last post by:
Does anyone know how to read the page title the executing page, using ASP.NET? I thought that this could be accessed using the Controls collection, but I can't seem to figure it out. Thanks! ...
0
by: David C | last post by:
Hi, I know that when calling a Webservice, the "Underlying Connection Was Closed" error message occurs intermittenly. This issue is addressed here http://support.microsoft.com/kb/819450 My...
2
by: Tod Birdsall | last post by:
Hi All, I am trying to secure non-ASP.NET files (i.e. .html, .pdf) in an application running on IIS 6.0, Win2K3 using the .NET Framework 2.0. What has worked in the past using .NET Framework...
2
by: deepukutty | last post by:
Hi all, I know tht we can do tracing in two ways.one in application level and the other is at Page level. I am able to see the details of trace either on the page itself or .../trace.axd page....
3
by: ABC | last post by:
How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?
4
by: Praveen Chandra | last post by:
Hi, I just wanted to put down the issue with more detailed information so that you can help us get to the right Microsoft resource for a solution! Here is the problem description... Our...
0
by: manishoz | last post by:
How can I print Windows test page using .NET code for eg. in c#. I need this without going throught the windows PrintDialog popup. Thanks
2
by: Sasquatch | last post by:
I'm having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight forward,...
2
by: Mittalswati | last post by:
Hi All I am getting the below mentioned error while accessing the page which uses VB.Net Dll ,Please look in to the matter and suggest some solution Unable to cast COM object of type...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.