Download PDF Document from URL in C#/VB.NET

This article shows you how to download a PDF document from an URL using Spire.PDF with C# and VB.NET.

C#
using System.IO;
using System.Net;
using Spire.Pdf;

namespace DownloadPdfFromUrl
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            //Create a WebClient object
            WebClient webClient = new WebClient();

            //Download data from URL and save as memory stream
            using (MemoryStream ms = new MemoryStream(webClient.DownloadData("https://www.e-iceblue.com/article/toDownload.pdf")))
            {
                //Load the stream
                doc.LoadFromStream(ms);
            }

            //Save to PDF file
            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)
            'Create a PdfDocument object
            Dim doc As PdfDocument = New PdfDocument()
 
            'Create a WebClient object
            Dim webClient As WebClient = New WebClient()
 
            'Download data from URL and save as memory stream
            Imports(MemoryStream ms = New MemoryStream(webClient.DownloadData("https:'www.e-iceblue.com/article/toDownload.pdf")))
            {
                'Load the stream
                doc.LoadFromStream(ms)
            }
 
            'Save to PDF file
            doc.SaveToFile("result.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

Download PDF Document from URL in C#, VB.NET