11# Basic Example - @libresign/pdf-elements
22
3- Basic integration example of the ` PDFElements ` component with dragging, resizing, and positioning elements in PDFs .
3+ This example shows how to integrate ` PDFElements ` with custom slots and basic actions .
44
55## Structure
66
77```
88examples/basic/
9- ├── App.vue # Main component: PDFElements integration
9+ ├── App.vue
1010├── components/
11- │ ├── AppToolbar.vue # Toolbar component
12- │ ├── DocumentsList.vue # List of loaded documents
13- │ ├── SignatureBox.vue # Custom visual element
14- │ └── DeleteButton.vue # Delete button
11+ │ ├── AppToolbar.vue
12+ │ ├── DocumentsList.vue
13+ │ ├── SignatureBox.vue
14+ │ └── DeleteButton.vue
1515└── README.md
1616```
1717
18- ## How to Use PDFElements
18+ ## Quick start
1919
20- ### 1. Import the component
20+ Import the component:
2121
2222``` vue
2323import PDFElements from '@libresign/pdf-elements'
2424```
2525
26- ### 2. Basic template
26+ Basic template:
2727
2828``` vue
2929<PDFElements
@@ -33,8 +33,8 @@ import PDFElements from '@libresign/pdf-elements'
3333 :initial-scale="1.1"
3434 @pdf-elements:end-init="onReady"
3535>
36- <template #custom="{ object, isSelected }">
37- <!-- Your component here -- >
36+ <template #custom="{ object }">
37+ <SignatureBox :object="object" / >
3838 </template>
3939
4040 <template #actions="{ onDelete }">
@@ -43,136 +43,40 @@ import PDFElements from '@libresign/pdf-elements'
4343</PDFElements>
4444```
4545
46- ### 3. Main props
47-
48- - ** ` init-files ` ** : Array of PDF URLs or File objects
49- - ** ` init-file-names ` ** : Array with document names
50- - ** ` initial-scale ` ** : Initial rendering scale (default: 1)
51-
52- ### 4. Events
46+ ## Props and event
5347
54- - ** ` pdf-elements:end-init ` ** : Triggered when PDFs finish loading
48+ - ` init-files ` : PDF URLs or files.
49+ - ` init-file-names ` : names shown in the footer.
50+ - ` initial-scale ` : initial zoom.
51+ - ` pdf-elements:end-init ` : emitted when the PDF finishes loading.
5552
56- ### 5. Ref methods
53+ ## Methods via ` ref `
5754
58- ``` javascript
55+ ``` js
5956const pdf = this .$refs .pdf
6057
61- // Iniciar modo de adicionar elemento (com preview que segue o mouse)
6258pdf .startAddingElement ({
6359 width: 160 ,
6460 height: 48 ,
6561 label: ' Signature' ,
6662 icon: ' signature' ,
6763})
6864
69- // Obter todos os objetos do documento
7065const objects = pdf .getAllObjects ()
7166```
7267
73- ### 6. Slots
68+ ## Slots
69+
70+ For specific types, use ` element-{type} ` . Example for signature:
7471
75- #### Type-specific slots (recommended for multiple element types)
7672``` vue
77- <!-- Slot for signature elements -->
7873<template #element-signature="{ object }">
7974 <SignatureBox :object="object" />
8075</template>
81-
82- <!-- Slot for text elements -->
83- <template #element-text="{ object }">
84- <TextBox :object="object" />
85- </template>
86-
87- <!-- Slot for date elements -->
88- <template #element-date="{ object }">
89- <DateBox :object="object" />
90- </template>
91- ```
92-
93- When an object has ` type: 'signature' ` , PDFElements looks for ` #element-signature ` . If not found, uses the ` #custom ` fallback.
94-
95- #### ` #custom ` - Generic rendering (fallback)
96- Used when:
97- - The object doesn't have a ` type ` property
98- - No specific slot exists for the type
99-
100- Receives:
101- - ` object ` : Element data (x, y, width, height, type, custom props)
102- - ` isSelected ` : Boolean indicating if selected
103-
104- #### ` #actions ` - Action toolbar
105- Receives:
106- - ` object ` : Element data
107- - ` onDelete ` : Function to delete the element
108-
109- ### Multiple types example
110-
111- ``` vue
112- <PDFElements ref="pdf" :init-files="files">
113- <!-- Signature elements -->
114- <template #element-signature="{ object }">
115- <div class="signature-box">
116- <SignIcon />
117- {{ object.label }}
118- </div>
119- </template>
120-
121- <!-- Text input elements -->
122- <template #element-text="{ object }">
123- <div class="text-box">
124- <input :value="object.value" />
125- </div>
126- </template>
127-
128- <!-- Date picker elements -->
129- <template #element-date="{ object }">
130- <div class="date-box">
131- <CalendarIcon />
132- {{ object.date || 'Select date' }}
133- </div>
134- </template>
135-
136- <!-- Checkbox elements -->
137- <template #element-checkbox="{ object }">
138- <div class="checkbox-box">
139- <input type="checkbox" :checked="object.checked" />
140- </div>
141- </template>
142-
143- <!-- Fallback for unknown types -->
144- <template #custom="{ object }">
145- <div class="generic-box">
146- {{ object.type || 'Element' }}
147- </div>
148- </template>
149-
150- <!-- Common actions for all types -->
151- <template #actions="{ onDelete }">
152- <button @click="onDelete">Delete</button>
153- </template>
154- </PDFElements>
15576```
15677
157- ** Performance** : Slots dinâmicos são eficientes - Vue compila apenas os slots usados. Muito melhor que condicionais enormes.
158-
159- ## Funcionalidades Implementadas
160-
161- ✅ ** Carregar múltiplos PDFs** (URL ou arquivo local)
162- ✅ ** Adicionar elementos com preview** (clique no botão → move o mouse → clique para posicionar)
163- ✅ ** Arrastar elementos** dentro da mesma página ou entre páginas diferentes
164- ✅ ** Redimensionar elementos** (4 cantos, mantém aspect-ratio)
165- ✅ ** Validação de bounds** (elementos não podem sair das páginas)
166- ✅ ** Elementos responsivos** (texto ajusta tamanho conforme dimensões)
167- ✅ ** Toolbar flutuante** com ações (aparece ao selecionar elemento)
168- ✅ ** Rolagem durante drag** (atualiza posições automaticamente)
169-
170- ## Componentes Auxiliares
78+ If there is no specific slot, ` #custom ` is used as a fallback.
17179
172- Os componentes em ` components/ ` são ** apenas para o exemplo** . Você pode:
173- - Usar seus próprios componentes
174- - Estilizar da forma que preferir
175- - Adicionar mais ações no toolbar
176- - Customizar totalmente o visual dos elementos
80+ ## Notes
17781
178- O importante é entender como usar o ` PDFElements ` no ` App.vue ` .
82+ Components under ` components/ ` are just for the example and can be replaced freely .
0 commit comments