ralfstuckert / pdfbox-layout

MIT License
156 stars 74 forks source link

How to print text dynamically in a new page #29

Closed divyasreeg closed 7 years ago

divyasreeg commented 7 years ago

How to print text dynamically in a new page using pdfbox? How to find the end of the page so that the data is entered automatically into next page.

ralfstuckert commented 7 years ago

What exactly is your intention? Do you want something like header/footer?

divyasreeg commented 7 years ago

When i enter huge data, the data automatically doesnt go to the next page. It is getting overridden on the page 1 itself. So, how do i find the end of page and enter the data into next page. Its not about header/footer; any kind of data.

ralfstuckert commented 7 years ago

What do you mean, it doesn't go on the next page, that's exactly what pagination is for. Could you provide some example code?

divyasreeg commented 7 years ago

Actually i am not allowed to share the office code.

divyasreeg commented 7 years ago

Suppose i want to print some data on pdf page . I initialize the contentStream and write the text. If this text is exceeding the page size, it is getting overridden on the 1st page itself. It is not entering the data by creating new page.

divyasreeg commented 7 years ago

Hello.World.docx Suppose this is the data i am trying to enter in a pdf page.The data which is present in the 2nd page is overridden in the 1st page itself in the pdf

ralfstuckert commented 7 years ago

Which API are you using, the low level or the layout API? The latter one supports pagination, see https://github.com/ralfstuckert/pdfbox-layout/blob/master/examples/MultiplePages.java

divyasreeg commented 7 years ago

Ok, i will try this and let you know

ralfstuckert commented 7 years ago

The wiki will be also very helpful for you.

divyasreeg commented 7 years ago

How can i implement pagination in my project without using your code. May i know which file has the pagination code in your code.

divyasreeg commented 7 years ago

Yes, the wiki is really helpful

ralfstuckert commented 7 years ago

I guess the low level API may be what you want, it allows you to operate on the content stream, see https://github.com/ralfstuckert/pdfbox-layout/blob/master/examples/LowLevelText.java

divyasreeg commented 7 years ago

Yes, this is helpful. But pdfbox should have made the text to automatically enter into the following page like in iText.

ralfstuckert commented 7 years ago

Also see the wiki on the low level API: https://github.com/ralfstuckert/pdfbox-layout/wiki/Text-API

ralfstuckert commented 7 years ago

After you set the maxwidth to a paragraph, you can ask it for its height and calculate the next position. That's how the layout API works.

divyasreeg commented 7 years ago

Oh.. ok i will try that. We used itext earlier. but now we have to use pdf box since its opensource

ralfstuckert commented 7 years ago

To be precise: you can always ask the paragraph for its width/height, but usually you want to constrain it by setting the max width.

ralfstuckert commented 7 years ago

Is there still some issue left?

divyasreeg commented 7 years ago

No Ralf, I developed the pdf pages perfectly for my project using Boxable.

divyasreeg commented 7 years ago

Only thing is am not able to set the line spacing to 0.5f in table : https://github.com/dhorions/boxable/tree/master/src/main/java/be/quodlibet/boxable

ralfstuckert commented 7 years ago

Thanks for the feedback, closing this issue