title: How to read a PDF file from a url of external site in C#
body: <p>I want to be able to download a pdf that is accessed by a routed url (external site) in my asp.net application.
  is there a way to do it?</p>
  
  <p>The Current Situation: 
  The routed url is in the company's internal site (joomla site) <a href="http://example/sites/index.php/2011-10-30-12-29-04/finish/11/1234" rel="nofollow noreferrer">http://example/sites/index.php/2011-10-30-12-29-04/finish/11/1234</a>
  This link is redirecting users to a pdf file
  I need to get this pdf in my application (PdfReader) using the routed url.</p>
  
  <hr>
  
  <p>Update#1:</p>
  
  <p>I did some changes to my code as you suggested (I added it in the original question), just I needed to pass the content stream to my pdfReader. However it still shows me that download failed..</p>
  
  <hr>
  
  <p>Update#2:
  The problem is solved now, I had to pass the contentstream as follows
    Dim pdfReader As New PdfReader(isp:=contentStream)</p>
  
  <p>Many Thanks..</p>
  
  <pre><code>   Public Async Function GetPDFFromCompanyWebsite() As Task(Of HttpResponseMessage)
  
      Using client As HttpClient = New HttpClient()
          Dim msg As HttpResponseMessage = Await client.GetAsync("http://example/sites/index.php/2011-10-30-12-29-04/finish/4/4088")
          If msg.IsSuccessStatusCode Then
  
  
              Dim contentStream = Await msg.Content.ReadAsStreamAsync()
  
              Dim pdfReader As New PdfReader(isp:=contentStream)
              Dim MST As MemoryStream = New MemoryStream()
              Dim pdfStamper As New PdfStamper(pdfReader, MST)
              For pageIndex As Integer = 1 To pdfReader.NumberOfPages
                  Dim pageRectangle As Rectangle = pdfReader.GetPageSizeWithRotation(pageIndex)
                  Dim pdfData As PdfContentByte = pdfStamper.GetOverContent(pageIndex)
  
                  pdfData.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 40)
                  Dim graphicsState As New PdfGState()
  
  
                  graphicsState.FillOpacity = 0.1F
                  pdfData.SetGState(graphicsState)
  
                  pdfData.SetColorFill(BaseColor.BLUE)
  
                  Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
  
                  pdfData.SetFontAndSize(bf, pageRectangle.Width / 25)
                  pdfData.BeginText()
                  pdfData.SetFlatness(1000)
  
                  Dim windowsuser As String = User.Identity.Name.Substring(4)
                  windowsuser = windowsuser + "        " + windowsuser + "        " + windowsuser + "        " + windowsuser + "        " + windowsuser + "        " + windowsuser + "        " + windowsuser
                  '    pdfData.ShowTextAligned(Element.ALIGN_BOTTOM, User.Identity.Name, 100, 100, 45)
                  Response.Write("width:height: " + pageRectangle.Width.ToString + " / " + pageRectangle.Height.ToString)
                  pdfData.ShowTextAligned(Element.ALIGN_CENTER, windowsuser, pageRectangle.Width / 2, pageRectangle.Height / 2, 45)
                  pdfData.ShowTextAligned(Element.ALIGN_CENTER, windowsuser, pageRectangle.Width / 4, pageRectangle.Height - (pageRectangle.Height / 4), 45)
                  pdfData.ShowTextAligned(Element.ALIGN_CENTER, windowsuser, pageRectangle.Width - (pageRectangle.Width / 4), pageRectangle.Height / 4, 45)
                  pdfData.ShowTextAligned(Element.ALIGN_CENTER, windowsuser, (3 * pageRectangle.Width) / 8, pageRectangle.Height - ((3 * pageRectangle.Height) / 8), 45)
                  pdfData.ShowTextAligned(Element.ALIGN_CENTER, windowsuser, pageRectangle.Width - ((3 * pageRectangle.Width) / 8), (3 * pageRectangle.Height) / 8, 45)
  
  
  
  
                  pdfData.EndText()
  
              Next
              pdfStamper.Close()
              Dim bytesInStream As Byte() = MST.ToArray()
  
              MST.Close()
  
              Response.Clear()
              Response.ClearContent()
              Response.ClearHeaders()
              Response.ContentType = "application/pdf"
              Response.AddHeader("content-disposition", "attachment;filename=File.pdf")
              Response.BufferOutput = True
              Response.Cache.SetCacheability(HttpCacheability.NoCache)
              Response.BinaryWrite(bytesInStream)
              Response.End()
              Response.Close()
  
              '        End Using
          End If
  
          Return msg
      End Using
  End Function
  </code></pre>