PDF Viewer Component – ApplyViewRect

Function: boolean ApplyViewRect(float left, float top, float width, float height)
Description: Sets the view rectangle according to the specified coordinates.
Param:
left – The upper left horizontal coordinate.
top – The vertical coordinate in the upper left corner.
width – The horizontal width of the rectangle.
height – The vertical height of the rectangle.

PDF Viewer Component – PrintPages

boolean PrintPages(long from, long to);
Description: Prints the specified pages without displaying a user dialog box. The current printer, page settings, and job settings are used.This method returns immediately, even if the printing has not completed. NOTE: If security settings do not allow printing, this method will be ignored.
Param:
from – The page number of the first page to be printed. The first page in a document is page 0.
to – The page number of the last page to be printed.

PDF Viewer Component – PrintPagesFit

Function: boolean PrintPagesFit(long from, long to, boolean shrinkToFit);
Description: Prints the specified pages without displaying a user dialog box. The current printer, page settings, and job settings are used. This method returns immediately, even if the printing has not completed. NOTE:If security settings do not allow printing, this method will be ignored.
Param:
from – The page number of the first page to be printed. The first page in a document is page 0.
to – The page number of the last page to be printed.
shrinkToFit – Specifies whether the pages will be shrunk, if necessary, to fit into the imageable area of a page in the printer.

PDF Viewer Component – PrintAll

Function: boolean PrintAll ();
Description: Prints the entire document without displaying a user dialog box. The current printer, page settings, and job settings are used. This method returns immediately, even if the printing has not completed. NOTE: If security settings do not allow printing, this method will be ignored.

Enumerate the menu name in MS Office

Sub ListShortCutMenus()
Cells.Clear
Application.ScreenUpdating = False
Row = 1
For Each cbar In CommandBars
If cbar.Type = msoBarTypePopup Then
Cells(Row, 1) = cbar.Index
Cells(Row, 2) = cbar.Name
For col = 1 To cbar.Controls.Count
Cells(Row, col + 2) = _
cbar.Controls(col).Caption
Next col
Row = Row + 1
End If
Next cbar
Cells.EntireColumn.AutoFit
End Sub

Better office viewer component than the WebBrowser control to open an Office document

When working with Office Documents you may want to display these documents directly in Visual Basic, but do not want to create an embedded OLE object using the OLE container control. Instead, you would like to link to an existing document and open it as an in-place ActiveX Document object.

ActiveX Documents are embeddable OLE objects that behave more like ActiveX controls than traditional OLE objects. Unlike a normal embedded object, an ActiveX Document is not designed to be a contained object in a larger document. Instead, it is considered a complete document in itself, which is merely being viewed by a viewer (such as Internet Explorer) or is being collected into a single resource with other documents (such as a Binder file).

While Microsoft Visual Basic does not currently support hosting ActiveX Documents directly, you can work around this limitation by using the capabilities of Internet Explorer and its WebBrowser control. The WebBrowser control (Shdocvw.dll) is a part of Internet Explorer and can only be used on systems that have Internet Explorer installed.

But the Webbrowser control has lot’s of flaws. It can’t open the office viewer with the read only property. It can’t open the file stream and save it back to the server. There isn’t any support for the office automation so that the developers can’t extend the own functions.

Fortunately, the Edraw Office Viewer Component offers the solution. It acts as an ActiveX document container for embeding Office documents (including Microsoft Word, Microsoft Excel, Microsoft PowerPoint, Microsoft Project, and Microsoft Visio documents) in a custom form or Web page. The control is lightweight and flexible, and gives developers new possibilities for using Office in a custom solution. More information

Fixed the vulnerable functions of Office Viewer Component

New version has removed the ”DeleteLocalFile” method to avoid the attack. Now the component will delete the temporary files when it exits.

We improved the HTTP download file too and provide a securer download method in the version 5.

The follow article is the vulnerable description about the 4.0 version. 

Multiple vulnerabilities have been identified in EDraw Office Viewer Component v4.0, which could be exploited by remote attackers to delete arbitrary files or take complete control of an affected system.

The first issue is caused by a design error in the “DeleteLocalFile()” method within the “edrawofficeviewer.ocx” ActiveX control, which could be exploited by attackers to delete arbitrary files from a vulnerable system by tricking a user into visiting a specially crafted web page.

The second vulnerability is caused by a buffer overflow error in the “edrawofficeviewer.ocx” ActiveX control when processing malformed arguments passed to the “HttpDownloadFile()” method, which could be exploited by remote attackers to execute arbitrary code via a malicious web page.

Enumerate all the caption in the context menu of MS Office

Sub ListCellControls()
k = Application.CommandBars(“Cell”).Controls.Count
For i = 1 To k
Cells(i, 1) = i ‘ID
Cells(i, 2) = Application.CommandBars(“Cell”).Controls(i).Caption
Next i
End Sub

Upload a file to a Web server in ASP.NET

EDraw WebOffice Component provides some methods to upload the file to a web server.

HTTP Post

[id(36), helpstring("Initializes the HTTP connection.")]
   boolean HttpInit();

[id(37), helpstring("Adds the post parameter.")]
   boolean HttpAddpostString([in] BSTR Name, [in] BSTR Value);

[id(38), helpstring("Adds the post file.")]
   boolean HttpAddPostFile([in] BSTR LocalFilePath, [in] BSTR NewFileName);

[id(39), helpstring("Executes the post action.")]
   boolean HttpPost([in] BSTR WebUrl,[in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);

You can use the follow steps to save the opened office document to a web server.

Sub SavetoServer()
    ‘ASP.NET’
    OA1.HttpInit
    OA1.HttpAddpostString “author”, “anyname”
    OA1.HttpAddpostString “Data”, “2007-5-15″
    OA1.HttpAddPostFile “”, “newfilename.doc”
    OA1.HttpPost “http://localhost:1320/Samples/UploadAction.aspx“    
       
    ‘Or you can call the Save method to upload the openned file to the server directly.For examples:
    ‘OA1.Save “http://localhost:1320/Samples/UploadAction.aspx?FileName=newname
End Sub

Note: If the first parameter of “HttpAddPostFile” is blank, the method will upload the opened office file to server.

Then you need to write a ASP.NET Get page to receipt the file.

Review the follow examples:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;

public partial class UploadAction : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["author"] == “anyname” && Request.Params["Data"] == “2007-5-15″)
        {
            Response.Write(“0\n”);
            Response.Write(“We have receipted the right param from Office ActiveX Control.”);
        }
        if (Request.Files.Count == 0)
        {
            Response.Write(“0\n”);
            Response.Write(“There isn’t file to upload.”);
            Response.End();
        }
        if (Request.Files[0].ContentLength == 0)
        {
            Response.Write(“0\n”);
            Response.Write(“Failed to receipt the data.\n\n”);
            Response.End();
        }
        string fullFileName = Server.MapPath(Request.Files[0].FileName);
        Request.Files[0].SaveAs(fullFileName);
        Response.Write(“Upload Successfully.”);
        Response.End();
    }
}

How to insert an Office document directly into my Visual Basic form

Microsoft Excel, Microsoft PowerPoint and Microsoft Word support both Object Linking and Embedding (OLE) and ActiveX Document containment. If you want to “host” an Office document in Visual Basic, you can use the OLE Container control and OLE. You can also use the WebBrowser control included with Microsoft Internet Explorer to provide basic ActiveX Document containment. But the simplest and effective method is using the Edraw office Viewer Component. It is a script safe office viewer component. Support more customize methods and events.