简体   繁体   中英

PHP Open PDF file in adobe reader

I Have alot of PDF files saved on the network drive. All the pdf files are linked to a task. I want to open them in reader instead of downloading it or open in a chrome tab.

I get the right PDF files with the right task using this:

echo "<b>Documenten: </b><br>"; 
    $documentenwo = "SELECT * FROM DOCUMENT INNER JOIN DOCUMENT_REF_WO ON DOCUMENT.ID = DOCUMENT_REF_WO.DOCUMENT_ID WHERE DOCUMENT_REF_WO.WORKORDER_BASE_ID='".$base."' AND DOCUMENT_REF_WO.WORKORDER_LOT_ID='".$lot."' AND DOCUMENT_REF_WO.WORKORDER_SPLIT_ID='".$split."' AND ID NOT LIKE '%.stp' AND ID NOT LIKE '%.dxf'";   
    $STH = $pdo->prepare($documentenwo);
    $STH->execute();
    while($row = $STH->fetch(PDO::FETCH_ASSOC)){ 
        $file_patch = $row["DOC_FILE_PATH"];
        if(!empty(trim($file_patch))){
            $file_patch = trim($file_patch);
            $file_patch = str_replace("M:", "file://local/data", $file_patch);
        }
        $id = $row["ID"];
        $path = $file_patch."/".$id;   
        echo "<p><a href=".$file_patch."/".$id." target='_blank'><i class='fa fa-download'></i> ".$row["ID"]."</a></p>";          
    }

When I open a pdf file, It will be openend in chrome pdf viewer.

I want to open it in adobe reader from its original location. Not download it. Just open the file from it's original location.

Why?

When someone have a remark in 1 of the documents, it will be saved at its original location, so everyone else can see his remark inside the pdf file.

I've been in your same situation with an intranet php webapp. Users didn't want to view pdf's from network server in browser tab they wanted to edit it directly in Acrobat Pro. Of course you have two barriers, php is server based and javascript is not allowed to run programs in the client machine. After thinking and thinking I've found a workaround, ajax will request a php script that will compose a batch file to open the acrobat pro with the file (network path) as parameter. So after warnings of dangerous type of file you download a .cmd and when executed it will open the file in the program that you wanted. If you want to use other program than the default one just add the path to the program executable. And it is self destructable so you won't have a lot of .cmd's in your download folder.

File called acrobat.php?filename=path_to_the_file (web path)

<?php 
extract($_REQUEST);
$filename = realpath($filename);
$filename = str_replace("D:\\Pdf_folder\\","\\\\Server_name\\Pdf_folder\\",$filename); //replace internal server path to network path
function acrobat($filename) {
   header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=acrobat.cmd");
print $filename; //dowload file called acrobat.cmd
}
//call the function with the command to open pdf by default program.
 acrobat( "start \"\" \"$filename\" ".PHP_EOL." DEL \"%~f0\"");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM