Is it possible to detect the end of page in creating PDF file with PDFsharp library? How? Or overflowing text on page? I am generating PDF file with list of users and if the list is too long, I need to add new page and continue on it. I don't want to write ugly code, I want it to be as automatic as possible.
I am aware of MigraDoc library, but I already have a lot of code written in PDFsharp, so if it's not necessary to use MigraDoc (which seems to be better), I would rather stay with PDFsharp. Thanks.
Asked
Active
Viewed 2,770 times
0

I liked the old Stack Overflow
- 20,651
- 8
- 87
- 153

Tomask
- 2,344
- 3
- 27
- 37
1 Answers
2
When using PDFsharp, you are responsible to detect the end of page and create a new page for the continuation.
We always say that PDFsharp is low level: no automatic page breaks, but anything can be drawn anywhere.
Still you can write clean code with PDFsharp that handles page breaks properly.
You always have a current page, a current gfx, and a current y position on the page. So when you have to start a new page, re-initialize those variables.

I liked the old Stack Overflow
- 20,651
- 8
- 87
- 153
-
And what is your recommendation? As I said, on the first page are only few details about the document and after that there should be list (table) of users which can be too long (thats why continuation on second page and so on). No photos, no pictures, just text, lines, rectangles etc. Thanks. – Tomask May 26 '14 at 15:08
-
Sounds like a simple task to start from scratch with MigraDoc. MigraDoc can draw table borders for you, can repeat table header on the following pages, adding page numbers is pretty simple. OTOH it should be easy to add a PageBreak to your PDFsharp code (but since you do not show any code, I cannot say which way will be quicker - but restarting with MigraDoc will probably lead to cleaner code and better extensibility). – I liked the old Stack Overflow May 26 '14 at 15:53
-
Here is the code: [http://pastebin.com/ufb3MbJu](http://pastebin.com/ufb3MbJu). And yes, I really care about clean code. Thank you so much. – Tomask May 26 '14 at 16:20