开发者

iTextSharp first page text higher

I created a simple pdf with iText. But why is the position of the text on the first page higher than on all the other pages.

Here is some test code to see where the problem situates:

MemoryStream PDFData = new MeMemoryStream PDFData = new MemoryStream();
Document document = new Document(PageSize.A4, 50, 50, 80, 50);
PdfWriter PDFWriter = PdfWriter.GetInstance(document,开发者_Go百科 PDFData);

document.Open();

Moviecollection movCol = new Moviecollection();
foreach (Movie mov in movCol.Movies)
{
    Phrase phr = new Phrase(mov.Description);
    document.Add(phr);
    document.Add(Chunk.NEWLINE);
}

document.Close();

Any ideas?

thanks,

Filip


I think its to do with Chunk.NEWLINE addition.

I'm guessing you are simulating a paragraph with that Phrase + Newline combination. If you switch to Paragraph object instead, the problem is solved (tested on my machine with your code).

using(MemoryStream PDFData = new MemoryStream())
    using(Document document = new Document(PageSize.A4, 50, 50, 80, 50))
    {
        PdfWriter PDFWriter = PdfWriter.GetInstance(document, PDFData);

        document.Open();

        Moviecollection movCol = new Moviecollection();

        foreach (Movie mov in movCol.Movies)
            document.Add(new Paragraph(mov.Description));
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