iPad上可以计算PowerPoint演示文稿的宽度/高度吗

发布于 2024-12-01 16:27:15 字数 775 浏览 2 评论 0原文

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

在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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哥,最终变帅啦 2024-12-08 16:27:15

想通了。

在这种情况下,UIWebView 的行为就好像它是 HTML 页面上的 iFrame,其中包含某个 powerpoint 文件的源。因此,您可以对其执行某些操作,并公开某些属性。

我发现 document.all (一个数组)有元素 - 很多元素。我的 20 页 powerpoint 测试文件有 300 多个元素。查看它们的宽度/高度并没有太大帮助 - 有些是 iframe 本身的尺寸,有些是从幻灯片 1 的左上角像素到幻灯片 N 的右下角像素的尺寸,有些是 0x0,有些是(隐藏的)中间)是幻灯片的尺寸。我发现的模式是,您必须跳过 document.all 中的第一个元素,然后进行迭代,直到找到一个具有非零宽度/高度的元素,这些元素具有相同的 clientHeight、offsetHeight、scrollHeight 值以及相同的值客户端宽度、偏移宽度和滚动宽度。其中第一个将为您提供单张幻灯片的高度/宽度,您可以从那里开始。当然,因为您使用的是 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。

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.

-残月青衣踏尘吟 2024-12-08 16:27:15

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

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

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

PPT 中的结果

1680 x 1050 屏幕PPT 在全屏

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

大约 为 1680 x 1050 屏幕 PPT。屏幕的 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文