Link to home
Start Free TrialLog in
Avatar of lblinc
lblincFlag for United States of America

asked on

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

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
Avatar of Ionut A. Tudor
Ionut A. Tudor
Flag of Romania image

Hi, yes you can do it using PHP using preg_match() function.
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

Avatar of lblinc

ASKER

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
Avatar of lblinc

ASKER

Do you know a link to good site containing some PHP basic scripting info?
Avatar of lblinc

ASKER

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";
}
 
?>
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
Avatar of lblinc

ASKER

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.    
ASKER CERTIFIED SOLUTION
Avatar of Ionut A. Tudor
Ionut A. Tudor
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lblinc

ASKER

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 ?