我目前正在工作的一个项目,我有ios需要显示一个pdf文件。但是,我希望选择要显示的页面。例如,请参阅UIWebView中37页中的第10页。我还没有找到一种方法来干净利落地分开一个pfd的页面。
谢谢你的帮助。
发布于 2013-10-03 08:48:59
您可以使用webview的setContentOffset属性来显示该页面,
[[webView scrollView] setContentOffset:CGPointMake(0,10*pageheight) animated:YES];在pageheight=your页面的高度,10是您的页面编号,
发布于 2015-02-19 08:34:28
使用UIWebView's delegate方法执行以下操作:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//Check if file still loading
if(!webView.isLoading)
{
//now traverse to specific page
[self performSelector:@selector(traverseInWebViewWithPage) withObject:nil afterDelay:0.1];
}
}现在添加下面的方法来遍历您的页面。备注需要有效的PDF文件路径,并提供您想要在PDF文件中遍历的有效的特定页面。
-(void)traverseInWebViewWithPage
{
//Get total pages in PDF File ----------- PDF File name here ---------------
NSString *strPDFFilePath = [[NSBundle mainBundle] pathForResource:@"yourPDFFileNameHere" ofType:@"pdf"];
NSInteger totalPDFPages = [self getTotalPDFPages:strPDFFilePath];
//Get total PDF pages height in webView
CGFloat totalPDFHeight = yourWebViewPDF.scrollView.contentSize.height;
NSLog ( @"total pdf height: %f", totalPDFHeight);
//Calculate page height of single PDF page in webView
NSInteger horizontalPaddingBetweenPages = 10*(totalPDFPages+1);
CGFloat pageHeight = (totalPDFHeight-horizontalPaddingBetweenPages)/(CGFloat)totalPDFPages;
NSLog ( @"pdf page height: %f", pageHeight);
//scroll to specific page --------------- here your page number -----------
NSInteger specificPageNo = 2;
if(specificPageNo <= totalPDFPages)
{
//calculate offset point in webView
CGPoint offsetPoint = CGPointMake(0, (10*(specificPageNo-1))+(pageHeight*(specificPageNo-1)));
//set offset in webView
[yourWebViewPDF.scrollView setContentOffset:offsetPoint];
}
}用于计算PDF总页数
-(NSInteger)getTotalPDFPages:(NSString *)strPDFFilePath
{
NSURL *pdfUrl = [NSURL fileURLWithPath:strPDFFilePath];
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
size_t pageCount = CGPDFDocumentGetNumberOfPages(document);
return pageCount;
}享受编码..。
https://stackoverflow.com/questions/19154484
复制相似问题