私は現在プロジェクトに取り組んでおり、ios で pdf ファイルを表示する必要があります。ただし、表示するページを選択したい。たとえば、UIWebView の 10/37 ページを参照してください。pfd のページをきれいに分離する方法が見つかりませんでした。
ご協力ありがとうございました。
私は現在プロジェクトに取り組んでおり、ios で pdf ファイルを表示する必要があります。ただし、表示するページを選択したい。たとえば、UIWebView の 10/37 ページを参照してください。pfd のページをきれいに分離する方法が見つかりませんでした。
ご協力ありがとうございました。
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;
}
コーディングを楽しむ.....
そのページを表示するには、webview のsetContentOffsetプロパティを使用でき ます。
[[webView scrollView] setContentOffset:CGPointMake(0,10*pageheight) animated:YES];
pageheight = ページの高さ、10 はページ番号、