Issues when trying to export a page from RadPdfViewer directly to a Bitmap, without saving the file to the computer.

2 Answers 33 Views
Accessibility Form General Discussions PdfViewer and PdfViewerNavigator
F3M
Top achievements
Rank 2
Iron
F3M asked on 28 Nov 2024, 11:09 AM

I have this code, and I just want to export all pages or a specific page from the loaded PDF in the RadPdfViewer, without saving the file to the computer.

The function RadPdfViewer.ExportPage returns a Bitmap, but when I assign the result of this function to a new variable of type Bitmap, an error occurs.

 

'1º Option - Work
            For i As Integer = 1 To RadPdfViewer1.Document.Pages.Count
                Dim guid As Guid = Guid.NewGuid

                RadPdfViewer1.ExportPage(i, "C:\temp\" & guid.ToString() & ".pdf", 1, True, ImageFormat.Png)

                Dim bitmap As Bitmap = New Bitmap("C:\temp\" & guid.ToString() & ".pdf")

                Dim reader As BarcodeReader = New BarcodeReader With {
                        .AutoRotate = True,
                        .TryInverted = True
                        }

                Dim result As Result = reader.Decode(bitmap)

                If result Is Nothing Then Continue For

                Dim decoded As String = result.ToString().Trim()

                If decoded Is Nothing Then Continue For

                If decoded <> TextBox1.Text Then TextBox1.Text = TextBox1.Text & vbNewLine & vbNewLine & decoded

                bitmap.Dispose()
                My.Computer.FileSystem.DeleteFile("C:\temp\" & guid.ToString() & ".pdf")
            Next

            '2 Option - Dont Work
            Dim bitmap As Bitmap = RadPdfViewer1.ExportPage(1, 1, False, ImageFormat.Png)

            '3º Option - Dont Work
            For Each bitmap As Bitmap In RadPdfViewer1.ExportPages(1, False, ImageFormat.Bmp)
                Dim reader As BarcodeReader = New BarcodeReader With {
                        .AutoRotate = True,
                        .TryInverted = True
                        }

                Dim result As Result = reader.Decode(bitmap)

                If result Is Nothing Then Continue For

                Dim decoded As String = result.ToString().Trim()

                If decoded Is Nothing Then Continue For

                If decoded <> TextBox1.Text Then TextBox1.Text = TextBox1.Text & vbNewLine & vbNewLine & decoded
            Next

2 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 03 Dec 2024, 08:32 AM

Hello,

Thank you for writing.

I tried to use the provided code snippet in a sample test project but it is difficult to replicate what exactly you have in mind. This is why I am providing my test project. Is it possible for you to update my project in such a way to reproduce there the issue that you are facing. This will be very helpful to me in understanding the exact case with ExportPage(). Thank you in advance for your understanding and cooperation. 

I am looking forward to your reply.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
F3M
Top achievements
Rank 2
Iron
answered on 04 Dec 2024, 09:56 AM

Hi,

Here’s the project. I’m not using RadForm, but the concept is the same. This is an example of what I need: I’m using a WindowsForm with one button, one PictureBox, and one RadPDFViewer.

In the attached ZIP file, there’s a PDF example to try loading into the RadPDFViewer. When I press the button, it returns an error. What I need is to display the first page of the loaded PDF in the PictureBox without saving the .png file to the computer.

Version of Telerik: 2021.2.511.40

Nadya | Tech Support Engineer
Telerik team
commented on 06 Dec 2024, 02:29 PM

Hello, 

Thank you for the updated project.

I have reviewed the sample code snippet for exporting to image on a button click and it seems ok to me. Then, I test the project with the latest Telerik version 2024.4.1113 and it is working as expected. I did not any modifications in your code. The image is correctly exported from the pdf viewer and displayed in the picture box next to it. You can see the result on my end in the attached gif file. 

I noticed that there was an older version referred in your test project. Is it possible to get our latest version and obtain the desired behavior that you want. By upgrading to latest version you should be able to benefit from all other improvements that we have made recently in our controls: How to Upgrade a Telerik UI for WinForms Project - Telerik UI for WinForms

I hope this information helps. Please let me know if I can assist you further.

Tags
Accessibility Form General Discussions PdfViewer and PdfViewerNavigator
Asked by
F3M
Top achievements
Rank 2
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
F3M
Top achievements
Rank 2
Iron
Share this question
or