KEXEL commited on
Commit
d5c74b4
·
verified ·
1 Parent(s): ce749a5
Files changed (1) hide show
  1. Editor-PDF.html +77 -28
Editor-PDF.html CHANGED
@@ -9,46 +9,52 @@
9
  <style>
10
  canvas {
11
  border: 1px solid #ccc;
12
- margin: 10px;
13
  cursor: crosshair;
 
14
  }
15
  </style>
16
  </head>
17
- <body class="bg-gray-100 text-gray-800 min-h-screen flex flex-col items-center p-6">
18
 
19
- <h1 class="text-3xl font-bold mb-6">📄 Editor de PDF</h1>
 
20
 
21
- <input type="file" id="pdfInput" accept="application/pdf" class="mb-4 border p-2 rounded" />
22
-
23
- <div class="flex space-x-4 mb-4">
24
- <button id="prevPage" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Página Anterior</button>
25
- <button id="nextPage" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Próxima Página</button>
26
- <span id="pageInfo" class="text-lg self-center">Página 1</span>
27
- </div>
28
 
29
- <div class="flex flex-col items-center">
30
- <canvas id="pdfCanvas" class="bg-white shadow-lg"></canvas>
31
-
32
- <div class="mt-4">
33
- <button id="addTextBtn" class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 mr-2">Adicionar Texto</button>
34
- <button id="addRectBtn" class="bg-yellow-500 text-white px-4 py-2 rounded hover:bg-yellow-600 mr-2">Adicionar Retângulo</button>
35
- <button id="downloadBtn" class="bg-purple-500 text-white px-4 py-2 rounded hover:bg-purple-600">Baixar como Imagem</button>
36
  </div>
 
 
37
  </div>
38
 
39
  <script>
40
  const fileInput = document.getElementById('pdfInput');
41
  const canvas = document.getElementById('pdfCanvas');
42
  const ctx = canvas.getContext('2d');
43
- const prevPageBtn = document.getElementById('prevPage');
44
- const nextPageBtn = document.getElementById('nextPage');
45
  const pageInfo = document.getElementById('pageInfo');
46
  const addTextBtn = document.getElementById('addTextBtn');
47
  const addRectBtn = document.getElementById('addRectBtn');
 
48
  const downloadBtn = document.getElementById('downloadBtn');
 
 
49
 
50
  let pdfDoc = null;
51
  let currentPage = 1;
 
 
 
52
 
53
  pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.14.305/pdf.worker.min.js';
54
 
@@ -90,18 +96,61 @@
90
  });
91
 
92
  addTextBtn.addEventListener('click', () => {
93
- const text = prompt("Digite o texto:");
94
- if (text) {
95
- ctx.fillStyle = 'red';
96
- ctx.font = '20px Arial';
97
- ctx.fillText(text, 50, 50);
98
- }
99
  });
100
 
101
  addRectBtn.addEventListener('click', () => {
102
- ctx.strokeStyle = 'blue';
103
- ctx.lineWidth = 2;
104
- ctx.strokeRect(100, 100, 150, 80);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  });
106
 
