C# iTextSharp第一页文本更高
我用iText创建了一个简单的pdf。 但是为什么第一页上的文本位置高于所有其他页面上的文本位置呢 下面是一些测试代码,以查看问题所在的位置: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
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));
}