Skip to content

Commit

Permalink
Fixed all PDF render Bugs (Hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
BolverBlitz committed Jul 18, 2024
1 parent d1dc1c8 commit 831773c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
5 changes: 3 additions & 2 deletions Telegram/src/commands/admin_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function generateJson(Guests, preisliste, mainconfig) {
"headline": `${mainconfig.LanName} ${newi18n.translate(tglang_response_inner, 'geninvoices.Abrechnung')}`,
"userid": Guest.userid,
"username": Guest.username,
"zvr": mainconfig.ZVR,
"zvr": `ZVR: ${mainconfig.ZVR}`,
"veranstalter": mainconfig.Veranstalter,
"strasse": mainconfig.Straße,
"pzort": mainconfig.PLZORT,
Expand All @@ -147,6 +147,7 @@ function generateJson(Guests, preisliste, mainconfig) {
log.error(error)
return bot.sendMessage(msg.chat.id, newi18n.translate(process.env.Fallback_Language || 'en', 'Error.DBFehler'));
})

if (i == Guests.length - 1) {
resolve(Restult_array);
}
Expand Down Expand Up @@ -335,7 +336,7 @@ module.exports = function (bot, mainconfig, preisliste) {
generateJson(Guests, preisliste, mainconfig).then(function (response) {
fs.writeFileSync(path.join(__dirname, '../', '../', '../', 'pdfGenerator', 'config.json'), JSON.stringify(response));
const config_end = new Date().getTime();
executeCommand('renderpdf', path.join(__dirname, '../', '../', '../', 'pdfGenerator')).then(function (executeCommand_response) {
executeCommand('./renderpdf', path.join(__dirname, '../', '../', '../', 'pdfGenerator')).then(function (executeCommand_response) {
const exec_end = new Date().getTime();
let Send_Incoices = [];
fs.readdirSync(path.join(__dirname, '../', '../', '../', 'pdfGenerator')).forEach(function (file) {
Expand Down
81 changes: 47 additions & 34 deletions pdfGenerator/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn genpdf(template &PDFTemplate) {
format: 'A4'
gen_content_obj: true
is_stream: true
compress: false
compress: true
})

mut page := &doc.page_list[page_n]
Expand Down Expand Up @@ -201,10 +201,12 @@ fn genpdf(template &PDFTemplate) {
// Draw table
mut page_index := 0
mut new_page := false
mut add_total_displacement := 0
mut not_draw_blue_line := false
for i, item in template.items {
mut y := 0
if i == 0 {
y = 45
y = 45 // Start at 45 for header red line
page.use_shader('sep_list_red')
page.push_content(page.draw_gradient_box('sep_list_red', pdf.Box{
x: 8
Expand All @@ -214,32 +216,38 @@ fn genpdf(template &PDFTemplate) {
}, 10))
} else {
if page_index > 0 {
y = 50 + ((i * 6) - (page_index * 255))
y = 50 + ((i * 6) - (page_index * 250)) + add_total_displacement
} else {
y = 50 + (i * 6)
y = 50 + (i * 6) + add_total_displacement
}
}

if i >= (template.items.len - 3) {
y += 6
if i == (template.items.len - 3) {
page.use_shader('sep_list_geen')
page.push_content(page.draw_gradient_box('sep_list_geen', pdf.Box{
x: 8
y: y - 7
w: 194
h: 1.5
}, 10))
}
// Do not draw blue Line since we´ll draw a green line for the last 3 items
if i == (template.items.len - 4) {
not_draw_blue_line = true
}
// Draw green line for last 3 items (total, prepayment, rest)
if i == (template.items.len - 3) {
add_total_displacement += 6
y += 6 // Ajust current y because its calculated above this if statement
page.use_shader('sep_list_geen')
page.push_content(page.draw_gradient_box('sep_list_geen', pdf.Box{
x: 8
y: y - 6
w: 194
h: 1.5
}, 10))
}

//Start putting content on the page with updated y
if new_page {
// Draw Table Header (Artikel, Preis pro Stück, Menge, Preis) and Red Line
page.use_shader('sep_list_red')
y = y - 5
page.use_shader('sep_list_blue') // Load blue shader for new page aswell
mut newheader_y := y - 6 // Move the y position up a bit (By one line)
page.push_content(page.draw_gradient_box('sep_list_red', pdf.Box{
x: 8
y: y+1
y: newheader_y + 1
w: 194
h: 0.5
}, 10))
Expand All @@ -248,47 +256,54 @@ fn genpdf(template &PDFTemplate) {

page.text_box(template.items[0].artikel, pdf.Box{
x: 10
y: y - 5
y: newheader_y - 5
w: 108 - 10
h: 4
}, fnt_params_list)

fnt_params_list.text_align = .right
page.text_box(template.items[0].priceper, pdf.Box{
x: 108
y: y - 5
y: newheader_y - 5
w: 125 - 90
h: 4
}, fnt_params_list)

page.text_box(template.items[0].amount, pdf.Box{
x: 125
y: y - 5
y: newheader_y - 5
w: 172 - 130
h: 4
}, fnt_params_list)

fnt_params_list.text_align = .right
page.text_box(template.items[0].price, pdf.Box{
x: 172
y: y - 5
y: newheader_y - 5
w: 200 - 172
h: 4
}, fnt_params_list)

new_page = false //Set it to false because we are done with drawing new page stuff
continue
} else if i != 0 {
}

if i != 0 {
// If I decide to skip line i could do it here, this could become usefull if artikels are too long and need spliting
if i != (template.items.len - 4) {
page.push_content(page.draw_gradient_box('sep_list_blue', pdf.Box{
x: 8
y: y+1
w: 194
h: 0.5
}, 10))
if i != (template.items.len - 1) {
if !not_draw_blue_line {
page.push_content(page.draw_gradient_box('sep_list_blue', pdf.Box{
x: 8
y: y + 1
w: 194
h: 0.5
}, 10))
}

not_draw_blue_line = false
}
}

// Draw the items (On Item 0 it will draw the header)
fnt_params_list.text_align = .left
page.text_box(item.artikel, pdf.Box{
x: 10
Expand Down Expand Up @@ -321,7 +336,7 @@ fn genpdf(template &PDFTemplate) {
}, fnt_params_list)

// Dynamic new page dedection
if y > (pg_fmt.h - 30) {
if y > (pg_fmt.h - 40) { // Should be 40
page_index = page_index + 1
new_page = true
page_n = doc.create_page(pdf.Page_params{
Expand All @@ -330,12 +345,10 @@ fn genpdf(template &PDFTemplate) {
compress: true
})
page = &doc.page_list[page_n]
page.use_shader('sep_list_blue')

}
}

// render the footers
// After all pages where created we can add the footer
mut index := 0
for index < doc.page_list.len {
mut page_f := &doc.page_list[index]
Expand Down

0 comments on commit 831773c

Please sign in to comment.