Skip to content

Commit a80ae74

Browse files
authored
Add files via upload
1 parent 93dd36e commit a80ae74

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Issue951.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { PDFDocument } = require('pdf-lib');
2+
const fs = require('fs');
3+
4+
async function fixBlankPdf() {
5+
try {
6+
console.log('Reading input.pdf...');
7+
const pdfBytes = fs.readFileSync('input.pdf');
8+
9+
// Carrega o original
10+
const srcDoc = await PDFDocument.load(pdfBytes);
11+
12+
// Cria um PDF NOVO do zero
13+
const newDoc = await PDFDocument.create();
14+
15+
console.log('Copying and cleaning pages...');
16+
const pageIndices = srcDoc.getPageIndices();
17+
18+
// Esta função copyPages tenta extrair o conteúdo visual de forma independente
19+
const copiedPages = await newDoc.copyPages(srcDoc, pageIndices);
20+
21+
copiedPages.forEach((page) => {
22+
newDoc.addPage(page);
23+
});
24+
25+
console.log('Saving with compatibility settings...');
26+
// Tentamos salvar sem compressão para garantir que nada suma
27+
const finalBytes = await newDoc.save({
28+
useObjectStreams: false,
29+
addDefaultFont: true // Tenta forçar uma fonte caso a original tenha sumido
30+
});
31+
32+
fs.writeFileSync('output_fixed_v2.pdf', finalBytes);
33+
console.log('Done! Check "output_fixed_v2.pdf"');
34+
} catch (err) {
35+
console.error('Error:', err);
36+
}
37+
}
38+
39+
fixBlankPdf();

0 commit comments

Comments
 (0)