Features
- FontAwesome Icons
- Adding Fonts
- Formatters
- Headers and Footers
- HTML Debugging
- LATTE Template Engine
- Page Dimensions
- PDF Viewer
- Preview Features
- Using Stylesheets
- Using Templates
Requirements
PHP>=8.1ProcessWire>=3.0.205RockFrontend>=3.8.2Less- FontAwesome Icons
PDF Viewer
You can use the PdfViewer class to show a preview of PDF files in a ProcessWire files field:
PDF Viewer
Usage
The PdfViewer can be added to any field via hook:
wire()->addHookAfter(
'Inputfield::render',
function($event) {
// only add viewer to a specific field
$f = $event->object;
if ($f->name !== 'your-field-name') return;
// render iframes
/** @var RockPdf $pdf */
$pdf = wire()->modules->get('RockPdf');
$pdf->getPdfViewer()
->field($f)
->height('600') // height in pixels
// by default the viewer will use $file->url for the iframe src attribute
// in case you have access-protected files you can provide a custom src:
->src('/rockinvoice/pdf/{id}/{basename}');
// replace the original field markup with the pdf viewer
$event->return = $viewer->render();
}
);
Show a PDF in the browser
RockPdf offers a serve
method that you can use to grab any PDF file and show it in the browser:
/** @var RockPdf $pdf */
$pdf = wire()->modules->get('RockPdf');
$pdf->serve($pagefile);
Note: The pagefile needs to be a standard ProcessWire Pagefile object, eg the return value of $page->getFormatted('mypdf.first')
.