Free Support Forum - aspose.com

AddImage and AddText in v 3.0.0

I am trying to upgrade my application from aspose.pdf.kit v 2.6.3 to v 3.0.0. However the AddImage and AddText functions of the PdfFileMend class are behaving differently in v 3.0 then they did in v 2.6.3<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

How the application works is it takes a PDF file and then places a white image over a place on the PDF using the AddImage

Function. Next I use the Addtext function to add text ontop of the image that was previously added.

This works in v 2.6.3 and the text is fully visible and is placed on top of the image. However when I run my code in v 3.0 the image is placed on top of the text and the text can not be read.

Hi,

Can you please provide us with your code and the input pdf files that you use so that we can test it.

Thanks.

I had a similar problem. I just added text and it worked on 2.6.3; after switching to 3.0.0 the text lines just don’t appear.

I have reverted to 2.6.3, and the text lines fortunately appear again.

Hi,

Would you be willing to share youre code and input pdf file with us so that we can further investigate this issue.

Thanks.

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

Hi,

Thanks for your reporting, we've reproduced the error and are working on the issue. Some internal codes need to be ajusted, we hope it would be all resolved in serveral days.

(logged as PdfKitNet-4866 (txt display upon image) and PdfKitNet-4867(different x,y location) )

Thanks again,

Hi,

The two issues have been resolved in our new release. It is published now, please download and try it.

Thanks,

Hi, does anyone have a response to this? I'm evaluating this product for purchase, and it's crucial that we be able to add text on top of an image that we insert.

(Also, the ability to set the text background colour would be very useful, or to write the text against a rectangle of a different colour...)

Thanks,
/vijayan

Sorry, I just noticed the rest of the thread...

However, I have downloaded the latest version (DLL version 3.7.0.0) and in a simple test, it appears that the (JPG) image is always being rendered above the text in the same location.

I've tried doing AddText before AddImage (and vice versa), but both seem to result in the image over-writing the text.

Not sure what I'm missing...?

Thanks in advance,

/vijayan

Hi,

Thank you very much for considering Aspose.

I’m sorry to inform you that adding text above an image is currently not supported. However, I have logged a new feature request as PDFKITNET-11339 in our issue tracking system. Our team will be looking into this requirement and you’ll be updated via this forum if we support this feature in future.

We’re sorry for the inconvenience.
Regards,

I did get it working with version 3.3.0.0 of Aspose.pdf.kit<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1. First I draw the background image on with the

PdfFileMend.AddImage

2. Next a create a stamp and bind my text as a logo on the stamp of the text that I want to write on the document and use the

PdfFileStamp.AddStamp

To place the stamp right over the top of the image.

So are you sayig that this method will no longer work. In later version of of PDF.Kit?

Hi Matthew,

In my last post, I was referring to AddText over AddImage; AddStamp over AddImage is still working fine. If you find any issues with this, then please share your PDF file and the code snippet and we’ll have a look at the issue at our end.

We’re sorry for the inconvenience.
Regards,