We help IT Professionals succeed at work.

printing .pdf links from a web page (see attaced pic)

Medium Priority
494 Views
Last Modified: 2012-05-06
I'm looking to automate a print process, or a batch job,  that can print approx. 140 .pdf links that are embedded on a web site page.   A pic of the page is attached so that you can see the adobe .pdf links.

Does anyone have a template, or script that does something similar to this?    I don't want to have to click each link and then click again a few times to print out each url link.

Thanks.
Pic-of-embedded-pdf-links.JPG
Comment
Watch Question

Ionut A. TudorPHP Programmer
CERTIFIED EXPERT

Commented:
Hi, yes you can do it using PHP using preg_match() function.
Ionut A. TudorPHP Programmer
CERTIFIED EXPERT

Commented:
an example below
<?php
$html_page_source = "your web page with pdf links";
 
preg_match_all('/\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]\.pdf/i', $html_page_source, $links);
 
foreach($links['0'] as $link)
{
echo $link."<br>\n";
}
 
?>

Open in new window

Author

Commented:
Ok.   Understand scripting, but I'm new to PHP..  is it like perl?   Do I save the above to a file?  if so, name?  extension?   how to run it?    can i save it to a .bat file, then click it?  

This is the url below, but it requires a login/pwd ..   it's not my account so i'd rather not post that info on experts-exch..

http://www.valueline.com/secure/vlispdf/stk1700/index.aspx

Author

Commented:
Do you know a link to good site containing some PHP basic scripting info?
Ionut A. TudorPHP Programmer
CERTIFIED EXPERT

Commented:
here's an tutorial: http://www.homeandlearn.co.uk/php/php.html
Good luck

Author

Commented:
al3cs12 :    nothing happens when i run this from command line  :         c:\php\php.exe  -f  c:\php\script\VLScript_1.php

I added the correct url to your script in a file i named VLScript_1.php    -->    

<?php
$html_page_source = "http://www.valueline.com/secure/vlispdf/stk1700/index.aspx";
 
preg_match_all('/\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]\.pdf/i', $html_page_source, $links);
 
foreach($links['0'] as $link)
{
echo $link."<br>\n";
}
 
?>
Ionut A. TudorPHP Programmer
CERTIFIED EXPERT

Commented:
when you arrive at the page with the pdf links apply my script and it will work. To get to that page http://www.valueline.com/secure/vlispdf/stk1700/index.aspx as i see you need to login using http auth, that is achieved using function curl(). Good luck

Author

Commented:
al3cs12  -     could you show me what u mean relating to login / pwd  using  curl()  function?

So, then the php script does the login/pwd to the url?    

Thanks again for reply.    If the script works as expected, I will close out this question and give you the points.    
PHP Programmer
CERTIFIED EXPERT
Commented:
Below is an example, you need to replace with your url, Hope this works for you, if you have other questions you can open new ones, i think this one is extra responded but i'm glad you stayed on the same logic and we can make something to work from scratch. See below the curl example, if any errors please post them here.
Cheers

<?php
 
$url = "http://your-login-url-here/";
$details = 'username:password';
 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_ USERPWD, $details);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
$result = curl_exec($ch);
curl_close($ch);
 
echo $result;
 
?>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
al3cs12 :  if you still are willing to help me get this script working.

i get a "parse error" in line 8 of the above login script :     curl_setopt($ch, CURLOPT_ USERPWD, $details);

is single quotes the correct way to enclose the login:pwd ?


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.