Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent borders-layout when performing page break #909

Closed
VonArmin opened this issue Sep 1, 2023 · 4 comments
Closed

Inconsistent borders-layout when performing page break #909

VonArmin opened this issue Sep 1, 2023 · 4 comments

Comments

@VonArmin
Copy link

VonArmin commented Sep 1, 2023

The problem I'm encountering happens when an automatic page break is performed by the table renderer:
The border-layout is not respected, but only randomly so, some more context/things I've tried.

  1. So reproducing the bug is very inconsistent, in the provided code snippet it adds the 'SINGLE_TOP_LINE' -line borderlayout a few times but not every time, Ive seen it both fail on all but the 'first/origin' table and succeed on all tables.
  2. I've tried changing to a different borderlayout, for MINIMAL the same problem occus but when using INTERNAL it does apply the borders consistently
  3. It is consistent in not respecting the layout: when generating a pdf and it doesnt respect the layout it never will when generated again. only when some seeming arbitrary things/positions change they will appear/disappear.
  4. Ive tried different fonts but that doesnt seem to be connected to the problem

Am I doing something wrong or is it a bug that needs to be resolved?
Hope this can be fixed soon!

from fpdf import *
import fpdf.fonts

class PDF(FPDF):
    def header(self):
        self.set_y(35)
    def footer(self):
        self.set_font(size=10)
        self.set_text_color(255, 255, 255)
        self.set_font(size=9)
        self.set_xy(x=10, y=-13)
        self.cell(
            txt=rf'List Creation Date: {displayDate}',
            markdown=True, new_y=YPos.NEXT, new_x=XPos.LEFT, h=4.5)
        self.set_xy(x=-28, y=-13)
        self.multi_cell(txt=f'text\n   {self.page_no()}/{{nb}}',
                        align=Align.C, w=20, h=4.5)
        self.set_text_color(0, 0, 0)

