backend: fix PDFService.ts
This commit is contained in:
1 parent
8f6b708d51
commit
91c213e6f0
1 file changed
+7
-3
@@ -204,15 +204,19 @@ export class PdfService {
|
|||||||
const lastPage = pdfDoc.getPage(pageCountBefore - 1);
|
const lastPage = pdfDoc.getPage(pageCountBefore - 1);
|
||||||
const contentStreams = (lastPage as any).node.Contents();
|
const contentStreams = (lastPage as any).node.Contents();
|
||||||
// Se não houver conteúdo, é uma página em branco
|
// Se não houver conteúdo, é uma página em branco
|
||||||
if (!contentStreams || contentStreams.length === 0) {
|
if (!contentStreams) {
|
||||||
pdfDoc.removePage(pageCountBefore - 1);
|
pdfDoc.removePage(pageCountBefore - 1);
|
||||||
pageCountBefore = pdfDoc.getPageCount();
|
pageCountBefore = pdfDoc.getPageCount();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Soma o tamanho dos streams de conteúdo
|
let totalLength = 0;
|
||||||
const totalLength = contentStreams
|
if (Array.isArray(contentStreams)) {
|
||||||
|
totalLength = contentStreams
|
||||||
.map((stream: any) => stream.contents.length)
|
.map((stream: any) => stream.contents.length)
|
||||||
.reduce((acc: number, len: number) => acc + len, 0);
|
.reduce((acc: number, len: number) => acc + len, 0);
|
||||||
|
} else if (contentStreams.contents && typeof contentStreams.contents.length === 'number') {
|
||||||
|
totalLength = contentStreams.contents.length;
|
||||||
|
}
|
||||||
// Se o conteúdo for muito pequeno (< 30 bytes), considera em branco
|
// Se o conteúdo for muito pequeno (< 30 bytes), considera em branco
|
||||||
if (totalLength < 30) {
|
if (totalLength < 30) {
|
||||||
pdfDoc.removePage(pageCountBefore - 1);
|
pdfDoc.removePage(pageCountBefore - 1);
|
||||||
|
|||||||
Reference in new issue
Block a user