Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp第一页文本更高_C#_Itextsharp - Fatal编程技术网

C# iTextSharp第一页文本更高

C# iTextSharp第一页文本更高,c#,itextsharp,C#,Itextsharp,我用iText创建了一个简单的pdf。 但是为什么第一页上的文本位置高于所有其他页面上的文本位置呢 下面是一些测试代码,以查看问题所在的位置: MemoryStream PDFData = new MeMemoryStream PDFData = new MemoryStream(); Document document = new Document(PageSize.A4, 50, 50, 80, 50); PdfWriter PDFWriter = PdfWriter.GetInstance

我用iText创建了一个简单的pdf。 但是为什么第一页上的文本位置高于所有其他页面上的文本位置呢

下面是一些测试代码,以查看问题所在的位置:

MemoryStream PDFData = new MeMemoryStream PDFData = new MemoryStream();
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)
{
    Phrase phr = new Phrase(mov.Description);
    document.Add(phr);
    document.Add(Chunk.NEWLINE);
}

document.Close();
有什么想法吗

谢谢


Filip

我认为这与Chunk.NEWLINE添加有关

我猜你是在用短语+换行符组合来模拟一个段落。如果您改为切换到段落对象,问题就解决了(用您的代码在我的机器上测试)


听起来您的页面顶部有一个“Chunk.NEWLINE”。使用Maverik的代码(段落而不是短语)解决了这个问题
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));
    }