Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanramsi committed Oct 31, 2024
0 parents commit 4456b44
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "leconfe/pdf-js",
"autoload": {
"psr-4": {
"PdfJs\\": "src/"
}
},
"authors": [
{
"name": "Leconfe"
}
],
"require": {}
}
18 changes: 18 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

require 'vendor/autoload.php';

use PdfJs\PdfJsPlugin;

return new PdfJsPlugin;
5 changes: 5 additions & 0 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'PDFjs Viewer Plugin'
folder: PdfJs
author: 'Leconfe'
description: 'This plugin uses the pdf.js PDF viewer to embed PDFs on the paper galley pages.'
version: 1.0.0
31 changes: 31 additions & 0 deletions src/PdfJsPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PdfJs;

use App\Classes\Plugin;
use App\Facades\Hook;
use CustomHeader\Pages\CustomHeaderPage;
use Filament\Panel;

class PdfJsPlugin extends Plugin
{
public function boot()
{
Hook::add('Frontend::PaperGalley', function ($hookName, $galley, &$returner) {
if (!$galley->isPdf()) {
return;
}

$media = $galley->file->media;

$returner = response()
->file($media->getPath(), [
'Content-Type' => $media->mime_type,
'Content-Disposition' => 'inline; filename="' . $media->file_name . '"',
'Content-Length' => $media->size,
'Content-Transfer-Encoding' => 'binary',
'Accept-Ranges' => 'bytes',
]);
});
}
}

0 comments on commit 4456b44

Please sign in to comment.