simonbengtsson / jsPDF-AutoTable

jsPDF plugin for generating PDF tables with javascript
https://simonbengtsson.github.io/jsPDF-AutoTable/
MIT License
2.28k stars 617 forks source link

[Question or Bug] Text without spaces overflows cell width #687

Open Nervniyak opened 4 years ago

Nervniyak commented 4 years ago

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

simonbengtsson commented 4 years ago

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.

Nervniyak commented 4 years ago

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

mmghv commented 9 months ago

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