Commit 4bea5711 by ramdayalmunda

handling font size completed

parent 65736c13
let isModule = (typeof module != 'undefined') ? true : false let isModule = (typeof module != 'undefined') ? true : false
const { jsPDF } = require("jspdf");
const { createCanvas } = require('canvas') const { createCanvas } = require('canvas')
var ADocEditor = function (customConfig) { var ADocEditor = function (customConfig) {
var counter = 7 var counter = 7
...@@ -348,10 +349,68 @@ var ADocEditor = function (customConfig) { ...@@ -348,10 +349,68 @@ var ADocEditor = function (customConfig) {
} }
function generatePDF(e){ function generatePDF(fileName) {
if (isModule){ if (isModule) {
console.log('to generate PDF on Server side') console.log('to generate PDF on Server side', config.pageSetup)
}else{
const doc = new jsPDF('l', 'px', [660, 1260]);
let canvasIndex = 0;
let x = 0
let y = (config.format.margin * config.pageSetup.canvasMultiplier)
let maxVericalWidth = (config.pageSetup.canvasHeight - config.format.margin * config.pageSetup.canvasMultiplier * 2)
for (let l = 0; l < lines.length; l++) {
x = (config.format.margin * config.pageSetup.canvasMultiplier);
y += lines[l].maxFontSize
if (lines[l].blockStart && l != 0) y += lines[l].maxFontSize
if ((maxVericalWidth + lines[l].maxFontSize) < (y - lines[l].maxFontSize)) {
canvasIndex++
doc.addPage()
console.log('new page added')
y = lines[l].maxFontSize + (config.format.margin * config.pageSetup.canvasMultiplier)
}
let setData = dataSet[lines[l].dataSetIndex]
lines[l].y = y
if (lines[l].listIndex >= 0) {
let totalTabDistance = config.format.tabWidth * config.pageSetup.canvasMultiplier * (lines[l].tabCount + 1)
x += totalTabDistance;
let numberX = x - config.format.tabWidth * config.pageSetup.canvasMultiplier / 2
if (lines[l].blockStart) {
let style = {
...config.style,
...setData.style
}
}
}
lines[l].x = x
lines[l].canvasIndex = canvasIndex
for (let c = lines[l].charStartIndex; c <= lines[l].charEndIndex; c++) {
let char = setData?.plainContent[c]
if (char) {
let style = setData.formatedText[c]
doc.setFont('times')
doc.setFontSize(style.fontSize)
doc.text( char, x, y )
// ctx.font = `${style?.bold ? 'bold ' : ''}${style?.italic ? 'italic ' : ''} ${style.fontSize}px ${style.fontFamily}`
// ctx.fillStyle = `${style?.fontColor}`
// ctx.fillText(char, x, y)
setData.formatedText[c].x = x
setData.formatedText[c].y = y
if (setData.formatedText[c]?.width) {
x += setData.formatedText[c]?.width
}
}
}
}
doc.save(fileName);
} else {
console.log('to generate PDF on browser') console.log('to generate PDF on browser')
} }
} }
......
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
.a-doc-editor .body .scrolling-area canvas.page { .a-doc-editor .body .scrolling-area canvas.page {
background: #f3f3f3; background: #f3f3f3;
margin-bottom: 10px; margin-bottom: 10px;
width: 100%; /* width: 100%; */
box-shadow: 4px 0px 10px 4px rgba(0, 0, 0, 0.4); box-shadow: 4px 0px 10px 4px rgba(0, 0, 0, 0.4);
} }
......
let ADocEditor = require("./a-doc-editor-node.js") let ADocEditor = require("./a-doc-editor-node.js")
var counter = 0
module.exports = async function(req, res){ module.exports = async function(req, res){
try{ try{
console.log('reaching server', ) console.clear()
console.log('generating PDF', ++counter)
let editor = new ADocEditor() let editor = new ADocEditor()
console.log('editor', editor) editor.generatePDF('temp.pdf')
res.status(200).json( { success: true, message: "Successfull" } ) res.status(200).json( { success: true, message: "Successfull" } )
}catch(err){ }catch(err){
console.log(err) console.log(err)
......
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment