php 读取页面高度,获取页面高度,窗口高度,滚动条高度等参数值getPageSize,getPageScroll_javascript技巧...

function getPageScroll(){

var yScroll;

if (self.pageYOffset) {

yScroll = self.pageYOffset;

} else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict

yScroll = document.documentElement.scrollTop;

} else if (document.body) {// all other Explorers

yScroll = document.body.scrollTop;

}

arrayPageScroll = new Array('',yScroll)

return arrayPageScroll;

}

function getPageSize(){

var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {

xScroll = document.body.scrollWidth;

yScroll = window.innerHeight + window.scrollMaxY;

} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

xScroll = document.body.scrollWidth;

yScroll = document.body.scrollHeight;

} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

xScroll = document.body.offsetWidth;

yScroll = document.body.offsetHeight;

}

var windowWidth, windowHeight;

if (self.innerHeight) { // all except Explorer

windowWidth = self.innerWidth;

windowHeight = self.innerHeight;

} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

windowWidth = document.documentElement.clientWidth;

windowHeight = document.documentElement.clientHeight;

} else if (document.body) { // other Explorers

windowWidth = document.body.clientWidth;

windowHeight = document.body.clientHeight;

}

// for small pages with total height less then height of the viewport

if(yScroll < windowHeight){

pageHeight = windowHeight;

} else {

pageHeight = yScroll;

}

if(xScroll < windowWidth){

pageWidth = windowWidth;

} else {

pageWidth = xScroll;

}

arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)

return arrayPageSize;

}

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

iTextSharp是一个非常流行的Java库,用于处理PDF文件。在处理PDF文件时,你可能需要获取特定页面高度,或者判断是否需要在新的一页开始新的内容。以下是如何使用iTextSharp来获取剩余页面高度并判断是否需要新建页面的步骤: 首先,你需要引入iTextSharp库到你的项目中。如果你使用的是.NET环境,你可以通过NuGet包管理器来添加这个库。 然后,你可以使用以下代码来获取剩余页面高度并判断是否需要新建页面: ```csharp using iTextSharp.text; using iTextSharp.text.pdf; public bool IsPageBreakNeeded(string pdfFilePath) { using (FileStream stream = new FileStream(pdfFilePath, FileMode.Open, FileAccess.Read)) { PdfReader reader = new PdfReader(stream); int totalPages = reader.NumberOfPages; float totalHeight = reader.GetPageSize(1).Height; //获取第一页的高度 // 获取剩余页数 int remainingPages = totalPages - reader.GetPageCount(); float remainingHeight = remainingPages * reader.GetPageSize(0).Height; //假设每一页的高度都相同 // 如果剩余高度小于当前第一页的高度,那么就需要新建一页 if (remainingHeight < totalHeight) { return true; } else { return false; } } } ``` 这个函数首先打开PDF文件并读取所有的页面。然后,它计算出总页数和总高度。接下来,它计算出剩余的页数和剩余的高度。如果剩余的高度小于第一页的高度,那么就返回true,表示需要新建一页。否则,返回false。 请注意,这个函数假设每一页的高度都是相同的。如果你的PDF文件中的页面高度不同,你可能需要调整这个函数以适应你的需求。另外,这个函数没有处理PDF文件的错误,你可能需要在实际使用时添加适当的错误处理代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值