107
  downloadBtn.addEventListener('click', () => {
 
9
  <style>
10
  canvas {
11
  border: 1px solid #ccc;
12
+ margin: 10px auto;
13
  cursor: crosshair;
14
+ display: block;
15
  }
16
  </style>
17
  </head>
18
+ <body class="bg-gray-100 text-gray-800 min-h-screen p-6">
19
 
20
+ <div class="max-w-4xl mx-auto bg-white shadow-lg rounded-lg p-6">
21
+ <h1 class="text-3xl font-bold mb-6 text-center">📄 Editor de PDF</h1>
22
 
23
+ <input type="file" id="pdfInput" accept="application/pdf" class="mb-4 block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100" />
24
+
25
+ <div class="flex flex-wrap gap-4 justify-center mb-4">
26
+ <button id="prevPage" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">⬅️ Página Anterior</button>
27
+ <button id="nextPage" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">➡️ Próxima Página</button>
28
+ <span id="pageInfo" class="text-lg self-center font-medium">Página 1</span>
29
+ </div>
30
 
31
+ <div class="flex flex-wrap gap-3 justify-center mb-4">
32
+ <button id="addTextBtn" class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600">✍️ Adicionar Texto</button>
33
+ <button id="addRectBtn" class="bg-yellow-500 text-white px-4 py-2 rounded hover:bg-yellow-600">🟦 Adicionar Retângulo</button>
34
+ <button id="clearBtn" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600">🧹 Limpar Anotações</button>
35
+ <button id="downloadBtn" class="bg-purple-500 text-white px-4 py-2 rounded hover:bg-purple-600">⬇️ Baixar como PNG</button>
 
 
36
  </div>
37
+
38
+ <canvas id="pdfCanvas" class="bg-white shadow-md mx-auto"></canvas>
39
  </div>
40
 
41
  <script>
42
  const fileInput = document.getElementById('pdfInput');
43
  const canvas = document.getElementById('pdfCanvas');
44
  const ctx = canvas.getContext('2d');
 
 
45
  const pageInfo = document.getElementById('pageInfo');
46
  const addTextBtn = document.getElementById('addTextBtn');
47
  const addRectBtn = document.getElementById('addRectBtn');
48
+ const clearBtn = document.getElementById('clearBtn');
49
  const downloadBtn = document.getElementById('downloadBtn');
50
+ const prevPageBtn = document.getElementById('prevPage');
51
+ const nextPageBtn = document.getElementById('nextPage');
52
 
53
  let pdfDoc = null;
54
  let currentPage = 1;
55
+ let isAddingText = false;
56
+ let isAddingRect = false;
57
+ let tempRectStart = null;
58
 
59
  pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.14.305/pdf.worker.min.js';
60
 
 
96
  });
97
 
98
  addTextBtn.addEventListener('click', () => {
99
+ isAddingText = true;
100
+ isAddingRect = false;
101
+ alert('Clique no local onde deseja inserir o texto.');
 
 
 
102
  });
103
 
104
  addRectBtn.addEventListener('click', () => {
105
+ isAddingRect = true;
106
+ isAddingText = false;
107
+ alert('Clique e arraste para desenhar um retângulo.');
108
+ });
109
+
110
+ canvas.addEventListener('click', (e) => {
111
+ if (isAddingText) {
112
+ const rect = canvas.getBoundingClientRect();
113
+ const x = e.clientX - rect.left;
114
+ const y = e.clientY - rect.top;
115
+ const text = prompt("Digite o texto:");
116
+ if (text) {
117
+ ctx.fillStyle = 'red';
118
+ ctx.font = '20px Arial';
119
+ ctx.fillText(text, x, y);
120
+ }
121
+ isAddingText = false;
122
+ }
123
+ });
124
+
125
+ canvas.addEventListener('mousedown', (e) => {
126
+ if (isAddingRect) {
127
+ const rect = canvas.getBoundingClientRect();
128
+ tempRectStart = {
129
+ x: e.clientX - rect.left,
130
+ y: e.clientY - rect.top
131
+ };
132
+ }
133
+ });
134
+
135
+ canvas.addEventListener('mouseup', (e) => {
136
+ if (isAddingRect && tempRectStart) {
137
+ const rect = canvas.getBoundingClientRect();
138
+ const endX = e.clientX - rect.left;
139
+ const endY = e.clientY - rect.top;
140
+ const width = endX - tempRectStart.x;
141
+ const height = endY - tempRectStart.y;
142
+
143
+ ctx.strokeStyle = 'blue';
144
+ ctx.lineWidth = 2;
145
+ ctx.strokeRect(tempRectStart.x, tempRectStart.y, width, height);
146
+
147
+ tempRectStart = null;
148
+ isAddingRect = false;
149
+ }
150
+ });
151
+
152
+ clearBtn.addEventListener('click', () => {
153
+ renderPage(currentPage); // Re-renderiza a página sem as anotações
154
  });
155
 
156
  downloadBtn.addEventListener('click', () => {