PDFkit fixes

This commit is contained in:
Elvanos 2021-05-21 14:27:17 +02:00
parent 08b161baf3
commit a5ded58d3e

View file

@ -308,6 +308,9 @@ import RobotoBold from "src/assets/fonts/Roboto-Bold.ttf"
} }
}) })
export default class ExportProject extends DialogBase { export default class ExportProject extends DialogBase {
RobotoRegular = RobotoRegular
RobotoBold = RobotoBold
/** /**
* React to dialog opening request * React to dialog opening request
*/ */
@ -549,7 +552,10 @@ export default class ExportProject extends DialogBase {
// PDF // PDF
if (this.selectedExportFormat === "Adobe Reader - PDF") { if (this.selectedExportFormat === "Adobe Reader - PDF") {
this.exportFile_PDF(exportObject, exportPath) const normalFontContents = fs.readFileSync(path.resolve(__dirname, "../../assets/fonts/Roboto-Regular.ttf"))
const boldFontContents = fs.readFileSync(path.resolve(__dirname, "../../assets/fonts/Roboto-Bold.ttf"))
this.exportFile_PDF(exportObject, exportPath, normalFontContents, boldFontContents)
} }
await this.sleep(5) await this.sleep(5)
@ -914,7 +920,7 @@ export default class ExportProject extends DialogBase {
fs.writeFileSync(`${documentDirectory}/${exportFileName}.md`, mdContent) fs.writeFileSync(`${documentDirectory}/${exportFileName}.md`, mdContent)
} }
exportFile_PDF (input: I_ExportObject, exportPath: string) { exportFile_PDF (input: I_ExportObject, exportPath: string, normalFontContents : any, boldFontContents: any) {
const { documentDirectory, exportFileName } = this.fixExportPaths(exportPath, input) const { documentDirectory, exportFileName } = this.fixExportPaths(exportPath, input)
const textFont = 11 const textFont = 11
@ -928,14 +934,6 @@ export default class ExportProject extends DialogBase {
paragraphGap: 8 paragraphGap: 8
} }
const normalFont = RobotoRegular
const boldFont = RobotoBold
console.log(path.resolve(__dirname, "../../assets/fonts/Roboto-Regular.ttf"))
const normalFontContents = fs.readFileSync(path.resolve(__dirname, "../../assets/fonts/Roboto-Regular.ttf"))
const boldFontContents = fs.readFileSync(path.resolve(__dirname, "../../assets/fonts/Roboto-Bold.ttf"))
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
const doc: I_PDFKitDocument = new PDFkit({ size: "A4" }) const doc: I_PDFKitDocument = new PDFkit({ size: "A4" })
@ -1034,7 +1032,7 @@ export default class ExportProject extends DialogBase {
wysiwygOptions.underline = node.attrs.underline wysiwygOptions.underline = node.attrs.underline
// Bold // Bold
doc.font((node?.attrs?.bold) ? boldFont : normalFont) doc.font((node?.attrs?.bold) ? "Roboto-Bold" : "Roboto-Regular")
// Heading font sizing // Heading font sizing
if (node?.attrs?.hasHeadingFontSize) { if (node?.attrs?.hasHeadingFontSize) {