|
@@ -59,7 +59,6 @@ class ConvertPdf extends ConvertHtml {
|
|
|
|
|
|
let title = '';
|
|
let title = '';
|
|
let author = '';
|
|
let author = '';
|
|
- let prevTop = 0;
|
|
|
|
let i = -1;
|
|
let i = -1;
|
|
|
|
|
|
const loadImage = async(image) => {
|
|
const loadImage = async(image) => {
|
|
@@ -97,10 +96,9 @@ class ConvertPdf extends ConvertHtml {
|
|
//добавим закрывающий тег стиля
|
|
//добавим закрывающий тег стиля
|
|
line.text += line.tClose;
|
|
line.text += line.tClose;
|
|
|
|
|
|
- const f = (line.fonts.length ? fonts[line.fonts[0]] : null);
|
|
|
|
-
|
|
|
|
//проверим, возможно это заголовок
|
|
//проверим, возможно это заголовок
|
|
if (line.fonts.length == 1 && line.pageWidth) {
|
|
if (line.fonts.length == 1 && line.pageWidth) {
|
|
|
|
+ const f = (line.fonts.length ? fonts[line.fonts[0]] : null);
|
|
const centerLeft = (line.pageWidth - line.width)/2;
|
|
const centerLeft = (line.pageWidth - line.width)/2;
|
|
if (f && f.isBold && Math.abs(centerLeft - line.left) < 3) {
|
|
if (f && f.isBold && Math.abs(centerLeft - line.left) < 3) {
|
|
if (!sectionTitleFound) {
|
|
if (!sectionTitleFound) {
|
|
@@ -112,12 +110,6 @@ class ConvertPdf extends ConvertHtml {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //добавим пустую строку, если надо
|
|
|
|
- if (f && f.fontSize && Math.abs(pt - line.top) > f.fontSize*1.5) {
|
|
|
|
- j++;
|
|
|
|
- pl[j] = {text: '<br>'};
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//объединяем
|
|
//объединяем
|
|
if (pt == 0 || Math.abs(pt - line.top) > 3) {
|
|
if (pt == 0 || Math.abs(pt - line.top) > 3) {
|
|
j++;
|
|
j++;
|
|
@@ -129,13 +121,25 @@ class ConvertPdf extends ConvertHtml {
|
|
});
|
|
});
|
|
|
|
|
|
//заполняем lines
|
|
//заполняем lines
|
|
|
|
+ const lastIndex = i;
|
|
pl.forEach(line => {
|
|
pl.forEach(line => {
|
|
putImage(line.top);
|
|
putImage(line.top);
|
|
|
|
+
|
|
|
|
+ //добавим пустую строку, если надо
|
|
|
|
+ const prevLine = (i > lastIndex ? lines[i] : {fonts: [], top: 0});
|
|
|
|
+ if (prevLine && !prevLine.isImage) {
|
|
|
|
+ const f = (prevLine.fonts.length ? fonts[prevLine.fonts[0]] : (line.fonts.length ? fonts[line.fonts[0]] : null));
|
|
|
|
+ if (f && f.fontSize && !line.isImage && line.top - prevLine.top > f.fontSize*1.8) {
|
|
|
|
+ i++;
|
|
|
|
+ lines[i] = {text: '<br>'};
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
i++;
|
|
i++;
|
|
lines[i] = line;
|
|
lines[i] = line;
|
|
});
|
|
});
|
|
pagelines = [];
|
|
pagelines = [];
|
|
- prevTop = 0;
|
|
|
|
|
|
+ putImage(100000);
|
|
};
|
|
};
|
|
|
|
|
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
@@ -171,7 +175,6 @@ class ConvertPdf extends ConvertHtml {
|
|
};
|
|
};
|
|
|
|
|
|
putPageLines();
|
|
putPageLines();
|
|
- putImage(100000);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (tag == 'textline') {
|
|
if (tag == 'textline') {
|
|
@@ -191,11 +194,7 @@ class ConvertPdf extends ConvertHtml {
|
|
};
|
|
};
|
|
|
|
|
|
if (line.width != 0 || line.height != 0) {
|
|
if (line.width != 0 || line.height != 0) {
|
|
- if (Math.abs(prevTop - line.top) > 3) {
|
|
|
|
- putImage(line.top);
|
|
|
|
- }
|
|
|
|
pagelines.push(line);
|
|
pagelines.push(line);
|
|
- prevTop = line.top;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -255,7 +254,6 @@ class ConvertPdf extends ConvertHtml {
|
|
});
|
|
});
|
|
|
|
|
|
putPageLines();
|
|
putPageLines();
|
|
- putImage(100000);
|
|
|
|
|
|
|
|
await Promise.all(loading);
|
|
await Promise.all(loading);
|
|
await utils.sleep(100);
|
|
await utils.sleep(100);
|