Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Dec 12, 2014 6:10 pm

How to load pdf in PdfDocument directly from url?

mustiks
 
Posts: 1
Joined: Thu Oct 09, 2014 3:12 pm

Mon Dec 15, 2014 2:55 am

Dear mustiks,

Sorry for the delay reply.

Spire.PDF doesn't support load pdf document directly from url, you must download it and then use "LoadFromFile" to load it.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Tue Mar 28, 2017 5:31 pm

It's been a couple of years since the original question was asked so I wanted to see if this feature was ever implemented. Can someone confirm if the latest version of this library can load pdf from a url? If not, does anyone have a solution they can share?

khanhduong
 
Posts: 1
Joined: Tue Mar 28, 2017 1:31 pm

Wed Mar 29, 2017 3:13 am

Dear khanhduong,

Thanks for your inquiry.
Sorry that Spire.PDF doesn't support to load pdf directly from url yet, but you can get the PDF stream first and then use the LoadFromStream method to solve this issue.
Code: Select all
            WebRequest wr = WebRequest.Create(url);
            wr.Credentials = CredentialCache.DefaultCredentials;
            Stream isp = wr.GetResponse().GetResponseStream();
            PdfDocument doc = new PdfDocument();
            doc.LoadFromStream(isp);

If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Mar 31, 2017 7:48 am

Dear khanhduong,

Did you test the code I provided ? Did it help you solve the issue ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Dec 01, 2017 6:14 pm

I tried the code and receive the following error: System.NotSupportedException: This stream does not support seek operations.

ttest
 
Posts: 1
Joined: Thu Nov 02, 2017 2:03 pm

Mon Dec 04, 2017 3:17 am

Hi,

Please refer to below code to load a pdf document from a URL.
Code: Select all
using (WebClient webClient = new WebClient())
{
       byte[] data = webClient.DownloadData(Url);

       using (MemoryStream stream = new MemoryStream(data))
       {
             PdfDocument doc = new PdfDocument(stream);
       }
}

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF