jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

[Question or Bug] Text without spaces overflows cell width

Open Nervniyak opened this issue 5 years ago • 3 comments

Space-less text overflows the width, like in this example: image If it was a bit longer it would actually break, but with this text "LONGUNSPLITTABLETEXTTHATHASNOSPACESATALL" it failed. It seems like the last letter can start printing or padding area.

Here's another example S letter overflowed to right padding area here also. image

Style for those cells is pretty simple

          const paramCell: CellDef = {
            colSpan: 1,
            content: '\nLONGUNSPLITTABLETEXTTHATHASNOSPACESATALL'
            styles: { minCellWidth: this.minColumnWidth, cellPadding: this.cellPadding },
          };

The bold label is printed manually and is only represnted by \n here

I think this is a bug in lib. Text should not overflow the padding area that much

Nervniyak avatar Jun 29 '20 14:06 Nervniyak

Yes that looks like a bug! Can you post a complete example that reproduces the issue? I know that jspdf have some issues with calculating the width when using justified text for example.

simonbengtsson avatar Jun 29 '20 18:06 simonbengtsson

I am using Angular 9 BTW

import * as jsPDF from 'jspdf';
import autoTable, { CellDef } from 'jspdf-autotable';

@Injectable({
  providedIn: 'root'
})
export class PdfTableExportService {
  public async generateTimeReport(){
        const doc = new jsPDF();
        const body: CellDef[][] = [];
        const head: CellDef[][] = [];

        body.push([{
                colSpan: 1,
                content: '\nLONGUNSPLITTABLETEXTTHATHASNOSPACESATALL',
                styles: { cellWidth: 80, cellPadding: 1.5 },
              }]);

        doc.setFontStyle('normal');
        autoTable(doc, {
          rowPageBreak: 'avoid',
          pageBreak: 'auto',
          margin: 10,
          head: head,
          body: body,
          theme: 'grid',
        }
        doc.save(`pdf.pdf`);
  }
}

Result, it broke the line one character later than it should've image

Nervniyak avatar Jun 30 '20 10:06 Nervniyak

Turned out to be a jspdf bug, reported here : https://github.com/parallax/jsPDF/issues/3644

mmghv avatar Sep 30 '23 20:09 mmghv