powerpoint saga


B

bsg92618

I work for a company that has very rigid security guidelines.

I have been given a project to convert a PowerPoint presentation into a web
site that looks exactly like the ppt. this part was easy.

Then I have to provide a button that will convert the whole web site into a
PowerPoint presentation that the user can save on his local machine. The
website is database driven. The approach that I have taken is to dynamically
create the html for each page and save it to a file on the server. Then I
load the page into an IE window and capture to web page as a jpg image. As I
load the html, file into I Explorer the page changes to allow me to create
the next image file. My IT department in their infinite wisdom sees this as
a major security breach.

I need a way turn my html files into an image file without loading it into
IE. Please I need some help. I have looked all over the internet and the
only thing I could find is someone having the same type of issue but no one
has replied to him. I will past my code below.



my work email is (e-mail address removed)

please someone help me



This is a snippet from my constructor method





using System;

using mshtml;

using System.Windows.Forms;

using System.ComponentModel;

using System.Drawing.Imaging;

using System.Diagnostics;

using System.Drawing;

using System.Security.Principal;

using System.Collections.Generic;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

using System.Text;

using SHDocVw;

using System.Runtime.InteropServices;

using System.IO;

using System.Text.RegularExpressions;

using Microsoft.Office.Core;

using Microsoft.Office.Interop;

using Oracle.DataAccess.Client;

using System.Collections.Specialized;

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

//framework Dll for visweb project

using NG_Support_FrameWork;

using NG_GH_FrameWork;



SHDocVw.WebBrowser m_browser = null;
m_browser = new SHDocVw.WebBrowser();
mshtml.IHTMLDocument2 myieDoc =
(mshtml.IHTMLDocument2)m_browser.Document;
CreateImage(Number_OF_Pages, myieDoc);



The variable Number_OF_Pages is a string array that holds the path to each
html file. The html files has access to all the images and style sheets
needed to render the page the next method is where I create and save the
images



