Sign In  Sign Up Live-Chat

AddImage and AddText in v 3.0.0

Last post 05-16-2008, 3:56 AM by Felix.Liu. 6 replies.
Sort Posts: Previous Next
  •  04-02-2008, 11:24 AM 120360

    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

     

    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.

     
  •  04-02-2008, 6:00 PM 120446 in reply to 120360

    Re: AddImage and AddText in v 3.0.0

    Hi,

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

    Thanks.

     
  •  04-10-2008, 2:16 AM 121537 in reply to 120446

    Re: AddImage and AddText in v 3.0.0

    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.
     
  •  04-10-2008, 2:13 PM 121661 in reply to 121537

    Re: AddImage and AddText in v 3.0.0

    Hi,

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

    Thanks.

     
  •  04-14-2008, 2:48 PM 122194 in reply to 121661

    Re: AddImage and AddText in v 3.0.0

    Attachment: Present (inaccessible)

    You can reproduce it by modifying the “Aspose.Pdf.Kit.Demos.VisualBasic” sample code that ships with the product.

    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

     
  •  04-15-2008, 10:44 PM 122482 in reply to 122194

    Re: AddImage and AddText in v 3.0.0

    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,


    Felix Liu
    Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  05-16-2008, 3:56 AM 127398 in reply to 122482

    Re: AddImage and AddText in v 3.0.0

    Hi,

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

    Thanks,


    Felix Liu
    Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
View as RSS news feed in XML