Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net itextsharp在区块图像上方添加文本_Vb.net_Pdf Generation_Itextsharp - Fatal编程技术网

Vb.net itextsharp在区块图像上方添加文本

Vb.net itextsharp在区块图像上方添加文本,vb.net,pdf-generation,itextsharp,Vb.net,Pdf Generation,Itextsharp,我想在我的图片上面得到一些文字。我的代码如下: Dim pdfcb As PdfContentByte = Writer.DirectContent Dim code128 As New Barcode128() code128.Code = partnumber code128.Extended = False

我想在我的图片上面得到一些文字。我的代码如下:

 Dim pdfcb As PdfContentByte = Writer.DirectContent
                        Dim code128 As New Barcode128()
                        code128.Code = partnumber
                        code128.Extended = False
                        code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128
                        code128.AltText = ""
                        code128.BarHeight = 13
                        code128.Size = 6
                        code128.Baseline = 8
                        code128.TextAlignment = Element.ALIGN_CENTER
                        Dim image128 As iTextSharp.text.Image = code128.CreateImageWithBarcode(pdfcb, Nothing, Nothing)

                        Dim phrase As New Phrase()
                        phrase.Font.Size = 10
                        Dim cell As New PdfPCell(phrase)
                        cell.FixedHeight = 68.69F
                        cell.HorizontalAlignment = Element.ALIGN_CENTER
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE
                        cell.Border = iTextSharp.text.Rectangle.NO_BORDER
                        phrase.Add(New Chunk(Environment.NewLine + "Companyname"))
                        phrase.Add(New Chunk(Environment.NewLine + "address"))
                        phrase.Add(New Chunk(image128, 10, 30))
                        phrase.Add(New Chunk(Environment.NewLine + partnumber))
                        phrase.Add(New Chunk(Environment.NewLine + "111"))
                        tbl.AddCell(cell)  
我总是在图片下方显示我的地址和公司名称。
我想在我的图片上面做这个

我能为此做些什么?任何帮助都是值得感激的

您正在中使用
PdfPCell
。如果要添加
图像
,则不应这样做。在中使用
PdfPCell

请注意,我删除了以下行:

cell.HorizontalAlignment = Element.ALIGN_CENTER
在复合模式下,需要更改要添加的图元的对齐方式。在这种情况下:您需要更改
段落
对象的对齐方式(这相当容易实现)。看到了吗


您的问题与2016年1月26日(一个多月前)在StackOverflow上发布的问题几乎完全相同。

您使用的是哪个版本的iTextSharp?为什么要使用
短语
?为什么在创建
PdfPCell
之后要将内容添加到
短语中?这一切都非常非常奇怪。。。好像你从未读过。我使用的是Itextsharp版本5.5.8.0。事实上,先生,我从谷歌搜索中获得了这段代码,然后我尝试打印条形码,条形码正在打印。但我想在上面的条形码中添加一些文本,这就是我试图做的。但没有工作好的程序员会从文档中学习如何编码。其他编码人员使用谷歌搜索查找他们可以复制/粘贴的代码。请看一下我的答案,你就会明白你搜索得不够好。与您现在发布的问题完全相同的问题在2016年1月26日得到了回答。我无法重现这个问题。请看条形码是否正确显示,没有任何问题。@Bruno您的答案中似乎混入了一些c#符号……或许可以整理一下?@Bruno新的关键字应该大写,是的,VB是一种真正的语言,能够处理c#的所有内容,没有大部分标点符号。所以这里没有语言狂热的地方。@MrGadget好的,现在我已经删除了
和made
New
大写。有没有其他我应该注意的vb.net特定的事情?
cell.HorizontalAlignment = Element.ALIGN_CENTER