Output Methods

FlatPDF gives you two ways to get the generated PDF: as raw bytes or written to disk.

Save to Disk

$pdf->save('report.pdf');
$pdf->save('/absolute/path/to/report.pdf');

Get Raw Bytes

The output() method returns the complete PDF as a string.

$bytes = $pdf->output();

Laravel HTTP Response

// Download
return response($pdf->output())
    ->header('Content-Type', 'application/pdf')
    ->header('Content-Disposition', 'attachment; filename="report.pdf"');

// Inline (display in browser)
return response($pdf->output())
    ->header('Content-Type', 'application/pdf')
    ->header('Content-Disposition', 'inline; filename="report.pdf"');

Upload to S3

use Illuminate\Support\Facades\Storage;

Storage::disk('s3')->put(
    'reports/monthly.pdf',
    $pdf->output()
);

Compression

Stream compression is enabled by default, reducing typical documents by 60–70%. Disable it for debugging.

$style = Style::make(compress: false);
$pdf = FlatPdf::make($style);

// PDF streams will be uncompressed (larger but human-readable)