可以在iPad上计算powerpoint演示文稿的宽度/高度

时间:2011-08-29 13:20:31

标签: iphone objective-c ios powerpoint dimensions

我有一个ipad应用程序,它在UIWebView中显示来自NSData的powerpoint演示文稿,我需要知道单张幻灯片的宽度/高度,所以我知道在前进到下一张幻灯片时要滚动多远。 / p>

在PDF中,我可以使用CGPDFDocumentRef计算它,如下所示,但是我找不到相应的powerpoint API,因为它是一种微软格式,我怀疑它是否存在。

我可以使用javascript来确定整个演示文稿的宽度/高度,但这并不能帮助我知道单张幻灯片前进多远,

执行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

2 个答案:

答案 0 :(得分:3)

想出来。

在这种情况下,UIWebView就好像它是HTML页面上的iFrame,它有一些powerpoint文件的来源。因此,您可以对其进行某些操作,以及暴露的某些属性。

我发现document.all(一个数组)有元素 - 很多元素。我的20页powerpoint测试文件有300多个元素。看看它们的宽度/高度并没有太大的帮助 - 有些是iframe本身的尺寸,有些是从幻灯片1的左上角像素到幻灯片N的右下角像素的尺寸,有些是0x0,有些是(埋葬)在中间)是幻灯片的尺寸。我发现的模式是你必须跳过document.all中的第一个元素,然后迭代直到你找到一个宽度/高度非零的,其中clientHeight,offsetHeight,scrollHeight的值相同,以及相同的值clientWidth,offsetWidth和scrollWidth。这些中的第一个将为您提供单张幻灯片的高度/宽度,您可以从那里开始。当然,因为您使用的是UIWebView,并且只能使用stringByEvaluatingJavaScriptFromString,所以您需要在一行返回值的javascript中执行此操作。

因此,要提取powerpoint演示文稿的宽度/高度,您可以写:

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();"];

并根据此处的宽度/高度做任何你需要的事情。

哦,文档加载后没有立即填充document.all - UIWebView似乎需要几毫秒才能收集并使其可用。我在webview完成加载后运行了1秒,并且它在ppt和pptx文件上运行良好。但它不适用于pdf。

答案 1 :(得分:0)

其中,这些对象包含宽度和高度属性:

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

最适合你的似乎是最后一个。

1680 x 1050屏幕的结果

全屏PPT

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

PPT in ca.屏幕的1/2

 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