2

How can we change the title name of the pdf. While viewing the Document

Note:

I didnt use any controller are modal, I just pass the url in href tag, But I want to change the title name

<a target="_blank" @if($docDet[$csr['docid']]['docext'] == 'pdf') href="{{url($csr['docpath'])}}" @else href="{{url(ADMIN.'/downloaddoc/'.$docDet[$csr['docid']]['dockey'])}}" @endif class="icon-btn blue-btn" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="View"><i class="fa fa-eye"></i></a>
Siva Ganesh
  • 1,415
  • 2
  • 16
  • 28

1 Answers1

2

The problem is that to set the title, the title must set into the pdf, but there is a workaround ( see explanation )

Explanation:

The page with target "_blank" attribute, set the file names base on the last part of the url. So if the url is my.site/32/55 , the html title is 55.

The workaround is to set the file name as the last part of the url

1) Web.php

This is the most important part. To give the page the pdf title, set

Route::get('/pdfSee/{fileID}/{htmlTitle}', 'FileController@viewInTheBrowser')->name('file.see');

2) Controller

public function viewInTheBrowser(File $file){
$basePath = 'public/myFolder/'; 
        return  response()->download(storage_path("app/".$this->basePath. $file->file_system_path), $file->file_name, [], 'inline');
    }

3) View

<a href="{{ URL::route('file.see', [$file, $file->file_name]) }}" target="_blank"> Download </a>

As you can see, we pass in the route file.see the actual file name as last param, so wen the html page is open, it takes the last param ( the file name ) as html page title

Francesco Taioli
  • 2,687
  • 1
  • 19
  • 34