Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using itextsharp to generate pdf ...i m getting problem is my content/text coming upon footer...i want to automatically break down content to new page...if it comes upon footer..

right now i m using document.newpage()

but i want to do it automatically that my page /content automatically breakdown to new page..it should not come to header/footer of page...

FOr Information i create header/footer through this class

public class ITextEvents : PdfPageEventHelper

and i used this function

public override void OnEndPage

I m attaching also the result that i m getting right now... please help me on this...i can share more information if you ask in comments

enter image description here

i want this last box to come automatically to new page.....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
382 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming that you are adding the flowing content using document.add(), you have to make sure that you define a bottom margin that is sufficiently large to accommodate the footer.

You don't share the code you have in your OnEndPage method, but suppose that you have something like:

canvas.MoveTo(36, 50);
canvas.LineTo(559, 50);
canvas.Strike();

This draws a line from x = 36 to x = 559 at y = 50.

Suppose you have created your Document like this:

Document document = new Document();

In this case, you are creating a document with pages in the A4 format (595 x 842 user units) and margins of 36 user units. As the bottom margin is only 36 user units, your content risks overlapping with the line drawn at 50 user units from the bottom.

You should change the line where you create the Document like this:

Document document = new Document(PageSize.A4, 36, 36, 36, 55);

Now you have a bottom margin of 55 user units and the line you draw at 50 user units no longer overlaps.

Note: I use the term user units because that's how we define measurements in PDF. By default 1 user unit equals 1 point. The default margin is 36 user units or half an inch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...