我正在尝试让我的pdf文档从( 0 ,0)开始,但是document对象似乎有一个默认的上边距,我不能设置为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, 0, 0);
PdfPTable tPrincipal = new PdfPTable(2);
tPrincipal .WidthPercentage = 100;
tPrincipal .DefaultCell.Border = 0;
tPrincipal .TotalWidth = 288f;
tPrincipal .LockedWidth = true;……
我就是不能把上边距设为0。它只是不关心我的设置为(0,0,0,0),并留下一个上边距(大约50f)。
发布于 2010-10-12 03:50:10
您需要在文档构造函数中设置边距,如下所示:
Document pdf = new Document(new Rectangle(288f, 144f), 0, 0, 0, 0); 您不需要使用Document.SetMargins()方法。我相信你会在通过调用Document.NewPage()创建一个新页面后使用SetMargins()。
发布于 2016-11-25 23:46:47
选项1:
Document doc = new Document();
doc.setMargins(0 , 0 , 0 , 0);选项2:
Document pdf = new Document(new Rectangle(595 , 842 ), 0, 0, 0, 0); 其中,595x842是A4大小的纸张。
发布于 2021-01-27 22:06:00
我确实喜欢下面的“…”/XYZ.pdf“是生成pdf文件下载路径的路径。
PdfDocument pdfDoc = new PdfDocument(new com.itextpdf.kernel.pdf.PdfWriter(“…/XYZ.pdf”));
Document doc = new Document(pdfDoc);
doc.setMargins(0f , 0f , 0f , 0f);https://stackoverflow.com/questions/3903743
复制相似问题