【问题标题】:ITextSharp MarginITextSharp 边距
【发布时间】:2015-01-30 22:40:17
【问题描述】:

我正在使用 itexsharp,但我遇到了问题,因为它没有分配文档的边距 这是代码。

Dim pdfw As PdfWriter
    Dim documentoPDF As New Document(iTextSharp.text.PageSize.A4.Rotate(), 20, 20, 20, 20) 'Creamos el objeto documento PDF
    documentoPDF.SetMargins(0.0F, 0.0F, 10.0F, 10.0F)

    pdfw = PdfWriter.GetInstance(documentoPDF, New FileStream(urlFija & "\" & "Manifiesto-" & Manifiesto & ".pdf", FileMode.Create))
    documentoPDF.Open()


    documentoPDF.NewPage()
    Dim aTable = New iTextSharp.text.pdf.PdfPTable(3)
    Dim Ancho0 As Single() = {0.75F, 1.45F, 0.75F}
    'aTable.DefaultCell.Border = BorderStyle.None

    Dim Imagen As iTextSharp.text.Image
    Imagen = iTextSharp.text.Image.GetInstance(path & "Ministerio-3.jpg")
    Imagen.ScalePercent(25)
    Imagen.SetAbsolutePosition(25.0F, 25.0F)

    Dim Img = New PdfPCell
    Img.Border = Rectangle.NO_BORDER
    Img.AddElement(Imagen)

    aTable.AddCell(Img)

    Dim C1 = New PdfPCell(New Paragraph("Formato", FontFactory.GetFont(FontFactory.TIMES, 13, iTextSharp.text.Font.BOLD)))
    C1.HorizontalAlignment = 1
    C1.VerticalAlignment = 2
    C1.Border = Rectangle.NO_BORDER

    aTable.AddCell(C1)

    Dim C2 = New PdfPCell(New Paragraph("Prueba", FontFactory.GetFont(FontFactory.TIMES, 7, iTextSharp.text.Font.NORMAL)))
    C2.HorizontalAlignment = 3
    C2.Border = Rectangle.NO_BORDER
    aTable.AddCell(C2)
    aTable.SetWidths(Ancho0)
documentoPDF.Add(aTable)
documentoPDF.AddAuthor(Session("IDUsuario").ToString)
    documentoPDF.AddTitle("Manifiesto")
    documentoPDF.AddCreationDate()
    documentoPDF.Close() 

在此之后我添加了一个包含信息的表格,将我移动到上边距

【问题讨论】:

  • 破英文在此之后我添加了一个带有信息的表格,将我移到上边距是什么意思?你是如何添加表格的?您是否知道表格居中并且只占用 80% 的宽度,除非您更改宽度百分比?您遗漏了代码 sn-p 中最重要的部分,并且您没有告诉我们任何有关您遇到的实际问题的有用信息。
  • 对不起,我不会说英语。发生的情况是我将边距分配给工作表(如代码中所示),但不接受它,我需要右边距和左边距是可能的最小值,但这是不可能的。使用表格来显示信息。
  • 我明白了,您是另一个没有阅读文档的开发人员。我会提供答案。

标签: vb.net pdf visual-studio-2013 itextsharp


【解决方案1】:

如文档所述,默认情况下,当您将PdfPTable 添加到页面时,其宽度仅占可用宽度的 80%(除非您定义绝对宽度而不是相对宽度)。它将居中,因此您将拥有可用宽度的 10% 的左右边距。

如果你想让表格100%跨越,你需要添加这一行:

aTable.WidthPercentage = 100;

现在表格将跨越整个宽度。

【讨论】:

    猜你喜欢
    • 2010-12-29
    • 2012-03-03
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 2011-08-10
    相关资源
    最近更新 更多