Spire.PDFViewer is a powerful PDF Viewer component for .NET. It allows developers to load PDF document from stream, file and byte array.

Tue Apr 07, 2020 10:05 am

I'm using freespire.pdfviewer from nuget version 4.1.0
when I select a pdf from file and display in my form, random characters are shown across the image
I am using your sample program "Open PDF Document via PDFViewer in C#, VB.NET " method 2 for visual basic
I have upload form showing problem as well as the original pdf file

lfcnutter
 
Posts: 7
Joined: Tue Apr 07, 2020 9:48 am

Wed Apr 08, 2020 6:59 am

Hello,

Thanks for your post.
I did reproduce your problem using the free version. But there was no issues when I used Commercial Spire.PDFViewer Pack(Hotfix) Version:5.1.4 to test your file. I recommend you try the commercial version. To help you evaluate our product without any watermarks or restrictions, we sent you a one-month temporary license.
How to apply license


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2645
Joined: Wed Jun 27, 2012 8:50 am

Wed Apr 08, 2020 7:22 am

Ok thanks for the update.
I don't really require a license and the commercial version as I am only learning VB.net and pdf manipulation for my own use during my 12 week coronavirus self isolation.
Will there be a future free version without the problem?
On another note.. the sample code for vb doesn't work with Visual Studio 2019 without tweaking
Will this also be addressed in a future version?
Finally would you be able to send me a vb version of your find and replace text (currently only C# sample) tweaked for vs 2019
many thanks for your help on these matters

lfcnutter
 
Posts: 7
Joined: Tue Apr 07, 2020 9:48 am

Wed Apr 08, 2020 9:49 am

Hi,

Thanks for your reply.
We will update free version in the future, but the release date is uncertain as we maintain the free version irregularly.
Our Spire.PDFViewer product just supports viewing PDF document, not support manipulating PDF document. Our Spire.PDF product is used to manipulate PDF documents.
Do you want the code in vb.net about finding and replacing text of pdf using Spire.PDF?


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2645
Joined: Wed Jun 27, 2012 8:50 am

Wed Apr 08, 2020 1:43 pm

OK I understand about the release strategy for free version.

Yes please I would like to take a stab at the Spire.PDF manipulation

regards

Dave

lfcnutter
 
Posts: 7
Joined: Tue Apr 07, 2020 9:48 am

Thu Apr 09, 2020 2:27 am

Hi Dave,

Thanks for your understanding.
Here is the code in vb.net about finding and replacing text of pdf using Spire.PDF. I have tested it in VS2019 and it worked perfectly.
Code: Select all
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.General.Find
Imports Spire.Pdf.Graphics

Module Module1

    Sub Main()
        Dim doc As New PdfDocument()

        ' Read a pdf file
        doc.LoadFromFile("../../SearchReplaceTemplate.pdf")

        ' Get the first page of pdf file
        Dim page As PdfPageBase = doc.Pages(0)

        ' Searches "Spire.PDF for .NET" by ignoring case
        Dim collection As PdfTextFindCollection = page.FindText("Spire.PDF for .NET", TextFindParameter.IgnoreCase)

        Dim newText As String = "E-iceblue Spire.PDF"

        ' Creates a brush
        Dim brush As PdfBrush = New PdfSolidBrush(Color.DarkBlue)

        ' Defines a font
        Dim font As New PdfTrueTypeFont(New Font("Arial", 12.0F, FontStyle.Regular))

        Dim rec As RectangleF
        For Each find As PdfTextFind In collection.Finds
            ' Gets the bound of the found text in page
            rec = find.Bounds

            page.Canvas.DrawRectangle(PdfBrushes.White, rec)
            ' Draws new text as defined font and color
            page.Canvas.DrawString(newText, font, brush, rec)

            ' This method can directly replace old text with newText,but it just can set the background color, can not set font/forecolor
            ' find.ApplyRecoverString(newText, Color.Gray);
        Next find

        Dim result As String = "ReplaceAllSearchedText_out.pdf"

        'Save the document
        doc.SaveToFile(result)
    End Sub

End Module


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2645
Joined: Wed Jun 27, 2012 8:50 am

Thu Apr 09, 2020 8:10 am

Hi Amy
I'm having problems with your solution.
If you try find replace using the example pdf I posted earlier replacing "Canelli" with "Chickpeas" for instance then all I get is a white rectangle blotting out the find text
Nothing shows the replace text
Again I'm using free spire version so maybe this is another error that is addressed in the pro version
regards

lfcnutter
 
Posts: 7
Joined: Tue Apr 07, 2020 9:48 am

Thu Apr 09, 2020 9:16 am

Hi Dave,

Thanks for your feedback.
The principle of replacing text in PDF documents is to draw new text on the same area as the original text. The area that "Chickpeas" needs to be drawn is larger than the area of "Canelli" when using same font, please use a smaller font size to draw "Chickpeas".
For example, setting font size to 6.
Code: Select all
Dim font As New PdfTrueTypeFont(New Font("Arial", 6.0F, FontStyle.Regular))


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2645
Joined: Wed Jun 27, 2012 8:50 am

Thu Apr 09, 2020 10:22 am

Thanks Amy that works just fine now
regards

lfcnutter
 
Posts: 7
Joined: Tue Apr 07, 2020 9:48 am

Fri Apr 10, 2020 1:28 am

Hi,

Thanks for your feedback.
I am glad to hear that it works.
Feel free to contact us if you need any other help.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2645
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDFViewer