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 link to the pdf in my program. The problem is I still have many chemical to go so it would be better to automate the process.

For example: A chemical has the following part number: 271004

The link containing the pdf is here:

Link

I have been reading the page source but cannot find a link to the pdf

But my knowledge of html/javascript is to limited at the moment.....

Is there any way to extract the pdf from the website?

Thanks in advance for any advice :)

1

3 Answers

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

0

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.

5

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

Using the following code I try to download the pdf:

 private void Download() { 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(""), @"C:\Users\test\Downloads\newfile.pdf"); // Defines the URL and destination directory for the downloaded file } private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) { Debug.WriteLine("DownloadProgressChangedEventHandler"); } private void Completed(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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like