Can width/height of a powerpoint presentation be calculated on iPad
Asked Answered
R

2

1

I have an ipad app, which displays a powerpoint presentation from an NSData, within a UIWebView, and I need to know the width/height of a single slide so I know how far to scroll when advancing to the next slide.

In PDF, I can calculate it using CGPDFDocumentRef, as below, but I can't find a corresponding API for powerpoint, and since it's a microsoft format, I doubt it even exists.

I can use javascript to determine the width/height of the ENTIRE presentation, but that doesn't help me know how far to advance to go one single slide,

Code to do what I need to for a PDF:

CFDataRef myPDFData = (CFDataRef)presentationContent;
CGDataProviderRef provider = CGDataProviderCreateWithCFData(myPDFData);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(provider);
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
int pageHeight=(int)pageRect.size.height;
int pageWidth=(int)pageRect.size.width;
//now I can advance to the proper page by doing a scrollto pageHeight*currentPage
Rebec answered 29/8, 2011 at 13:20 Comment(6)
Since slide height and width is a presentation-level property in PPT (in other words, all slides have the same dimensions), if you can derive the height for the presentation, you have the height for each slide IN the presentation. But are you actually working with PPT and slides or with some other app's representation of the presentation's contents?Crutch
@Steve, I'm using UIWebView's representation of the slide/presentation content. You can run javascript on it to determine content height/width, but height=height of ENTIRE presentation, from the first pixel in slide 1 to the last pixel in slide N. If I could determine the number of slides, I could take that number and divide, but I don't know the number of slides, and have no way of knowing.Rebec
So in effect the entire presentation becomes one big scrollable web page or something like that? I thought from context that that might be the case but didn't know for sure. Does each slide get converted to an image (and if so, can you get its height from the DOM?)Crutch
Yes, it becomes one huge scrollable web page - but it doesn't parse it into HTML, so I can't grab a single slide as an image as you suggest. I'm currently experimenting with document.all[someindex].offsetHeight and offsetWidth - but "someindex" seems to change each time the ppt loads. I think there's a pattern I can look for, and will post if I find a reliable way of getting slide height... FYI, sometimes document.all.length is, like 10 or so, sometimes >300, and the proper element to look for is burried somewhere in that mess. :(Rebec
What exactly does the presentation become? Can you post an example somewhere? I doubt I could make any sense out of it but I'd be curious to see it.Crutch
Not sure what you're asking for - basically, it's like if you had an iframe on a webpage, and it's source was a powerpoint file. You can run javascript on it to do certain things (like scrollTo(somenumberofpixels) to scroll down the page), but it is one blob of data, not segmented properly into html - I don't think. However, I've found the solution to my problem - posting it nowRebec
R
3

Figured it out.

In this case, the UIWebView acts as if it's an iFrame on an HTML page, which has a source of some powerpoint file. So, there are certain things you can do to it, and certain properties that are exposed.

I found that document.all (an array) has elements - LOTS of elements. My 20 page powerpoint test file had over 300 elements. Looking at width / height of them was not overly helpful - some were the dimensions of the iframe itself, some were the dimensions from top-left pixel of slide 1 to bottom-right pixel of slide N, some were 0x0, and some (burried in the middle) were the dimensions of a slide. The pattern I found was that you have to skip the first element in document.all, and iterate through until you found one with non-zero width/height, who have identical values for clientHeight, offsetHeight, scrollHeight, as well as identical values for clientWidth, offsetWidth, and scrollWidth. The first one of these will give you the height/width of a single slide, and you can go from there. And, of course, because you're using a UIWebView, and only have stringByEvaluatingJavaScriptFromString to work with, you need to do this all in one line of javascript that returns the value.

So, to extract width/height of a powerpoint presentation, you can write:

NSString *w=[webview stringByEvaluatingJavaScriptFromString:@"function x(){var rtn='';for (var i=1;i<document.all.length;i++){var a=document.all[i];if (((a.clientWidth>0)&&(a.clientHeight>0))&&(a.scrollHeight.toString()==a.offsetHeight.toString())&&(a.offsetHeight.toString()==a.clientHeight.toString())){return ''+a.offsetWidth; }}return rtn;};x();"];
NSString *h=[webview stringByEvaluatingJavaScriptFromString:@"function x(){var rtn='';for (var i=1;i<document.all.length;i++){var a=document.all[i];if (((a.clientWidth>0)&&(a.clientHeight>0))&&(a.scrollHeight.toString()==a.offsetHeight.toString())&&(a.offsetHeight.toString()==a.clientHeight.toString())){return ''+a.offsetHeight; }}return rtn;};x();"];

and do whatever you need to with width/height from that point on.

Oh, and document.all isn't populated immediately once your document is loaded - UIWebView seems to need a few milliseconds to gather that and make it available. I run this 1 second after my webview has finished loading, and it works great on both ppt and pptx files. it does NOT work on pdf, though.

Rebec answered 1/9, 2011 at 15:59 Comment(0)
A
0

amongst others, these objects contain width and height properties:

Sub Test()
Dim A As Application

    Set A = Application
    Debug.Print A.Width, A.Height
    Debug.Print A.Windows(1).Width, A.Windows(1).Height
    Debug.Print A.SlideShowWindows(1).Width, A.SlideShowWindows(1).Height

End Sub

The most suitable for you seems to be the last one.

Results for a 1680 x 1050 screen

PPT in full-screen

 1266          793,5 
 1245,75       699,75 
 1260          787,5 

PPT in ca. 1/2 of screen

 711,75        551,25 
 691,5         457,5 
 1260          787,5  <-- same as above as slideshows always go full-screan at the selected aspect ratio
Abomasum answered 30/8, 2011 at 10:24 Comment(3)
thanks, but (unless I read you wrong) you seem to be assuming I am running this in powerpoint, or ppviewer - I'm not. It's displaying in a UIWebView within an iPad application, and isn't even running as a ppt application, but more as a web browser would display it. I'm reasonably sure I don't get any VBA DOM access - though it's not a bad idea for me to double check. I'll give it a whirl (as well as trying other javascriptie possibilities), and will post if your stuff helps, but unless you hear back in the positive, your solution won't work.Rebec
Sorry ... I seem to have missed this point ... I will remove my answer tomorrowAbomasum
might as well keep your post - it doesn't answer the problem, but doesn't send me off on the wrong track, either, and it might help myself or others try to find the proper solution as well. Thanks!Rebec

© 2022 - 2024 — McMap. All rights reserved.