如何使用itextsharp删除pdf文档的默认上边距?

我试图让我的pdf文档从(0,0)开始,但是看起来文档对象有一个认的上边距,我不能设置为0.
有没有办法做到这一点?

我的代码如下所示

using (MemoryStream memoria = new MemoryStream())
        {
            Document pdf = new Document(new Rectangle(288,144));

            try
            {
                PdfWriter writer = PdfWriter.GetInstance(pdf,memoria);

                pdf.open();
                pdf.SetMargins(0,0);

                PdfPTable tPrincipal = new PdfPTable(2);            
                tPrincipal .WidthPercentage = 100;           
                tPrincipal .DefaultCell.Border = 0;
                tPrincipal .TotalWidth = 288f;
                tPrincipal .LockedWidth = true;

….

我只是不能将上边距设置为0.它只是不关心我的设置为(0,0)并留下一个上边距(约50f).

解决方法

您需要在Document构造函数中设置边距,如下所示:
Document pdf = new Document(new Rectangle(288f,144f),0);

您不需要使用Document.SetMargins()方法.我相信你通过调用Document.NewPage()创建一个页面后会使用SetMargins().

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效