IText锐边距
ITextSharp Margin
我正在使用 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()
在此之后我添加了一个 table 信息,将我移动到顶部边距
如文档所述,当您将 PdfPTable
添加到页面时,它的宽度默认仅占可用宽度的 80%(除非您定义绝对宽度而不是相对宽度)。它将居中,因此您将有可用宽度 10% 的左右边距。
如果你想让table跨越100%,你需要添加这一行:
aTable.WidthPercentage = 100;
现在 table 将跨越整个宽度。
我正在使用 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()
在此之后我添加了一个 table 信息,将我移动到顶部边距
如文档所述,当您将 PdfPTable
添加到页面时,它的宽度默认仅占可用宽度的 80%(除非您定义绝对宽度而不是相对宽度)。它将居中,因此您将有可用宽度 10% 的左右边距。
如果你想让table跨越100%,你需要添加这一行:
aTable.WidthPercentage = 100;
现在 table 将跨越整个宽度。