Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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在现有pdf中绝对定位图像_Vb.net_Itextsharp - Fatal编程技术网

Vb.net 如何使用itextsharp在现有pdf中绝对定位图像

Vb.net 如何使用itextsharp在现有pdf中绝对定位图像,vb.net,itextsharp,Vb.net,Itextsharp,以下是我目前掌握的代码: Imports iTextSharp.text Imports iTextSharp.text.pdf Imports System.IO Module Module1 Sub Main() AddjImage("C:\test.png", "c:\pdfTemplate.pdf", "C:\output.pdf") End Sub Private Function AddjImage(ByVal strImageFileNa

以下是我目前掌握的代码:

Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO

Module Module1

    Sub Main()
        AddjImage("C:\test.png", "c:\pdfTemplate.pdf", "C:\output.pdf")
    End Sub
    Private Function AddjImage(ByVal strImageFileName As String, ByVal pdfTemplateFile As String, ByVal outputPdf As String) As Boolean
        Try
            Dim iPdfReader As PdfReader = New PdfReader(pdfTemplateFile)
            Dim iPdfStamper As PdfStamper = New PdfStamper(iPdfReader, New FileStream(outputPdf, FileMode.Create))
            Dim imgjImage As iTextSharp.text.Image
            Dim bytContent As PdfContentByte
            'Insert Image
            imgjImage = iTextSharp.text.Image.GetInstance(strImageFileName)
            imgjImage.Alignment = iTextSharp.text.Image.ALIGN_TOP
            imgjImage.ScalePercent(78)
            imgjImage.SetAbsolutePosition(445, 0)
            bytContent = iPdfStamper.GetOverContent(1)
            bytContent.AddImage(imgjImage)
            iPdfStamper.FormFlattening = True
            iPdfStamper.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function    
End Module
pdf是横向布局。页面大小为A4。我正在尝试在pdf页面的右侧插入图像。我想在x=445和y=0位置对齐图像

我有两张两种尺寸的图片。他们是: 图1,宽度=500px;高度=910px; 图2,宽度=500px;高度=400px

问题是,这两个图像都与底部对齐,而不是与顶部对齐。因此,图像1的顶部被切断。

我尝试了您的代码(经过修改),以适应wpf应用程序中的按钮单击事件。必须修改下面的线条以使图像上升。我觉得您使用的0是从底部开始的

imgjImage.SetAbsolutePosition(445, 0)
改为

imgjImage.SetAbsolutePosition(445, 200)
200不是绝对值,它必须根据您的图像实际大小重新调整。

我尝试了您的代码(经过修改),以适应wpf应用程序中的按钮单击事件。必须修改下面的线条以使图像上升。我觉得您使用的0是从底部开始的

imgjImage.SetAbsolutePosition(445, 0)
改为

imgjImage.SetAbsolutePosition(445, 200)
200不是绝对值,必须根据图像的实际大小重新调整