[iOS] เปิดอ่าน PDF ด้วย Swift

Swift สามารถเขียนให้เปิด PDF โดยเลือกใช้ component WebView วาดลงใน storyboard และจัดการ layout ให้เรียบร้อย ตามรูปแบบการแสดงผลที่ต้องการ (จากตัวอย่างลองวาดเต็มจอ)
เขียนโปรแกรมเรียก *.pdf มาแสดงบน WebView

// Get the document's file path.
let path = NSBundle.mainBundle().pathForResource("sample.pdf", ofType: nil)
        
// Create an NSURL object based on the file path.
let url = NSURL.fileURLWithPath(path!)
        
// Create an NSURLRequest object.
let request = NSURLRequest(URL: url)
        
// Load the web viewer using the request object.
webView.loadRequest(request)

ซึ่งสามารถแสดงผลดังรูป

Facebook Comment

Recent Posts

Popular post of 7 days

Portal คืออะไรกันนะ???

[Java] ความแตกต่างระหว่าง Overloading กับ Overriding

Port Forwarding สำหรับคนใช้ AIS Fibre

Popular

Portal คืออะไรกันนะ???

[Java] ความแตกต่างระหว่าง Overloading กับ Overriding

มาตรฐานการตั้งชื่อตัวแปร (Naming Convention)

เรื่องของ ++i กับ i++

Port Forwarding สำหรับคนใช้ AIS Fibre

วิธีการสมัคร Apple Developer Program และ Enterprise Program ฉบับลงมือเอง

ลืมรหัสปลดล็อค Android เข้าเครื่องไม่ได้ มีทางออกครับ

ทดสอบ Mobile App แบบ Automated ด้วย Appium ทำยังไงกันนะ

Deeplink, Universal Links คืออะไร ทำงานร่วมกับ Mobile App ได้ยังไง

Android Auto & Apple Carplay คืออะไร ใช้งานยังไง