> ## Documentation Index
> Fetch the complete documentation index at: https://flex-fields.bjanczak.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Examples target Filament 5. Verify optional dependencies before configuring integrations.
> Upload transfer completion, permanent storage and record acceptance are separate milestones. Native and Spatie image conversions retain the original.

# Image and PDF Annotations

> Review images and PDFs in FLEX Canvas and save annotation layers with your Laravel records.

FLEX Canvas lets users mark up images and PDFs with shapes, notes, drawing and text. It stores those marks in a separate layer so the original file stays intact. Add it to a FLEX upload field or attach it to a Filament action.

The FLEX Fields workspace disables printing, downloading, adding signatures and managing bookmarks.

## Set up annotation storage

Run the optional migration once in your application.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
php artisan fff:annotations:migrate
```

## Add an action to File Upload

Use `imageAnnotations()` on a FLEX upload field. In the example, `AssetReview::targetFor()` is an application method that authorizes the attachment and returns an `ImageAnnotationTarget`. Build the target from the authorized workspace, stable attachment identity and current file revision. Return `null` when access is denied.

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use App\Media\AssetReview;
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexFileUpload;
use Bjanczak\FilamentFlexFields\Support\Media\Annotations\ImageAnnotationTarget;

FlexFileUpload::make('attachments')
    ->multiple()
    ->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp', 'application/pdf'])
    ->imageAnnotations(fn (mixed $file): ?ImageAnnotationTarget =>
        app(AssetReview::class)->targetFor($file)
    );
```

The action uses the original owned by the field. Temporary PDFs on a local disk are streamed through an expiring, session-bound link. On S3, allow the application origin to fetch signed PDF URLs through the bucket's CORS configuration.

## Limit the tools for a review

Choose the main toolbar controls, drawing tools and property controls independently. For example, reviewers can navigate a PDF and leave notes without seeing the shape, text and drawing groups.

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Filament\Actions\ImageAnnotationsAction;
use Bjanczak\FilamentFlexFields\Support\Media\Annotations\ImageAnnotationProfile;
use Bjanczak\FilamentFlexFields\Support\Media\Annotations\ImageAnnotationToolbar;

$field->imageAnnotations(
    targetUsing: fn (mixed $file) => app(AssetReview::class)->targetFor($file),
    configure: fn (ImageAnnotationsAction $action) => $action->profile(
        new ImageAnnotationProfile(
            maxPages: 250,
            textMarkupActions: [],
            toolbar: new ImageAnnotationToolbar(
                items: ['pages', 'pager', 'viewMode', 'zoom', 'zoomMode', 'annotations'],
                tools: ['note', 'pin'],
                properties: ['color', 'noteIcon'],
            ),
        ),
    ),
);
```

`toolbar.tools` controls what reviewers can create. Existing annotations still display as long as the profile allows their types. To open a saved layer for reading, use `new ImageAnnotationProfile(readOnly: true, maxPages: 250)`. Keep access checks in the source resolver for both configurations.

## Open a document from another button

Use `ImageAnnotationsAction` where you register Filament actions. The source resolver runs on open and save. Resolve the attachment on the server, authorize the current user and return its current target, name, URL, layer identifier and media type. Use `'image'` for images and `'pdf'` for PDFs.

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use App\Media\AssetReview;
use Bjanczak\FilamentFlexFields\Filament\Actions\ImageAnnotationsAction;
use Bjanczak\FilamentFlexFields\Support\Media\Annotations\ImageAnnotationProfile;
use Bjanczak\FilamentFlexFields\Support\Media\Annotations\ImageAnnotationSource;

ImageAnnotationsAction::make('reviewAttachment')
    ->label('Review attachment')
    ->sourceUsing(fn (array $arguments): ?ImageAnnotationSource =>
        app(AssetReview::class)->sourceFor($arguments)
    )
    ->profile(new ImageAnnotationProfile(maxPages: 500));
```

Saving annotations updates the layer. For PDF page editing, explicitly add `pdfDocumentEditor()` with a callback that verifies the source revision and atomically replaces the document. Enable `preserveAnnotations: true` to move saved layers with surviving pages. A deleted page's annotations are excluded from the new revision.

## Browser assets

The viewer loads when the action opens. It resolves `@useflex/canvas@latest` from jsDelivr and keeps the JavaScript, CSS, fonts and worker on the same resolved release for that workspace. Image sessions skip the PDF worker and WebAssembly.

If you enforce a Content Security Policy, allow Canvas assets from `cdn.jsdelivr.net` and version resolution from `data.jsdelivr.com`. The CDN PDF worker needs `blob:` in `worker-src` and permission to compile WebAssembly. Your storage host also needs to permit the browser to fetch the document. For a self-hosted distribution, set `filament-flex-fields.canvas.asset_base_url` to its `dist/browser/` directory and serve the matching parent `dist/` files alongside it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.