private void CreateImage(string[] PageArray, mshtml.IHTMLDocument2 myDoc)
{



try
{
for (int x = 0; x != Number_OF_Pages.Length; x++)
{
if (Number_OF_Pages[x] != null)
{
string pgum = Number_OF_Pages[x];
SHDocVw.WebBrowser m_browser = null;
m_browser = new SHDocVw.WebBrowser();
SHDocVw.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass();



//Find first availble browser window.
//Application can easily be modified to loop through and
capture all open windows.
string filename = "";



foreach (SHDocVw.WebBrowser ie in shellWindows)
{
filename =
Path.GetFileNameWithoutExtension(ie.FullName).ToLower();



if (filename.Equals("iexplore"))
{
m_browser = ie;
break;
}
}
//present user with a Close extra browser message
if (m_browser == null)
{
//MessageBox.Show("No Browser Open");
return;
}



//Assign Browser Document
//URL Location
// mshtml.IHTMLDocument2
myDoc = (mshtml.IHTMLDocument2)m_browser.Document;
string myLocalLink = myDoc.url;




object o = null;
//m_browser.FullScreen = true;
m_browser.Navigate(pgum, ref o, ref o, ref o, ref o);

int URLExtraHeight = 0;
int URLExtraLeft = 0;







//TrimHeight and TrimLeft trims off some captured IE graphics.
int trimHeight = 3;




//Use UrlExtra height to carry trimHeight.
URLExtraHeight = 0;
URLExtraLeft = 0;




//Set Browser Window Height
int heightsize = 3000;
int widthsize = 1500;



//Set Screen Height
int screenHeight = 3000;
int screenWidth = 3000;



//Get bitmap to hold screen fragment.
Bitmap bm = new Bitmap(3000, 3000,
System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
//Create a target bitmap to draw into.
Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize +
URLExtraHeight - trimHeight,
System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
Graphics g2 = Graphics.FromImage(bm2);



Graphics g = null;
IntPtr hdc;
Image screenfrag = null;
int brwTop = 0;
int brwLeft = 0;
int myPage = 0;
IntPtr myIntptr = (IntPtr)m_browser.HWND;
//Get inner browser window.
int hwndInt = myIntptr.ToInt32();
IntPtr hwnd = myIntptr;
hwnd = GetWindow(hwnd, GW_CHILD);
StringBuilder sbc = new StringBuilder(256);
//Get Browser "Document" Handle
while (hwndInt != 0)
{
hwndInt = hwnd.ToInt32();
GetClassName(hwndInt, sbc, 256);



if (sbc.ToString().IndexOf("Shell DocObject View", 0) > -1)
{
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet
Explorer_Server", IntPtr.Zero);
break;
}
hwnd = GetWindow(hwnd, GW_HWNDNEXT);



}



//Get Screen Height (for bottom up screen drawing)
while ((myPage * screenHeight) < heightsize)
{
myDoc.body.setAttribute("scrollTop", (screenHeight - 5) *
myPage, 0);
++myPage;
}
//Rollback the page count by one
--myPage;



int myPageWidth = 0;



while ((myPageWidth * screenWidth) < widthsize)
{
myDoc.body.setAttribute("scrollLeft", (screenWidth - 5) *
myPageWidth, 0);
brwLeft = (int)myDoc.body.getAttribute("scrollLeft", 0);
for (int I = myPage; I >= 0; --I)
{
//Shoot visible window
g = Graphics.FromImage(bm);
hdc = g.GetHdc();
myDoc.body.setAttribute("scrollTop", (screenHeight - 5)
* I, 0);
brwTop = (int)myDoc.body.getAttribute("scrollTop", 0);
PrintWindow(hwnd, hdc, 0);
g.ReleaseHdc(hdc);
g.Flush();
screenfrag = Image.FromHbitmap(bm.GetHbitmap());
g2.DrawImage(screenfrag, brwLeft + URLExtraLeft, brwTop
+ URLExtraHeight);
}
++myPageWidth;
}



ps I also get these error messages on a random basis



1.Retrieving the COM class factory for component with CLSID
{9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error:
8007000e. I get the error when I hit this line of code



shellWindows = new SHDocVw.ShellWindowsClass();



2. OUT OF MEMORY

this one is particulary confusing because when I watch my memory usage
it does not spike
 
Ad

Advertisements

A

Alvin Bruney [MVP]

post this in the aspnet newsgroup, see if you get any takers.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless Author Plug
OWC Black Book 2nd Edition
Exclusively on www.lulu.com/owc
$19.99


bsg92618 said:
I work for a company that has very rigid security guidelines.

I have been given a project to convert a PowerPoint presentation into a
web site that looks exactly like the ppt. this part was easy.

Then I have to provide a button that will convert the whole web site into
a PowerPoint presentation that the user can save on his local machine. The
website is database driven. The approach that I have taken is to
dynamically create the html for each page and save it to a file on the
server. Then I load the page into an IE window and capture to web page as
a jpg image. As I load the html, file into I Explorer the page changes to
allow me to create the next image file. My IT department in their infinite
wisdom sees this as a major security breach.

I need a way turn my html files into an image file without loading it into
IE. Please I need some help. I have looked all over the internet and the
only thing I could find is someone having the same type of issue but no
one has replied to him. I will past my code below.



my work email is (e-mail address removed)

please someone help me



This is a snippet from my constructor method





using System;

using mshtml;

using System.Windows.Forms;

using System.ComponentModel;

using System.Drawing.Imaging;

using System.Diagnostics;

using System.Drawing;

using System.Security.Principal;

using System.Collections.Generic;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

using System.Text;

using SHDocVw;

using System.Runtime.InteropServices;

using System.IO;

using System.Text.RegularExpressions;

using Microsoft.Office.Core;

using Microsoft.Office.Interop;

using Oracle.DataAccess.Client;

using System.Collections.Specialized;

using PowerPoint = Microsoft.Office.Interop.PowerPoint;

//framework Dll for visweb project

using NG_Support_FrameWork;

using NG_GH_FrameWork;



SHDocVw.WebBrowser m_browser = null;
m_browser = new SHDocVw.WebBrowser();
mshtml.IHTMLDocument2 myieDoc =
(mshtml.IHTMLDocument2)m_browser.Document;
CreateImage(Number_OF_Pages, myieDoc);



The variable Number_OF_Pages is a string array that holds the path to each
html file. The html files has access to all the images and style sheets
needed to render the page the next method is where I create and save the
images



private void CreateImage(string[] PageArray, mshtml.IHTMLDocument2 myDoc)
{



try
{
for (int x = 0; x != Number_OF_Pages.Length; x++)
{
if (Number_OF_Pages[x] != null)
{
string pgum = Number_OF_Pages[x];
SHDocVw.WebBrowser m_browser = null;
m_browser = new SHDocVw.WebBrowser();
SHDocVw.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass();



//Find first availble browser window.
//Application can easily be modified to loop through and
capture all open windows.
string filename = "";



foreach (SHDocVw.WebBrowser ie in shellWindows)
{
filename =
Path.GetFileNameWithoutExtension(ie.FullName).ToLower();



if (filename.Equals("iexplore"))
{
m_browser = ie;
break;
}
}
//present user with a Close extra browser message
if (m_browser == null)
{
//MessageBox.Show("No Browser Open");
return;
}



//Assign Browser Document
//URL Location
// mshtml.IHTMLDocument2
myDoc = (mshtml.IHTMLDocument2)m_browser.Document;
string myLocalLink = myDoc.url;




object o = null;
//m_browser.FullScreen = true;
m_browser.Navigate(pgum, ref o, ref o, ref o, ref o);

int URLExtraHeight = 0;
int URLExtraLeft = 0;







//TrimHeight and TrimLeft trims off some captured IE graphics.
int trimHeight = 3;




//Use UrlExtra height to carry trimHeight.
URLExtraHeight = 0;
URLExtraLeft = 0;




//Set Browser Window Height
int heightsize = 3000;
int widthsize = 1500;



//Set Screen Height
int screenHeight = 3000;
int screenWidth = 3000;



//Get bitmap to hold screen fragment.
Bitmap bm = new Bitmap(3000, 3000,
System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
//Create a target bitmap to draw into.
Bitmap bm2 = new Bitmap(widthsize + URLExtraLeft, heightsize +
URLExtraHeight - trimHeight,
System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
Graphics g2 = Graphics.FromImage(bm2);



Graphics g = null;
IntPtr hdc;
Image screenfrag = null;
int brwTop = 0;
int brwLeft = 0;
int myPage = 0;
IntPtr myIntptr = (IntPtr)m_browser.HWND;
//Get inner browser window.
int hwndInt = myIntptr.ToInt32();
IntPtr hwnd = myIntptr;
hwnd = GetWindow(hwnd, GW_CHILD);
StringBuilder sbc = new StringBuilder(256);
//Get Browser "Document" Handle
while (hwndInt != 0)
{
hwndInt = hwnd.ToInt32();
GetClassName(hwndInt, sbc, 256);



if (sbc.ToString().IndexOf("Shell DocObject View", 0)
{
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Internet
Explorer_Server", IntPtr.Zero);
break;
}
hwnd = GetWindow(hwnd, GW_HWNDNEXT);



}



//Get Screen Height (for bottom up screen drawing)
while ((myPage * screenHeight) < heightsize)
{
myDoc.body.setAttribute("scrollTop", (screenHeight - 5) *
myPage, 0);
++myPage;
}
//Rollback the page count by one
--myPage;



int myPageWidth = 0;



while ((myPageWidth * screenWidth) < widthsize)
{
myDoc.body.setAttribute("scrollLeft", (screenWidth - 5) *
myPageWidth, 0);
brwLeft = (int)myDoc.body.getAttribute("scrollLeft", 0);
for (int I = myPage; I >= 0; --I)
{
//Shoot visible window
g = Graphics.FromImage(bm);
hdc = g.GetHdc();
myDoc.body.setAttribute("scrollTop", (screenHeight -
5) * I, 0);
brwTop = (int)myDoc.body.getAttribute("scrollTop", 0);
PrintWindow(hwnd, hdc, 0);
g.ReleaseHdc(hdc);
g.Flush();
screenfrag = Image.FromHbitmap(bm.GetHbitmap());
g2.DrawImage(screenfrag, brwLeft + URLExtraLeft,
brwTop + URLExtraHeight);
}
++myPageWidth;
}



ps I also get these error messages on a random basis



1.Retrieving the COM class factory for component with CLSID
{9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error:
8007000e. I get the error when I hit this line of code



shellWindows = new SHDocVw.ShellWindowsClass();



2. OUT OF MEMORY

this one is particulary confusing because when I watch my memory usage
it does not spike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top