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

Thu Nov 26, 2015 4:19 pm

Hi!

How can I clean the content of pdfViewer? I want load other document but the content of viewer doesn't change, it's the same that
the first document.

If I change the size of iframe and the document, only changes the size.

In other post I have seen that the response:

"If you want to load other file, just call method pdfDocumentViewer1.LoadFromFile ("yourfilepath"); if you want to close the opened file, call method pdfDocumentViewer1.CloseDocument()."

But I don't see the method closeDocument to try to use it.


My code

DocumentoDeSharepointBL sharepointDocBO = new DocumentoDeSharepointBL(this.CRMService);
urlDocumento = sharepointDocBO.getRutaAbsolutaAdjunto(urlDocumento);
System.IO.Stream sharepointDoc = sharepointDocBO.GetDocumentoSharePoint(urlDocumento);
byte[] documento = CommonUtils.ToByteArray(sharepointDoc);
MemoryStream fs = new MemoryStream();
fs.Write(documento, 0, documento.Length);
this.PdfViewer1.CacheInterval = 1200;
this.PdfViewer1.CacheTime = 1000;
this.PdfViewer1.LoadFromStream(fs);

Thanks!

Blanquita_84
 
Posts: 44
Joined: Tue Oct 13, 2015 8:58 am

Fri Nov 27, 2015 3:39 am

Hi,

Thanks for your inquiry.
Please try the following code snippet.
Code: Select all
 if (!string.IsNullOrEmpty(Request["CacheStreamTime"]))
                {
                    this.PdfViewer1.CacheTime = int.Parse(Request["CacheTime"].ToString());//second
                    this.PdfViewer1.CacheInterval = int.Parse(Request["CacheInterval"].ToString());//second
                    this.PdfViewer1.CacheNumberImage = int.Parse(Request["CacheNumberImage"].ToString());
                    this.PdfViewer1.ScrollInterval = int.Parse(Request["ScrollInterval"].ToString());
                    this.PdfViewer1.ZoomFactor = float.Parse(Request["ZoomFactor"].ToString());
                    this.PdfViewer1.CacheNumberStream = int.Parse(Request["CacheNumberStream"].ToString());
                    this.PdfViewer1.CacheStreamTime = int.Parse(Request["CacheStreamTime"].ToString());
                    this.PdfViewer1.CacheStreamInterval = int.Parse(Request["CacheStreamInterval"].ToString());

                    byte[] data = System.IO.File.ReadAllBytes(Server.MapPath("/") + "files\\" + Request["Files"].ToString());
                    System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
                    this.PdfViewer1.LoadFromStream(stream);

                }
                else
                {
                    //The interval time of emptying caching, specified in seconds.
                    this.PdfViewer1.CacheInterval = 1200;
                    //caching time of an image, specified in seconds.
                    this.PdfViewer1.CacheTime = 1000;
                    //Cache the number of Image, default is 1000.
                    this.PdfViewer1.CacheNumberImage = 1000;
                    //The time of responding to event after stop scrolling, specified in milliseconds.default is 500.
                    this.PdfViewer1.ScrollInterval = 300;
                    //Zoom value of page, default is 1.
                    this.PdfViewer1.ZoomFactor = 1;
                    this.PdfViewer1.CacheNumberStream = 100;
                    this.PdfViewer1.CacheStreamTime = 1000;
                    this.PdfViewer1.CacheStreamInterval = 1200;
                    this.PdfViewer1.CustomErrorMessages = "Error information";
                    byte[] data = System.IO.File.ReadAllBytes(Server.MapPath("/") + "files\\Testfile_1.pdf");
                    System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
                    this.PdfViewer1.LoadFromStream(stream);
                }

And then use a url to load other document.
For example:
http://localhost:4079/Default.aspx?CacheTime=1000&CacheInterval=1200&CacheNumberImage=1000&CacheStreamTime=1000&CacheStreamInterval=1200&CacheNumberStream=100&ZoomFactor=1&ScrollInterval=300&Files=Testfile_2.pdf

Best Regards,
Amy
E-iceblue support team
User avatar

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

Fri Nov 27, 2015 10:27 am

Hi!

I tried with your code, but the error continues. This error began with the newest dll for can change the size of the iframe , but with the latest dll the error doesn't happen.

I prove the same code with the newest dll and the previous dll, and works with the previous but not with the newest.

I send the dlls with which I tested the code.

Thanks!

Blanquita_84
 
Posts: 44
Joined: Tue Oct 13, 2015 8:58 am

Mon Nov 30, 2015 3:23 am

Hello,

Thanks for your feedback, but there is no any attachments, please send it again.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Nov 30, 2015 8:06 am

Hi!

I send you a emial with the link of mega for download the dlls.

Thanks!

Blanquita_84
 
Posts: 44
Joined: Tue Oct 13, 2015 8:58 am

Mon Nov 30, 2015 8:10 am

Hello,

I have get it and will look into it.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Nov 30, 2015 11:40 am

Hi!

I detected some errors.

1. The pdfViewer doesn't update de content, but if I click the button of zoom(PdfViewer1_btnZoomPage, PdfViewer1_btnNarrowPage),content changes pdfViewer, but it's still wrong because the content is a selected document before but not the current.

2. if I change the option of "PdfViewer1_SelectCurrentZoomLevel", the zoom changes but in the value of option appear "isNaN".

Thanks!

Blanquita_84
 
Posts: 44
Joined: Tue Oct 13, 2015 8:58 am

Tue Dec 01, 2015 9:30 am

Hello,

Thanks for the information. What's your test environment? And please provide us your project to help us reproduce your issue.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Dec 02, 2015 5:55 pm

