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

Wed May 23, 2018 10:37 am

Hi I have a simple web form - added the PDFViewer control, added the following lines:
If Not Page.IsPostBack Then

With PdfViewer1
.CacheInterval = 1000
.CacheTime = 1200
.CacheNumberImage = 1000
.ScrollInterval = 300
.ZoomFactor = 1.0F
.CustomErrorMessages = ""
End With
PdfViewer1.LoadFromFile("c:\temp\test.pdf")
End If
run the page and I get the following error:
Page request fails, it may have been released stream

Forensicare
 
Posts: 22
Joined: Fri Aug 02, 2013 3:29 am

Thu May 24, 2018 10:03 am

Hello,

Thanks for your post.
As for the LoadFromFile method, due to the permission on website, you need to create a new folder under your project and then put the pdf you want to load into the folder.
13928.png

Code: Select all
this.PdfViewer1.LoadFromFile(@"File/test.pdf");

If you want to load pdf from other place, you could use LoadFromStream method.
Code: Select all
var Path = "C:\\temp\\test.pdf";
var data = File.ReadAllBytes(Path);
var pdfStream = new MemoryStream(data);
this.PdfViewer1.LoadFromStream(pdfStream);



Sincerely,
Wade
E-iceblue support team
User avatar

Wade.shao
 
Posts: 32
Joined: Thu Mar 22, 2018 8:23 am

Fri May 25, 2018 7:19 am

Thank you, that worked perfectly.

Forensicare
 
Posts: 22
Joined: Fri Aug 02, 2013 3:29 am

Fri May 25, 2018 7:32 am

Hello,

Thanks for your feedback.
Just feel free to contact us if you need any assistance.

Sincerely,
Wade
E-iceblue support team
User avatar

Wade.shao
 
Posts: 32
Joined: Thu Mar 22, 2018 8:23 am

Sun Jul 19, 2020 10:25 am

Hello,

How to configure and change the message "Page request fails,it may have been released stream" to other language (Simplified Chinese)?

Thanks.

zhengwenrui
 
Posts: 2
Joined: Wed Jul 15, 2020 3:47 pm

Mon Jul 20, 2020 9:17 am

Hi zhengwenrui,

Thanks for your inquiry.
Sorry to tell you that there is no multi-language configuration in our product. For your requirement, you can refer to the following code snippet to catch the exception and configure custom error messages.
Code: Select all
    try
    {
        //When setting a wrong path
        this.PdfDocumentViewer1.LoadFromFile("filepath");
    }
    catch (Exception ex)
    {
        //Custom error message
        HttpContext.Current.Response.Write("<script>alert('打开文档错误!')</script>");
    }

But unfortunately, there are still some problems with the exception handling of the "LoadFromFile" method. It cannot throw the exception as expected. I have posted this issue to our Dev team with the ticket SPIREPDFVIEWER-457 for further investigation and fixing. If there is any update, we will let you know.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1573
Joined: Tue Jul 09, 2019 2:22 am

Wed Jul 22, 2020 7:10 am

Hi zhengwenrui,

Hope you are doing well.
I got information from our Dev team that when the path of the loaded file is incorrect, our product will not handle such exceptions, so the "LoadFromFile" method won't throw an exception. In this case, you can refer to the following code to handle it. If you have further questions or needs, please provide us with detailed information, then we will do further investigation.
Code: Select all
                try
                {
                    if (!File.Exists(filepath))
                    {
                        HttpContext.Current.Response.Write("<script>alert('文档路径不存在!')</script>");
                        //throw new Exception();
                    }
                    else
                    {
                        this.PdfDocumentViewer1.LoadFromFile(filepath);
                    }             
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Response.Write("<script>alert('打开文档错误!')</script>");
                }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1573
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDFViewer