@@ -407,7 +407,7 @@ function PDFGenerator:splitTextToLines(text, fontSize, maxWidth)
407407 local currentWidth = 0
408408
409409 for i , word in ipairs (words ) do
410- local wordWidth = self :getTextWidth (word , fontSize , self .last_font .fontWeight )
410+ local wordWidth = self :getTextWidth (word , fontSize , self .last_font .fontWeight ) or 0
411411 local spaceWidth = self :getTextWidth (" " , fontSize , self .last_font .fontWeight )
412412
413413 -- Check if adding this word would exceed maxWidth
@@ -466,7 +466,6 @@ function PDFGenerator:addText(text, fontSize, color, alignment, width)
466466 -- For justified text, we need to calculate word spacing
467467 if alignment == " justify" then
468468 local spaces = text :gsub (" [^ ]" , " " ):len () -- Count spaces
469- local words = select (2 , text :gsub (" %S+" , " " )) + 1 -- Count words
470469 local available_width = self .page_width - self .margin_x [1 ] - self .margin_x [2 ]
471470 local extra_space = available_width - text_width
472471 local word_spacing = extra_space / spaces
@@ -530,7 +529,7 @@ function PDFGenerator:addParagraph(text, options)
530529
531530 for _ , text in ipairs (splittedText ) do
532531 local lines = self :splitTextToLines (text , options .fontSize , options .width - options .paddingX )
533- for i , line in ipairs (lines ) do
532+ for _ , line in ipairs (lines ) do
534533 if options .newLine == true then
535534 self .current_y = self .current_y + options .fontSize * 1.2
536535 end
@@ -2073,7 +2072,7 @@ function PDFGenerator:generate()
20732072 string.format (" %d 0 obj\n << /Type /Catalog /Pages %d 0 R >>\n endobj\n " , self .root , self .pages_obj )
20742073
20752074 -- Write content streams
2076- for pageId , content in pairs (self .contents ) do
2075+ for _ , content in pairs (self .contents ) do
20772076 local stream = table.concat (content .streams )
20782077
20792078 self .objects [content .id ] =
0 commit comments