Spire.OfficeViewer for .NET as a powerful Office Viewer component, is designed for developers to load Word, Excel, Presentation slides and PDF files and view them from Windows Forms Applications.

Thu Jun 27, 2019 3:00 am

I want to adjust the size automatically after loading a file using LoadFromStream method.(MemoryStream)

The code below is from the example file.

public Form1()
{
InitializeComponent();
MemoryStream ms = new MemoryStream(File.ReadAllBytes(@"..\..\..\..\..\..\Data\Spire.Office.pdf"));
this.documentViewer1.LoadFromStream(ms);
documentViewer1.ZoomTo(Spire.OfficeViewer.Forms.ZoomMode.FitPage);
}

right after LoadFromStream method, it doesn't work.
But after loading file completely,(When the viewer is finished rendering and the screen is visible,) Zoomto method works well.
If I can set the time when the rendering ends, I think I can apply it with a function right after that point.

How do i know the end of rendered point from stream loading?

-------------------------------------------------------------------------------------------
I found the event DocLoaded.
but could I set the size of file loading?

kelesym
 
Posts: 12
Joined: Thu Jan 04, 2018 1:42 am

Thu Jun 27, 2019 6:33 am

Hello,

Thanks for your inquiry.
You can refer to the following sample code to make the size fit page after LoadFromStream. If there is any question, just feel free to write back.
Code: Select all
public Form1()
{
    InitializeComponent();
    this.documentViewer1.DocLoaded += new Spire.OfficeViewer.Forms.DocumentOpenedEventHandler(documentViewer1_DocLoaded);
    MemoryStream ms = new MemoryStream(File.ReadAllBytes(@"..\..\..\..\..\..\Data\Spire.Office.pdf"));
    this.documentViewer1.LoadFromStream(ms);
}
void documentViewer1_DocLoaded(object sender, EventArgs args)
{
    this.documentViewer1.ZoomTo(Spire.OfficeViewer.Forms.ZoomMode.FitPage);
}

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1270
Joined: Wed Apr 25, 2018 3:20 am

Mon Jul 01, 2019 8:34 am

Hello,

Greetings from E-iceblue.
Did my solution meet your requirement? Your feedback will be greatly appreciated. Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1270
Joined: Wed Apr 25, 2018 3:20 am

Mon Jul 01, 2019 9:08 am

Thank you :D

Actually, I already found DocLoaded event, but it works after loaded fully.
I wanted to apply the size when I started downloading, but it seems impossible.
So I decided to be satisfied with the size adjustment after downloading.

Have a good day!

kelesym
 
Posts: 12
Joined: Thu Jan 04, 2018 1:42 am

Mon Jul 01, 2019 9:59 am

Hello,

Thanks for your feedback.
If you need further assistance, please contact us without any hesitation. Wish you all the best.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1270
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.OfficeViewer