Skip to content Skip to sidebar Skip to footer

Save Embedded Pdf From Website

I am writing a small C# application to manage our Safety data Sheets (of chemicals) from our suppliers. At the moment I manually search for the chemical and save the pdf and add a

Solution 1:

For those using Firefox and Chrome, put the mouse pointer anywhere within the PDF area and press control + s (on windows) or + s (on mac). Doing so will download the file.

Solution 2:

Look in the page for an iframe element with id "msdsPageFrame". The src attribute of that element contains the url to your PDF. Download that url.

If you have questions about how to download an URL or how to parse a page in search for an id, ask another question.

Solution 3:

Now I am able to access the pdf file direct using an product code:

www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL&language=EN-generic‌​&productNumber=271004&brand=SIAL&PageToGoToURL=null

Using the following code I try to download the pdf:

privatevoidDownload()
    {
        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);                   // Uses the Event Handler to check whether the download is complete
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);  // Uses the Event Handler to check for progress made
        webClient.DownloadFileAsync(new Uri("http://www.sigmaaldrich.com/MSDS/MSDS/DisplayMSDSPage.do?country=NL&language=EN-generic&productNumber=271004&brand=SIAL&PageToGoToURL=null"), @"C:\Users\test\Downloads\newfile.pdf");           // Defines the URL and destination directory for the downloaded file
    }

    privatevoidProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        Debug.WriteLine("DownloadProgressChangedEventHandler");
    }

    privatevoidCompleted(object sender, AsyncCompletedEventArgs e)
    {
        Debug.WriteLine("AsyncCompletedEventHandler");
    }

However this does not work. The problem is that the pdf is first generated (takes a few seconds). However, the AsyncCompletedEventHandler is triggered right away. I think this is the problem why the pdf file is not downloaded.

Post a Comment for "Save Embedded Pdf From Website"