Just in case someone else has similar problem, I'm going to add my solution to this problem. The solution I found to be solid pdf library (FPDF Tutorial) called
from fpdf import FPDF
which requires a bit more legwork but the output is the PDF file that looks exactly the same on most devices I was able to test. I also used PyPDF
from PyPDF2 import PdfMerger
To merge the generated PDF files.
It all depends on how you get the data, in my example I had a report with row - for each department across, and the columns where types of the gifts with totals at the end as last column. Also all the last row was total for all departments for the particular gift type. Data was coming in already calculated - before report was generated.
Ex.
# Gift Report
# Headers across the top by type of the gift
# Headers in the first column indicating Departments
# Totals in the last row
# Totals in the last column
# Set PDF properties and insert the background image
pdf = FPDF(orientation = 'L', unit = 'mm', format = 'A4')
pdf.add_page()
pdf.image(self.backgrnd_image, x = 60, y = 60, w = 211, h = 100)
# Add custom fonts - You can use google fonts in your app
pdf.add_font('Lora',
'',
self.path_to_fonts + "Lora\static\Lora-Regular.ttf",
uni=True)
pdf.add_font('LoraItalic',
'',
self.path_to_fonts + "Lora\static\Lora-Italic.ttf",
uni=True)
# TITLE CELL
pdf.set_fill_color(214, 213, 210)
pdf.set_text_color(0,0,0)
pdf.set_font("Lora", size=12, style='U')
pdf.set_xy(10,26)
pdf.cell(0, 12.5, txt='Gift Report', ln=1, align="C" , fill = False)
# SUB TITLE
pdf.set_font("Lora", size=10, style='I')
pdf.set_xy(10,36)
pdf.cell(0, 12.5, txt='This is sample SUBTITLE.', ln=1, align="C" , fill = False)
# REPORT YEAR
pdf.set_font("LoraItalic", size=10, style='B')
pdf.set_xy(135,43)
pdf.cell(10, 10, txt=str(fiscal_year), ln=0, align="C" , fill = False)
# SET UP COLUMN HEADERS: Gift 1, Gift 2... Total by Unit
set_y = 53
pdf.set_font("Arial", size=9, style='B')
pdf.set_xy(70,set_y)
pdf.cell(10, 10, txt="Gift Type 1", ln=0, align="C" , fill = False)
pdf.set_font("Arial", size=9, style='B')
pdf.set_xy(97,set_y)
pdf.cell(10, 10, txt="Gift Type 2", ln=0, align="C" , fill = False)
pdf.set_font("Arial", size=9, style='B')
pdf.set_xy(251,set_y)
pdf.cell(10, 10, txt="Total by Dept", ln=0, align="C" , fill = False)
...
# ROWS - Header names (In first column) on the left
set_y = 60
for row in gift_data:
# Put space between rows based on the index/position of the element to lay it accurately as possible over image background
if row[7] == 9: #Dept 1
set_y = set_y + 6.1
if row[7] == 13: #Dept 2
set_y = set_y + 6.1
if row[7] == 14: #Dept 3
set_y = set_y + 6.5
# ROWS
pdf.set_font("Arial", size=8, style='')
pdf.set_xy(82,set_y)
pdf.cell(10, 10, txt="$" + "{:,.2f}".format(row[1]), ln=0, align="R" , fill = False)
pdf.set_font("Arial", size=8, style='')
pdf.set_xy(105,set_y)
pdf.cell(10, 10, txt="$" + "{:,.2f}".format(row[2]), ln=0, align="R" , fill = False)
pdf.set_font("Arial", size=8, style='')
pdf.set_xy(105,set_y)
pdf.cell(10, 10, txt="$" + "{:,.2f}".format(row[2]), ln=0, align="R" , fill = False)
...