Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-02-17
10
Medium Priority
?
428 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
0
Comment
Question by:lblinc
  • 5
  • 5
10 Comments
 
LVL 14

Expert Comment

by:Ionut A. Tudor
ID: 23664146
Hi, yes you can do it using PHP using preg_match() function.
0
 
LVL 14

Expert Comment

by:Ionut A. Tudor
ID: 23664232
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

0
 

Author Comment

by:lblinc
ID: 23664847
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lblinc
ID: 23664862
Do you know a link to good site containing some PHP basic scripting info?
0
 
LVL 14

Expert Comment

by:Ionut A. Tudor
ID: 23665216
here's an tutorial: http://www.homeandlearn.co.uk/php/php.html
Good luck
0
 

Author Comment

by:lblinc
ID: 23666746
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";
}
 
?>
0
 
LVL 14

Expert Comment

by:Ionut A. Tudor
ID: 23666925
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
0
 

Author Comment

by:lblinc
ID: 23726742
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.    
0
 
LVL 14

Accepted Solution

by:
Ionut A. Tudor earned 2000 total points
ID: 23726871
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

0
 

Author Comment

by:lblinc
ID: 24094017
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 ?


0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question