displayDate = '1.9.2023'
info = [['H627', 'Aberrant Autophagy (LSD)'],
        ['H758', 'Abortion (embryonic lethality), BTBD17-related'],
        ['H386', 'Achromatopsia 2 (Day Blindness) - German Shepherd'],
        ['H387', 'Achromatopsia 2 (Day Blindness) - Labrador Retriever'], ['H904', 'Achromatopsia 3 (Day Blindness)'],
        ['H918', 'Achromatopsia 3 (Day Blindness) - Pointer type'], ['H336', 'Acral Mutilation Syndrome (AMS)'],
        ['H338', 'Acute Respiratory Distress Syndrome (ARDS)'], ['H893', 'Adult Onset Deafness 1'],
        ['H822', 'Adult Onset Deafness EAOD (4 associated markers)'], ['H389', 'Alexander Disease'],
        ['H351', 'Amelogenesis Imperfecta'], ['H679', 'Amelogenesis Imperfecta 2'],
        ['H680', 'Amelogenesis Imperfecta 3'], ['H866', 'Bardet-Biedl syndrome 2'], ['H788', 'Beta Mannosidosis'],
        ['H450', 'Bleeding disorder due to P2RY12 defect'], ['H487', 'Brachyury (Bobtail)'], ['H412', 'C3 Deficiency'],
        ['H807', 'Cardiomyopathy and juvenile mortality (CJM) - Belgian Shepherd'],
        ['H663', 'Centronuclear Myopathy (CNM) - Border Collie'],
        ['H749', 'Centronuclear Myopathy (CNM) - Labrador Retriever'], ['H413', 'Cerebellar Abiotrophy'],
        ['H410', 'Cerebellar Ataxia'], ['H331', 'Cerebellar Ataxia (SDCA1)'], ['H341', 'Cerebellar Ataxia (SDCA2)'],
        ['H804', 'Cerebellar Ataxia / NCL-A'], ['H653', 'Cerebellar Ataxia 2'], ['H905', 'Cerebellar Ataxia, KCNIP4'],
        ['H411', 'Cerebellar Ataxia, progressive early-onset'], ['H318', 'Cerebellar Cortical Degeneration'],
        ['H355', 'Cerebellar Hypoplasia Resembling'], ['H356', 'Chondrodysplasia, disproportionate short-limbed'],
        ['H346', 'Chondrodystrophy and Intervertebral Disc Disease'], ['H709', 'CLAD, Type I'],
        ['H484', 'CLAD, Type III'], ['H344', 'Cleft Lip / Palate and Syndactyly (CLPS)'],
        ['H871', 'CMR1 (Canine Multifocal Retinopathy)'], ['H730', 'CMR2 (Canine Multifocal Retinopathy)'],
        ['H705', 'Collie Eye Anomaly CEA, CH'], ['H625', 'Congenital Cornification Disorder'],
        ['H416', 'Congenital Hypothyroidism 1 - Dog'], ['H488', 'Congenital Hypothyroidism 3 - Dog'],
        ['H694', 'Congenital Methemoglobinemia - All breeds'],
        ['H626', 'Congenital Myasthenic Syndrome (CMS) - Jack Russell Terrier'],
        ['H339', 'Congenital Myasthenic Syndrome (CMS) - Labrador Retriever'],
        ['H425', 'Congenital Myasthenic Syndrome (CMS) - Old Danish Pointer'],
        ['H728', 'Congenital Stationary Night Blindness (CSNB) - Briard'],
        ['H814', 'Congenital Stationary Night Blindness (CSNB) - Beagle'], ['H701', 'Coppertoxicosis'],
        ['H312', 'Craniomandibular Osteopathy (CMO)'], ['H901', 'Craniomandibular Osteopathy (CMO) - Basset Hound'],
        ['H357', 'crd (Cone rod dystrophy) 1'], ['H358', 'crd (Cone rod dystrophy) 2'],
        ['H766', 'crd4-PRA (previously cord1-PRA)'], ['H929', 'Cystinuria - English and French Bulldog'],
        ['H703', 'Cystinuria I - A - 1'], ['H644', 'Cystinuria, type II - A'], ['H643', 'Cystinuria, type II - A - 1'],
        ['H645', 'Cystinuria, type II - B'], ['H889', 'Deafness with Vestibular Dysfunction - DVD'],
        ['H308', 'Degenerative Myelopathy 2 (DM2)'], ['H673', 'Degenerative Myelopathy, DM'],
        ['H327', 'Dental Hypomineralization'], ['H489', 'Dermatofibrosis'], ['H865', 'Dilated Cardiomyopathy (PLN)'],
        ['H434', 'Dilated Cardiomyopathy DCM1 (PDK4)'], ['H459', 'Dilated Cardiomyopathy DCM3 (RBM20)'],
        ['H876', 'Disproportionate Dwarfism'], ['H375', 'Dog_Skin Fragility'], ['H739', 'Dominant PRA'],
        ['H913', 'Dry Eye Curly Coat Syndrome'], ['H497', 'Dystrophic Epidermolysis Bullosa (RDEB)'],
        ['H878', 'Early Onset PRA - Spanish Water Dog'], ['H756', 'Early-onset adult deafness (Rhodesian Ridgeback)'],
        ['H385', 'Ectodermal Dysplasia X-linked'], ['H689', 'Ehlers-Danlos syndrome type 1 - All breeds'],
        ['H686', 'Ehlers-Danlos syndrome type 1 - Labrador Retriever'],
        ['H732', 'Ehlers-Danlos Syndrome, type 7 - Doberman'], ['H687', 'Elliptocytosis'],
        ['H363', 'Epidermolytic Hyperkeratosis'], ['H486', 'Epilepsy, BFJ'], ['H672', 'Exercise Induced Collapse, EIC'],
        ['H467', 'Exercise Induced Metabolic Myopathy'], ['H727', 'Eye malformation, congenital'],
        ['H435', 'Factor VII deficiency'], ['H713', 'Familial Thyroid Follicular Cell Carcinoma I & II'],
        ['H863', 'Fanconi syndrome - FS'], ['H869', 'Fecundity'],
        ['H676', 'FN, Familial Nephropathy - (English) Cocker Spaniel'],
        ['H633', 'FN, Familial Nephropathy - English Springer Spaniel'], ['H736', 'Fucosidosis'],
        ['H702', 'Gangliosidosis (GM1) - Shiba Inu'], ['H361', 'Gangliosidosis (GM2 Type I) - Japanese Chin'],
        ['H490', 'Gangliosidosis (GM2 Type II) - Poodle Type'], ['H440', 'Glanzmanns Thrombasthenia  (GT) 1 - Dog'],
        ['H496', 'Glaucoma (POAG)'], ['H737', 'Globoid Cell Leukodystrophy / Krabbes Disease'],
        ['H415', 'Glycogen Storage Disease GSD I'], ['H472', 'Goniodysgenesis and glaucoma'], ['H915', 'gPRA'],
        ['H868', 'GR_PRA1'], ['H473', 'GR_PRA2'], ['H752', 'Gray Collie Syndrome (Cyclic Neutropenia)'],
        ['H347', 'GSDII (Pompe Disease)'], ['H931', 'Haemophilia A (factor VIII deficiency)'],
        ['H491', 'Haemophilia A (Factor VIII)'], ['H607', 'Haemophilia B (factor IX deficiency)'],
        ['H780', 'Heamophilia A - German Shepherd'], ['H392', 'Hemorragic diathesis (Scott Syndrome)'],
        ['H781', 'Hereditary Ataxia - Australian Shepherd'], ['H809', 'Hereditary Cataract (HC) - HSF4'],
        ['H699', 'Hereditary Cataract 2 (HSF4)'], ['H777', 'Hereditary Footpad Hyperkeratosis, DSG1-related'],
        ['H492', 'Hereditary Footpad Hyperkeratosis, FAM83G-related'], ['H811', 'Hyperuricemia (HUU)'],
        ['H364', 'Hypocatalasia'], ['H365', 'Hypomyelination'], ['H636', 'Hypophosphatasia'],
        ['H873', 'Ichthyosis - Golden Retriever Type 1'], ['H304', 'Ichthyosis 3'], ['H378', 'Ichthyosis 4'],
        ['H384', 'Ichthyosis 5'], ['H858', 'Ichthyosis type 1 & 2 - Golden Retriever'],
        ['H366', 'IGS (Selective Cobalamin Malabsorption) 1'], ['H367', 'IGS (Selective Cobalamin Malabsorption) 2'],
        ['H867', 'Inflammatory Myopathy (Myositis)'], ['H726', 'Inflammatory Pulmonary Disease'],
        ['H718', 'Junctionalis Epidermolysis Bullosa, LAMA3-related'],
        ['H778', 'Junctionalis Epidermolysis Bullosa, LAMB3-related'], ['H335', 'Juveniele Myoclonic Epilepsy'],
        ['H329', 'Juvenile Laryngeal Paralysis Polyneuropathy (JLPP)'], ['H724', 'L2-HGA'],
        ['H641', 'Laryngeal paralysis (LP)'], ['H693', 'Laryngeal paralysis and polyneuropathy, CNTNAP1-related'],
        ['H463', 'Lethal Acrodermatitis (LAD)'], ['H708', 'Leukodystrophy'],
        ['H395', 'Limb girdle muscular dystrophy (LGMD) 1'], ['H864', 'Lundehund syndrome - LS'],
        ['H879', 'Macrothrombocytopenia (MTC)'], ['H317', 'Macular Corneal Dystrophy'],
        ['H746', 'Malignant Hyperthermia (MH) - All breeds'], ['H882', 'May-Hegglin Anomaly (MHA) - Pug'],
        ['H629', 'MDR1 Multi Drug Resistance'], ['H754', 'MDR1 Multi Drug Resistance - Phenobarbital Resistance'],
        ['H786', 'Metabolizer of a Cognitive Enhancer'], ['H824', 'Modifier of copper toxicosis, ATP7A-related'],
        ['H451', 'Mucopolysaccharidose Type VII - 2'], ['H418', 'Mucopolysaccharidosis Type IIIa'],
        ['H886', 'Mucopolysaccharidosis type VI (MPS)'], ['H748', 'Mucopolysaccharidosis Type VII'],
        ['H307', 'Multifocal Retinopathy 3 (cmr3) 2'], ['H747', 'Muscular Dystrophy (GRMD)'],
        ['H735', 'Muscular Dystrophy, COL6A3-related'], ['H359', 'Muscular Dystrophy, Duchenne type (DMD)'],
        ['H419', 'Muscular Dystrophy, Duchenne type (MDM)'], ['H688', 'Muscular Dystrophy-dystroglycanopathy'],
        ['H424', 'Musladin-Lueke Syndroom (MLS)'], ['H391', 'Myasthenia gravis-like disease'], ['H368', 'Myopathy'],
        ['H690', 'Myotonia - Labrador Retriever'], ['H738', 'Myotonia Congenita'], ['H498', 'Myotonia Congenita 2'],
        ['H776', 'Myotubular Myopathy'], ['H707', 'Narcolepsy 1'], ['H697', 'Narcolepsy 2'], ['H698', 'Narcolepsy 3'],
        ['H460', 'Nasal parakeratosis'], ['H812', 'Neonatal Encephalopathy (NEWS)'], ['H370', 'Nephritis'],
        ['H890', 'Neuroaxonal Dystrophy (NAD) - Papillon'], ['H888', 'Neuroaxonal Dystrophy (NAD) - Rottweiler'],
        ['H462', 'Neuroaxonal Dystrophy (NAD) - Spanish Water Dog'],
        ['H428', 'Neuroaxonal Dystrophy (NAD), MFN2-related'], ['H716', 'Neurological defects with dilute coat colour'],
        ['H494', 'Neuronal ceroid lipofuscinosis (NCL) 1'], ['H429', 'Neuronal ceroid lipofuscinosis (NCL) 10'],
        ['H499', 'Neuronal ceroid lipofuscinosis (NCL) 2'], ['H380', 'Neuronal ceroid lipofuscinosis (NCL) 5 GR'],
        ['H330', 'Neuronal ceroid lipofuscinosis (NCL) 6'], ['H721', 'Neuronal ceroid lipofuscinosis (NCL), 5'],
        ['H337', 'Neuronal ceroid lipofuscinosis NCL, 8-2'], ['H652', 'Neuronal ceroid lipofuscinosis, 8-1'],
        ['H895', 'Obesity'], ['H898', 'Osteochondrodysplasia (OC)'], ['H430', 'Osteogenesis imperfecta'],
        ['H431', 'Osteogenesis imperfecta 2'], ['H381', 'Osteogenesis Imperfecta 3'], ['H634', 'Paroxysmal Dyskinesia'],
        ['H792', 'Paroxysmal Dyskinesia (PD) - Markiesje'], ['H717', 'PFK (Phosphofructokinase Deficiency)'],
        ['H872', 'Pituitary dwarfism'], ['H457', 'POAG / PLL Primary Glaucoma and Lens Luxation'],
        ['H509', 'Polycystic Kidney Disease (PKD) - Bull Terrier'], ['H914', 'Polyneuropathy 1'],
        ['H495', 'Polyneuropathy 2'], ['H379', 'Polyneuropathy 3 (LPN1)'], ['H342', 'Polyneuropathy 4 (LPN2)'],
        ['H390', 'PRA 2'], ['H682', 'PRA 5'], ['H394', 'PRA BBS4'], ['H372', 'PRA crdPRA'], ['H382', 'PRA erd'],
        ['H373', 'PRA type 3'], ['H704', 'prcd PRA'], ['H439', 'Prekallikrein deficiency'],
        ['H414', 'Primary Ciliary Dyskinesia (PCD), CCDC39-related'], ['H383', 'Primary Glaucoma'],
        ['H374', 'Primary hyperoxaluria'], ['H849', 'Primary Lens Luxation - PLL'],
        ['H371', 'Progressive Retinal Atrophy (Bas-PRA) - Basenji'],
        ['H808', 'Progressive Retinal Atrophy (PRA) HIVEP3'], ['H445', 'Pyruvate Kinase Deficiency (PK) - Basenji'],
        ['H455', 'Pyruvate Kinase Deficiency (PKDef) - Beagle'],
        ['H741', 'Pyruvate Kinase Deficiency (PKDef) - Labrador Retriever'],
        ['H454', 'Pyruvate Kinase Deficiency (PKDef) - Pug'], ['H768', 'rcd1 PRA'], ['H769', 'rcd1a PRA'],
        ['H770', 'rcd3 PRA'], ['H511', 'rcd4-PRA'], ['H725', 'Retinal Dysplasia'],
        ['H794', 'Retinal Dysplasia Retinal Folds RD OSD 1'], ['H695', 'Sensory Neuropathy - All breeds'],
        ['H423', 'Severe Combined Immunodeficiency - SCID'], ['H456', 'Severe Combined Immunodeficiency - SCID 2'],
        ['H891', 'Shar-Pei Fever (SPAID)'], ['H510', 'Skeletal Dysplasia 2 (SD2)'], ['H303', 'Spinocerebellar ataxia'],
        ['H683', 'Spinocerebellar Ataxia 2'], ['H328', 'Spinocerebellar ataxia, LOA (Late Onset Ataxia)'],
        ['H803', 'Spondylocostal Dysostosis (Comma Defect)'], ['H907', 'Stargardt disease 1'],
        ['H441', 'Thrombocytopaenia'], ['H442', 'Thrombopathia'], ['H448', 'Thrombopathia 2'],
        ['H449', 'Thrombopathia 3'], ['H787', 'Trapped Neutrophil Syndrome (TNS)'], ['H432', 'Tremor, X-linked'],
        ['H932', 'Ventricular Arrhythmias and Sudden Death'], ['H433', 'Vitamin D-deficiency rickets, type II'],
        ['H642', 'Von Willebrand disease 3 - 2'], ['H677', 'Von-Willebrands Disease Type 1'],
        ['H345', 'Von-Willebrands Disease Type 2-2'], ['H744', 'Von-Willebrands Disease Type 3'],
        ['H696', 'Warburg Micro Syndrome 1 (WARBM1)'], ['H825', 'Wilson Disease'], ['H772', 'X Linked PRA1 (XL PRA1)'],
        ['H427', 'X-linked Myotubular Myopathy (MTM)'], ['H745', 'X-SCID'],
        ['H671', 'Xanthinuria, type 1 - All breeds'], ['H789', 'Xanthinuria, type 2 - Manchester Terrier']]

