You can reproduce it by modifying the “Aspose.Pdf.Kit.Demos.VisualBasic” sample code that ships with the product.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
This code is a modification to the adhere form.
Another thing that is behaving differently is that the x,y location of the addtext and add image properties behave differently in v 3 then they did in v 2.6. So when testing you will have to adjust these values bbased on the version to get the image to be behind the text.
Attached is a sample pdf file nothing fancy but the same thing is happening to me on all of the PDF files that I have tried it with.
Private Sub okButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles okButton.Click
Dim imgFile As String = Me.imgTxt.Text
Dim inFile As String = demoFrm.file1Txt.Text
Dim outFile As String = demoFrm.destFileTxt.Text
Me.okButton.Enabled = False
Me.button1.Enabled = False
Try
Dim fs As FileStream = File.Open(inFile, FileMode.Open, FileAccess.Read)
Dim aFileByteArray As Byte()
ReDim aFileByteArray(fs.Length)
Dim br As BinaryReader = New BinaryReader(fs)
br.Read(aFileByteArray, 0, CInt(fs.Length))
br.Close()
fs.Close()
fs.Dispose()
Dim inPdfStream As MemoryStream = New MemoryStream(aFileByteArray)
Dim outputStream As MemoryStream = New MemoryStream
Dim mendor As PdfFileMend = New PdfFileMend(inPdfStream, outputStream)
Dim enCulture As CultureInfo = New CultureInfo("")
Dim lowLeftX1 As Single
Dim lowLeftY1 As Single
Dim upRightX1 As Single
Dim upRightY1 As Single
lowLeftX1 = 200
lowLeftY1 = 530
upRightX1 = 400
upRightY1 = 650
Dim imageStream As New MemoryStream
Dim ImageCodecInfoJPG As ImageCodecInfo
ImageCodecInfoJPG = GetEncoderInfo("image/jpeg")
Dim EP As New EncoderParameters(2)
EP.Param(0) = New EncoderParameter(Encoder.Quality, 0)
EP.Param(1) = New EncoderParameter(Encoder.ColorDepth, 0)
CreateImage("Policy Number: Testing Testing Testing").Save(imageStream, ImageCodecInfoJPG, EP)
mendor.AddImage(imageStream, 1, lowLeftX1, lowLeftY1, upRightX1, upRightY1)
mendor.Close()
Dim lowLeftX2 As Single
Dim lowLeftY2 As Single
Dim upRightX2 As Single
Dim upRightY2 As Single =
lowLeftX2 = 200
lowLeftY2 = 200
upRightX2 = 400
upRightY2 = 220
Dim polStream As MemoryStream = New MemoryStream
mendor = New PdfFileMend(outputStream, polStream)
Dim fText As FormattedText = New FormattedText("Policy Number: Testing Testing Testing", New FontColor(0, 0, 0), Aspose.Pdf.Kit.FontStyle.HelveticaBold, EncodingType.Winansi, False, 18)
mendor.AddText(fText, 1, lowLeftX2, lowLeftY2)
mendor.Close()
Dim polfile As FileStream = New FileStream(outFile, FileMode.Create)
polStream.WriteTo(polfile)
polfile.Flush()
polfile.Close()
outputStream.Close()
outputStream.Dispose()
inPdfStream.Close()
inPdfStream.Dispose()
MessageBox.Show("Demo Adhere run successfully!" & System.Environment.NewLine() & "Please check the result pdf in 'DemoForm'.", "Success", MessageBoxButtons.OK)
Catch e1 As Exception
MessageBox.Show("File is missing, or input is illegal! Please check and retry.", "Message", MessageBoxButtons.OK)
End Try
Me.okButton.Enabled = True
Me.button1.Enabled = True
Me.Refresh()
End Sub
Private Function CreateImage(ByVal imageText As String) As System.Drawing.Image
Dim oBitmap As Bitmap = New Bitmap(1, 1)
Dim oGraphic As Graphics = Graphics.FromImage(oBitmap)
oGraphic.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
Dim oFont As New Font("Helvetica", 18, Drawing.FontStyle.Bold)
Dim width As Integer = oGraphic.MeasureString(imageText, oFont).Width
Dim height As Integer = oGraphic.MeasureString(imageText, oFont).Height
oBitmap = New Bitmap(oBitmap, New Size(width, height))
oGraphic = Graphics.FromImage(oBitmap)
oGraphic.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
With oGraphic
.Clear(Color.White)
.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
.DrawRectangle(Pens.White, New Rectangle(0, 0, width, height))
End With
oGraphic.Flush()
oGraphic.Dispose
Return oBitmap
End Function