#import "WebViewController.h"
#import <WebKit/WebKit.h>
 
@interface WebViewController ()
 
@end
 
@implementation WebViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 번들에 있는 pdf 파일 가져오기
    NSString *path = [[NSBundle mainBundle] pathForResource:@"SampleTest" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:webView];
    
    // NSURLRequest 만든후 WKWebView 로 로드
    // 인터넷에 있는 PDF 파일도 동일하게 NSURLRequest 객체 생성 후 웹요청하여 사용
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}
 
@end
cs

 

 

결과

'IT > Ⅰ. IOS' 카테고리의 다른 글

[IOS] GIF, SVG, APNG 이미지 사용  (0) 2025.05.22
[IOS] 이미지로 프로그레스바 만들기  (0) 2025.05.17
[IOS] PDF 문서 보기 - PDFKit 사용  (0) 2025.05.10
#import "PdfViewController.h"
#import <PDFKit/PDFKit.h>
 
@interface PdfViewController ()
 
@end
 
@implementation PdfViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 번들에 있는 pdf 파일 가져오기
    NSString *path = [[NSBundle mainBundle] pathForResource:@"SampleTest" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:path];
 
    // PDF문서
    PDFDocument *document = [[PDFDocument alloc] initWithURL:url];
    // PDF뷰
    PDFView *pdfView = [[PDFView alloc] initWithFrame:self.view.bounds];
    // PDF문서를 PDF뷰 크기에 맞게 자동 확대/축소
    pdfView.autoScales = YES;
    // PDF문서와 PDF뷰 연결
    pdfView.document = document;
 
    // 뷰 전체 화면에 추가
    pdfView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:pdfView];
}
 
@end
cs

 

 

결과

'IT > Ⅰ. IOS' 카테고리의 다른 글

[IOS] GIF, SVG, APNG 이미지 사용  (0) 2025.05.22
[IOS] 이미지로 프로그레스바 만들기  (0) 2025.05.17
[IOS] PDF 문서 보기 - WKWebView 사용  (0) 2025.05.11
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
 
</LinearLayout>
cs

 

 

public class PdfViewerActivity extends AppCompatActivity {
 
    PDFView mPDFView;
 
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdfviewer);
 
        mPDFView = findViewById(R.id.pdfView);
        // assets 폴더에 있는 pdf 파일읽기
        mPDFView.fromAsset("SampleTest.pdf")
                .enableSwipe(true)      // 스와이프로 페이지 넘김
                .swipeHorizontal(false// true-가로로 넘김, false-세로로 넘김
                .enableDoubletap(true)  // 화면을 두번 탭하여 확대/축소
                .load();
 
    }
}
cs

 - assets폴더에 SampleTest.pdf 파일을 포함시키고 로드

 

 

implementation ("com.github.mhiew:android-pdf-viewer:3.2.0-beta.3")
 
cs

 

 

결과

 

+ Recent posts