bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.7k stars 2.04k forks source link

Is it possible to cut cell content based on cell width #264

Open bmihelac opened 9 years ago

bmihelac commented 9 years ago

Currently pdfmake wrap content if it does not fit in given cell and if text cannot be wrapped it is diplay and overflows outside of bounds.

Is it possible to hide overflow content?

Example:

var dd = {
    content: [
                {
                        table: {
                            widths: [50],
                                body: [
                                        [{text: 'ColumnColumnColumnColumnColumnColumnColumn'}]
                                ]
                        }
                },
    ],

}

Result:

screen shot 2015-04-17 at 12 16 24

Wished:

screen shot 2015-04-17 at 12 16 24

This is not same as #204 as I would like etxt not to be wrapped but cut.

Wabbala commented 9 years ago

I do not think that hyphenation is supported in pdfmake. It would wrap if your text is Column Column Column Column Column Column Column.

On 17 April 2015 at 12:18, Bojan Mihelac notifications@github.com wrote:

Currently pdfmake wrap content if it does not fit in given cell and if text cannot be wrapped it is diplay and overflows outside of bounds.

Is it possible to hide overflow content?

Example:

var dd = { content: [ { table: { widths: [50], body: [ [{text: 'ColumnColumnColumnColumnColumnColumnColumn'}] ] } }, ],

}

— Reply to this email directly or view it on GitHub https://github.com/bpampuch/pdfmake/issues/264.

bmihelac commented 9 years ago

@Wabbala I do not want to hyphenate word, I want to cut excessive text that does not fit specified width of cell.

jthoenes commented 9 years ago

That's currently not supported in pdfmake.

Happy to accept a pull request. Let me know when you need help for it. Am 17.04.2015 14:49 schrieb "Bojan Mihelac" notifications@github.com:

@Wabbala https://github.com/Wabbala I do not want to hyphenate word, I want to cut excessive text that does not fit specified width of cell.

— Reply to this email directly or view it on GitHub https://github.com/bpampuch/pdfmake/issues/264#issuecomment-93979409.

bmihelac commented 9 years ago

Ok thanks for answer, I will try to make PR for this.

Looking at pdfkit documentation under Text styling there are two options that should be of interest for implementing this option:

I guess we should add width and height options to styling. Am I on the right path?

jthoenes commented 9 years ago

No, we're not using the pdfkit text method for writing text. See https://github.com/bpampuch/pdfmake/blob/master/src/printer.js#L257.

Have a look at https://github.com/bpampuch/pdfmake/blob/master/src/layoutBuilder.js and https://github.com/bpampuch/pdfmake/blob/master/src/tableProcessor.js.

Detect, when a line will be to long (you can before you are in the printer) and react to it.

bmihelac commented 9 years ago

Pull request allows setting of maxHeight. It works in with text object so it can be used in columns and tables as well.

This is not exactly what I was asking for but still can be usable.

Example input:

var dd = {
  content: [
  {
    text: 'Max one line - Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines',
    maxHeight: 15,
    marginBottom: 15
    },
  {
    text: 'Max two lines - Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines',
    maxHeight: 30,
    }
  ]
}

Result:

screen shot 2015-06-03 at 14 07 31

zamb3zi commented 2 years ago

Here's my solution at #1733 for this that doesn't use the maxHeight property. It measures the text width and truncates with ellipses as necessary.