Hi!

I sent you a email with the link of mega for download the proyect.

I checked that if I use the method "LoadFromFile", the code works ok but if I use the method "LoadFromStream", the content
of pdfViewer doesn't update with the new stream.

The code doesn't work and either locally or on the server

In local:

-Windows 8
-Internet Explorer 11

In server:

-Windows Server 2012

Thanks!

Blanquita_84
 
Posts: 44
Joined: Tue Oct 13, 2015 8:58 am

Thu Dec 03, 2015 3:19 am

Hi,

Please try the following code snippet:
Code: Select all
 public partial class Default : System.Web.UI.Page
    {   
        private void CargarPreView()
        {
            FileStream fs = null;
            fs = System.IO.File.OpenRead(Server.MapPath("/") + "files\\tabla.pdf");
            byte[] bytes = new byte[fs.Length];
            fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
            var ms = new MemoryStream();
            fs.Position = 0;
            fs.CopyTo(ms);
            fs.Close();
            fs.Dispose();
            this.PdfViewer1.CacheInterval = 1200;
            this.PdfViewer1.CacheTime = 1000;
            //this.PdfViewer1.LoadFromFile("files\\tabla.pdf");
            this.PdfViewer1.LoadFromStream(ms);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["CacheStreamTime"]))
                {
                    this.PdfViewer1.CacheTime = int.Parse(Request["CacheTime"].ToString());//second
                    this.PdfViewer1.CacheInterval = int.Parse(Request["CacheInterval"].ToString());//second
                    this.PdfViewer1.CacheNumberImage = int.Parse(Request["CacheNumberImage"].ToString());
                    this.PdfViewer1.ScrollInterval = int.Parse(Request["ScrollInterval"].ToString());
                    this.PdfViewer1.ZoomFactor = float.Parse(Request["ZoomFactor"].ToString());
                    this.PdfViewer1.CacheNumberStream = int.Parse(Request["CacheNumberStream"].ToString());
                    this.PdfViewer1.CacheStreamTime = int.Parse(Request["CacheStreamTime"].ToString());
                    this.PdfViewer1.CacheStreamInterval = int.Parse(Request["CacheStreamInterval"].ToString());


                    byte[] data = System.IO.File.ReadAllBytes(Server.MapPath("/") + "files\\" + Request["Files"].ToString());
                    System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
                    this.PdfViewer1.LoadFromStream(stream);
                }
                else
                {
                    CargarPreView();
                }
            }
        }
    }


When you first start it up, you should get a link likes "http://localhost:1796/Default.aspx".
Please directly use the url likes "http://localhost:1796/Default.aspx?CacheTime=1000&CacheInterval=1200&CacheNumberImage=1000&CacheStreamTime=1000&CacheStreamInterval=1200&CacheNumberStream=100&ZoomFactor=1&ScrollInterval=300&Files=traducido.pdf" to visit another pdf file.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Thu Dec 03, 2015 9:08 am

Hi!

I checked the code, and this works if I use a document located in the folder called "files" of the proyect Asp, but
If I try to view a document located in another place, like "C:\Users\patricia.blanco\Downloads\tabla.pdf" or Sharepoint, the content of pdfViewer doesn't update.

In my real proyect, I need to show documents that are located in Sharepoint.

Thanks!

Blanquita_84
 
Posts: 44
Joined: Tue Oct 13, 2015 8:58 am

Fri Dec 04, 2015 2:26 am

Hi,

Please change source code to
byte[] data = System.IO.File.ReadAllBytes(Request["Files"].ToString());
, and then try to visit the url likes
http://localhost:1796/Default.aspx?CacheTime=1000&CacheInterval=1200&CacheNumberImage=1000&CacheStreamTime=1000&CacheStreamInterval=1200&CacheNumberStream=100&ZoomFactor=1&ScrollInterval=300&Files=C:\Users\patricia.blanco\Downloads\tabla.pdf

Best Regards,
Amy
E-iceblue support team
User avatar

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

Mon Jan 08, 2018 8:16 pm

I am trying to use two buttons to display two different pdf's such that when button 1 is clicked, it displays pdf 1 and when button 2 is clicked, it should display pdf 2.

It was working fine until the new spire versions. With the current version, it just displays the 1st pdf that is displayed. It doesn't display the other pdf even though value seem to pass to the pdfviewer control.

I am using spire versions pdfviewer.asp - 2.12.47.14340, spire.pdf - 3.9.480.14040.

this.pdfViewer1.CacheInterval = 1000;
this.pdfViewer1.CacheTime = 1200;
this.pdfViewer1.CacheNumberImage = 1000;
this.pdfViewer1.ScrollInterval = 300;
this.pdfViewer1.ZoomFactor = 1f;
this.pdfViewer1.CustomErrorMessages = "";
this.pdfViewer1.Height = 8000;
var Path = @"C:\(***Localpath***)";

var data = File.ReadAllBytes(Path);
var pdfStream = new MemoryStream(data);
pdfViewer1.LoadFromStream(pdfStream);

Walter.Wh
 
Posts: 2
Joined: Mon Jan 08, 2018 7:53 pm

Tue Jan 09, 2018 3:55 am

Hello,

Thanks for your feedback. I have noticed the issue and logged it into our bug tracking system. We apologize for the inconvenience. If there is any update, we will notify you.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Tue Jan 09, 2018 5:32 pm

Hi Simon,

Thank for your prompt reply. Do you have a timeline for the fix to be passed as an update?

Walter.Wh
 
Posts: 2
Joined: Mon Jan 08, 2018 7:53 pm

Return to Spire.PDFViewer