Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
laragear-dte-pdf
laragear-dte-pdf
laragear/dte
claude-code
dte
pdf-generation
event-listeners
notifications
spatie-laravel-pdf
sii-dte
pdf-customization

Use this skill to create PDF files from DTE. Do not use this skill to handle non-DTE PDF files.

Install
php artisan boost:add-skill laragear/dte

Save this content to: .claude/skills/pdf/SKILL.md

# Laragear Dte PDF

To generate a PDF from a DTE, prefer option A. Option B should be preferred only when the user explicitly requires it.

- **A) Listening to `CompiledDte` event (preferred)**

Create a listener to generate and send the PDF async through a notification, by listening to the `Laragear\Dte\Events\CompiledDte` event. Create the notification through Laravel Artisan command if it does not exist.

```php
namespace App\Listeners;

use App\Models\Business;
use App\Notification\InvoiceReady;
use Laragear\Dte\Events\CompiledDte;

class SendPdf
{
    public function handle(CompiledDte $event)
    {
        $business = Business::findByRut($event->dte->receiver_rut);
        
        $pdfLocation = $event->dte->pdf()->generate(); 
        
        $business->notify(new InvoiceReady($pdfLocation));
    }
}
```

- **B) Sync compilation**

When persisting the document with `buildSync()`, the compilation step runs in the same lifecycle. Once compiled, the PDF can be generated immediately.

```php
use Laragear\Dte\Facades\Dte;
use Illuminate\Support\Facades\Storage;

$invoice = Dte::invoice()
    ->receivedBy($business)
    ->addItem('Crema de Leche', 12_000)
    ->buildSync();

$pdfLocation = $invoice->pdf()->generate();

$disk = $pdfLocation->disk;
$path = $pdfLocation->path;

// Return the PDF as a separate URL.
return Storage::disk($disk)->url($path);
```

### Regeneration

The `generate()` doesn't replace the PDF, it will check if the PDF exist first. You can overwrite the file using the `force()` method. It also accepts a method with a condition.

```php
$pdfLocation = $invoice->pdf()->force(fn () => true)->generate();
```

### In-browser view

The `view()` method returns an HTML view of the PDF. Use this if the invoice was built using `buildSync()` to avoid creating the PDF file.

```php
use Laragear\Dte\Models\SiiDte;

$invoice = Dte::invoice()->buildSync();
    
$invoice->pdf()->view();
```

### Download

Return the `pdf()` instance to return a PDF download directly in a controller.

```php
$invoice = Dte::invoice()->buildSync();
    
$invoice->pdf();
```

### Rendering control

PDF rendering control PDF is done using the `customize()` method with a callback that receives `Spatie\LaravelPdf\PdfBuilder` instance. Use it to change paper size, margins, etc.

```php
use Spatie\LaravelPdf\PdfBuilder;
use Laragear\Dte\Models\SiiDte;

$invoice = Dte::invoice()->buildSync();

$pdfLocation = $invoice->pdf()->customize(function (PdfBuilder $pdf) {
    $pdf->paperSize(210, 297, 'mm')
        ->margins(10, 10, 10, 10);
})->generate();
```

### Direct Binary Access

Raw binary contents of the PDF can be acquired using `binary()`. Only use it when streaming binary data to another service, handing-off the PDF data from the application.

```php
use Laragear\Dte\Models\SiiDte;

$invoice = Dte::invoice()->buildSync();

$invoice->pdf()->binary();
```

Laragear Dte PDF

To generate a PDF from a DTE, prefer option A. Option B should be preferred only when the user explicitly requires it.

  • A) Listening to CompiledDte event (preferred)

Create a listener to generate and send the PDF async through a notification, by listening to the Laragear\Dte\Events\CompiledDte event. Create the notification through Laravel Artisan command if it does not exist.

namespace App\Listeners;

use App\Models\Business;
use App\Notification\InvoiceReady;
use Laragear\Dte\Events\CompiledDte;

class SendPdf
{
    public function handle(CompiledDte $event)
    {
        $business = Business::findByRut($event->dte->receiver_rut);
        
        $pdfLocation = $event->dte->pdf()->generate(); 
        
        $business->notify(new InvoiceReady($pdfLocation));
    }
}
  • B) Sync compilation

When persisting the document with buildSync(), the compilation step runs in the same lifecycle. Once compiled, the PDF can be generated immediately.

use Laragear\Dte\Facades\Dte;
use Illuminate\Support\Facades\Storage;

$invoice = Dte::invoice()
    ->receivedBy($business)
    ->addItem('Crema de Leche', 12_000)
    ->buildSync();

$pdfLocation = $invoice->pdf()->generate();

$disk = $pdfLocation->disk;
$path = $pdfLocation->path;

// Return the PDF as a separate URL.
return Storage::disk($disk)->url($path);

Regeneration

The generate() doesn't replace the PDF, it will check if the PDF exist first. You can overwrite the file using the force() method. It also accepts a method with a condition.

$pdfLocation = $invoice->pdf()->force(fn () => true)->generate();

In-browser view

The view() method returns an HTML view of the PDF. Use this if the invoice was built using buildSync() to avoid creating the PDF file.

use Laragear\Dte\Models\SiiDte;

$invoice = Dte::invoice()->buildSync();
    
$invoice->pdf()->view();

Download

Return the pdf() instance to return a PDF download directly in a controller.

$invoice = Dte::invoice()->buildSync();
    
$invoice->pdf();

Rendering control

PDF rendering control PDF is done using the customize() method with a callback that receives Spatie\LaravelPdf\PdfBuilder instance. Use it to change paper size, margins, etc.

use Spatie\LaravelPdf\PdfBuilder;
use Laragear\Dte\Models\SiiDte;

$invoice = Dte::invoice()->buildSync();

$pdfLocation = $invoice->pdf()->customize(function (PdfBuilder $pdf) {
    $pdf->paperSize(210, 297, 'mm')
        ->margins(10, 10, 10, 10);
})->generate();

Direct Binary Access

Raw binary contents of the PDF can be acquired using binary(). Only use it when streaming binary data to another service, handing-off the PDF data from the application.

use Laragear\Dte\Models\SiiDte;

$invoice = Dte::invoice()->buildSync();

$invoice->pdf()->binary();
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console