我无法将表格对齐页面左侧? [英] I cannot align my table to the left of the page?

查看:146
本文介绍了我无法将表格对齐页面左侧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个PDF,但图像显示在页面中间,我无法弄清楚如何将图像和文本单元格对齐到页面左侧。

I have created a PDF but the image is appearing to the middle of the page and I cannot figure out how to align the image and the cell of text to the left of the page.

这是我的代码

PdfWriter.GetInstance(mydoc, New FileStream(filename, FileMode.Create))

mydoc.Open()

Dim titleTable As New Table(2, 1)
titleTable.Border = 0
titleTable.BorderWidth = 0
titleTable.Cellpadding = 3
titleTable.SetWidths({20, 80})
titleTable.DefaultCellBorder = iTextSharp.text.Rectangle.NO_BORDER
titleTable.TableFitsPage = True

Dim myCell As Cell

'add impero logo 
Dim imperoImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(GetBytesForImage(<my image>))
imperoImage.ScalePercent(15)
myCell = New iTextSharp.text.Cell(imperoImage)
myCell.SetHorizontalAlignment(Cell.ALIGN_LEFT)
titleTable.AddCell(myCell)

'title
Dim myChunk As New iTextSharp.text.Chunk(ImperoClientApp.LanguageResources.GetPhrase("some text", Nothing), _
    iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 16, iTextSharp.text.Font.BOLD, New iTextSharp.text.Color(0, 0, 0)))
myCell = New iTextSharp.text.Cell(myChunk)
myCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE
titleTable.AddCell(myCell)
mydoc.Add(titleTable)


推荐答案

如果你重新打开表格边框,你会看到表格单元格离表格允许的最左边:

If you turn your table borders back on you'll see that the table cell is as far left as the table allows:

titleTable.Border = 1
titleTable.BorderWidth = 1
''//titleTable.DefaultCellBorder = iTextSharp.text.Rectangle.NO_BORDER

但您还需要告诉桌子占用尽可能多的水平空间:

But you also need to tell the table to take up as much horizontal space as possible:

titleTable.Width = 100

但是,所有这些仍将相对于文档的大小包括边距。根据您正在做的事情,您可以在创建时完全删除文档中的边距:

However, all of this will still be relative to the document's size including margins. Depending on what you're doing you could just remove the margins from the document completely when you create it:

Dim Doc As New Document(PageSize.LETTER, 0, 0, 0, 0)

注意!

iTextSharp.text.Table 非常陈旧,近十年来一直没有得到支持。相反,我们鼓励您使用 iTextSharp.text.pdf.PdfPTable 。几乎所有文档都将始终与 PdfPTable 有关。升级代码不应该太痛苦,因为它们具有大多数类似的方法和属性。

The iTextSharp.text.Table is very old and has been unsupported for almost a decade. Instead you are encouraged to use iTextSharp.text.pdf.PdfPTable. Almost all documentation out there will always be about the PdfPTable. Upgrading your code shouldn't be too painful as they have mostly similar methods and properties.

这篇关于我无法将表格对齐页面左侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