pdf = PDF()
pdf.add_page()
pdf.set_font('Helvetica', size=9)
with pdf.table(cell_fill_color=230, cell_fill_mode="ROWS", borders_layout="SINGLE_TOP_LINE",
               col_widths=(10, 90), text_align=('LEFT', 'LEFT')) as table:
    row = table.row()
    for colname in ['Code', 'Test Name']:
        row.cell(colname)
    for result in info:
        row = table.row()
        for info in result:  # formats only certain test results to make them more apperant
            row.cell(text=str(info))
pdf.output('issue_909.pdf')

Environment
Please provide the following information:

  • Operating System: Windows 11
  • Python version: python 3.11.0
  • fpdf2 version used: 2.7.5
@VonArmin VonArmin added the bug label Sep 1, 2023
@Lucas-C Lucas-C added the table label Sep 4, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Sep 4, 2023

Hi @VonArmin, and thank you for reporting this bug!

The border-layout is not respected, but only randomly so

Could you please describe more precisely what happens that should not happen?

Thank you for providing some minimal code reproducing the problem.
I ran it, and I do not quite understand the problem with the result PDF, sorry 😞
Here it is: issue_909.pdf

I used the latest version of fpdf2 from git: maybe you could try installing this version and see if you problem still occurs?

pip install git+https://github.com/py-pdf/fpdf2.git@master

@VonArmin
Copy link
Author

VonArmin commented Sep 4, 2023

Its to do with the line underneath the header, its very minor I know.
But on some pages the thickness is a pixel less namely 3,5,7.

Its honestly not that big of a deal but I'd like to print the documents and the line is very thin (barely visible) when I print them.

@Lucas-C
Copy link
Member

Lucas-C commented Sep 4, 2023

OK, thank you for the explanation

I figured out the issue: you can notice that this problem only occurs on pages where the top content row has a grey background.

When cell_fill_mode is set, the cell background fill on the row after the headings slightly steps over the black line, drawn previously above it.
This is what causes the issue you spotted.

I currently don't have a clean & simple solution for this.
Should we slightly vertically shift down the content row when a black line has been rendered before?
Would that mean that we should also slightly reduce the heights of all the cells in this row?

I'm open to suggestions and PRs to provide a fix that preserve the backward compatibility as much as possible 😊

As a workaround, you can try to play with the settings (header/footer height, font size...) so that the first row on every page is always an even one (or an odd one).

@Lucas-C
Copy link
Member

Lucas-C commented May 24, 2024

Given that a fix was implemented in #912, I'm going to close this now 🙂

@Lucas-C Lucas-C closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants