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

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

Open
bmihelac opened this issue Apr 17, 2015 · 7 comments
Open

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

bmihelac opened this issue Apr 17, 2015 · 7 comments

Comments

@bmihelac
Copy link
Contributor

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
Copy link

Wabbala commented Apr 17, 2015

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
#264.

@bmihelac
Copy link
Contributor Author

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

@jthoenes
Copy link
Contributor

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
#264 (comment).

@bmihelac
Copy link
Contributor Author

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:

  • width - the width that text should be wrapped to (by default, the page width minus the left and right margin)
  • height - the maximum height that text should be clipped to

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

@jthoenes
Copy link
Contributor

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 added a commit to bmihelac/pdfmake that referenced this issue Jun 3, 2015
@bmihelac
Copy link
Contributor Author

bmihelac commented Jun 3, 2015

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

touchaqb pushed a commit to touchhealth/pdfmake that referenced this issue Jan 31, 2017
…ght as well as width (bpampuch#264, bpampuch#204, bpampuch#561, bpampuch#511, bpampuch#505, bpampuch#391).

Conflicts:
	build/pdfmake.js
	build/pdfmake.min.js
	build/pdfmake.min.js.map
	src/documentContext.js
	src/layoutBuilder.js
	src/pageElementWriter.js
	src/printer.js
@liborm85 liborm85 added the table label Feb 5, 2017
touchaqb pushed a commit to touchhealth/pdfmake that referenced this issue Feb 13, 2017
…ght as well as width (bpampuch#264, bpampuch#204, bpampuch#561, bpampuch#511, bpampuch#505, bpampuch#391).

Conflicts:
	build/pdfmake.js
	build/pdfmake.min.js
	build/pdfmake.min.js.map
	src/documentContext.js
	src/layoutBuilder.js
	src/pageElementWriter.js
	src/printer.js
@touchaqb touchaqb mentioned this issue Jul 6, 2017
@zamb3zi
Copy link

zamb3zi commented Jan 11, 2022

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.

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

5 participants