Display and manipulate PDF documents in your applications using PDFKit.

Posts under PDFKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

Highlighter Annotation Large Frame
I am using PDFKit to draw annotation over PDF view. While performing multiple highlighter annotation most of the time long pressing on the highlighter annotation is getting proper frame but in one PDF when long pressing on the highlighter annotation is getting large frame and it is selecting all the nearest highlighter. This method is giving the wrong location and this is the default method of PDFKit. let tapPageLocation = pdfView.convert(location, to: page)
0
0
1.5k
Aug ’22
How to create and store the pdf file
I'm using CGContext.init(withUrl) to create a pdf context and doing some rendering inside that context. I was able to save the pdf in the location which will be available in the url. But in my case i will not have a location while creating the CGContext. So in my case i need a create a CGPDFContext without the location. I tried using the CGDataConsumer, but that also not working. My Requirements 1. Have to create PDF file without the save location. 2. In certain time interval i have to save that pdf to the particular location
3
0
3.8k
Aug ’22
Enable Live Text on PDFKit
Hi! I watched WWDC2022's 10089 session "What's New in PDFKit?" where it's said that Live Text is now compatible with PDFKit. However, I can't seem to find anything related to it in documentation or code. ImageAnalyzer needs an UIImage to work. But that would mean retrieve the current PDFPage and then convert it to UIImage which is a performance hog. How can I enable Live Text in PDFKit? thanks.
1
0
1.8k
Aug ’22
Multipage PDF with PDFKit on macOS with swift
Hello everybody, After weeks and months of searching for a solution (with interruptions) I finally have to ask the question: is there a tutorial to generate PDF with multiple pages from a macOS app with swift / swiftui? I am programming a macOS app and want (must) save and print letters and other documents as PDFs at the touch of a button. All the examples that I have been able to find so far are only for iOS and simply turning "UIGraphicsPDFRenderer" into "NSGraphicsPDFRenderer" is not possible. It can't be that no PDF can be created under macOS. It has to work somehow, doesn't it? Alternatively, it would be enough for me if you could print a view from SwiftUI. But that doesn't seem to work that easily, too. I would be very grateful for your help.
1
0
2k
Aug ’22
Error loading a file from Firebase
Hi all, I have been facing a problem while loading a file from the firebase storage. Basically in my code i have a data model which is the file/document (pdf in this case), a manager which goes into the database of Firebase to fetch the object and finally two views, one to list the files fetched and another one to show the document. I can fetch all the documents with their specific data, pass them to my view and then show the document pdf in another view. Everything seems correct but the problem comes when opening one of this docs. First, the doc doesn't open at first so you need to close the view and try to open the doc again. Then when i want to open another doc from my list, when i click on it the previous document is shown and not the correct one, so i need to do the same, close the view and click again on the doc to open the correct one. So at the end what i'm looking for is to open the doc just clicking once but i don't know where is my problem. List of docs: 1st time: 2nd time: 2nd doc but 1st time: 2nd doc and 2nd time clicking on it: Here is my code Model: struct DocumentoPdf {     let titulo: String     let docUrl: URL?     let id: String     let storageUrl: String } Manager which fetches the documents from firebase: final class DatabaseManager { [...]     public func getNovedades(completion: @escaping ([DocumentoPdf]) -> Void) {         database.collection("novedades").getDocuments { snapshot, error in             guard let documents = snapshot?.documents.compactMap ({ $0.data() }), error == nil else {                 return             }             let novedades: [DocumentoPdf] = documents.compactMap({ dictionary in                 guard let id = dictionary["id"] as? String,                       let titulo = dictionary["titulo"] as? String,                       let docUrlString = dictionary["docUrl"] as? String,                       let storageUrl = dictionary["storageUrl"] as? String else {                           return nil                       }                 let novedad = DocumentoPdf(titulo: titulo,                                            docUrl: URL(string: docUrlString),                                            id: id,                                            storageUrl: storageUrl)                 return novedad             })             completion(novedades)         }     } } First View: class NovedadesViewControllerViewModel {     let docUrl: URL?     var docData: Data?     init(docUrl: URL?) {         self.docUrl = docUrl     } } class NovedadesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, PDFViewDelegate {     private var tableView =  UITableView()    private var doc = PDFDocument()     public func configureDocPdf(with viewModel: NovedadesViewControllerViewModel) {         if let data = viewModel.docData {             doc = PDFDocument(data: data)!         }         else if let url = viewModel.docUrl {             // fetch doc & cache             let task = URLSession.shared.dataTask(with: url) { [weak self] data, _, _ in                 guard let data = data else {                     return                 }                 viewModel.docData = data                 DispatchQueue.main.async {                     self?.doc = PDFDocument(data: data)!                 }             }             task.resume()         }     }     private var novedades: [DocumentoPdf] = []     private func obtenerNovedades() {         DatabaseManager.shared.getNovedades() { [weak self] novedades in             self?.novedades = novedades             DispatchQueue.main.async {                 self?.tableView.reloadData()             }         }     }     override func viewDidLoad() { [...]         obtenerNovedades() [...]     } [... sections, rows in section...]     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         let novedad = novedades[indexPath.row]         let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)         cell.textLabel?.text = novedad.titulo         return cell     }     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         let novedad = novedades[indexPath.row]         switch indexPath.section {         case 0:             configureDocPdf(with: .init(docUrl: novedad.docUrl))             let lectorPdfView = LectorPdfViewController(doc: self.doc, nameDoc: novedad.titulo)             self.present(lectorPdfView, animated: true, completion: nil)         default:             break         }     } } Second View to load the pdf: class LectorPdfViewController: UIViewController, PDFViewDelegate {     private let navBar = UINavigationBar()     private let pdf = PDFView()     let nameDoc: String     let doc: PDFDocument     init(doc: PDFDocument, nameDoc: String) {         self.doc = doc         self.nameDoc = nameDoc         super.init(nibName: nil, bundle: nil)     }     required init?(coder: NSCoder) {         fatalError()     }     override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .systemBackground         view.addSubview(navBar)         view.addSubview(pdf)         pdf.document = self.doc         pdf.delegate = self         let item = UINavigationItem(title: self.nameDoc)         navBar.setItems([item], animated: false)         navBar.barTintColor = .systemBackground     }     override func viewDidLayoutSubviews() {         navBar.frame = CGRect(x: 0,                               y: 0,                               width: view.frame.size.width,                               height: 50)         pdf.frame = CGRect(x: 0,                            y: navBar.frame.height,                            width: view.frame.size.width,                            height: view.frame.size.height - navBar.frame.height)     } } Please if someone can help me with this will be fantastic. I hope you understood my code and my problem. Sorry for my bad english Thank you so much in advance
4
1
1.9k
Aug ’22
PDFKit Link Annotations gets stripped off when saving
I'm using the following code to draw a text over PDF page.Everything works fine, but if you process a PDF with internal links eg: a Book with Content links to pages, the resultant PDF file seems to have the links stripped off.Why does this happen? let data = NSMutableData() let consumer = CGDataConsumer(data: data as CFMutableData)! let context = CGContext(consumer: consumer, mediaBox: nil, nil)! let pdffile=PDFDocument(url: input) for y in stride(from: 0, to: pagecount, by: 1) { let page: PDFPage = pdffile!.page(at: y)! var mediaBox = page.bounds(for: PDFDisplayBox.mediaBox) NSGraphicsContext.current = NSGraphicsContext(cgContext: context, flipped: false) let bounds = page.bounds(for: PDFDisplayBox.mediaBox) let size = bounds.size page.draw(with: .mediaBox, to: context) text.draw(in:drawrect,withAttributes:textFontAttributes); context.endPDFPage() } context.closePDF() try! data!.write(to: GetOutputFileName(inputfile: x), options[.atomicWrite]) What I have tried is saving the annotation of each page applying it before ending the page for annotation in pageannottaions                 {                     page.addAnnotation(annotation)                 } This also does not work.Please advice
0
0
716
Aug ’22
Export MacOS SwiftUI form to pdf
I am building a MacOS dedicated app where I want to build a document template using a form. Inside the form there are multiple data types: text, pickers, images, links to other pdfs and signatures. I want to be able to export the data in the form to pdf, retaining the formatting of the form. I have searched high and low for some sort of solution, where PDFKit and Quartz seem to come up but no viable solution. This really should not be a complex process... And I do not want to use storyboard but only use SwiftUI.
1
0
762
Aug ’22
Upside down drawings on iOS 16 preview
We are currently testing our mobile application on the iOS 16 preview. Our application allows you to draw and sign using the UIKit/PDFKit which results in an image that we store. When the image is opened it is displayed upside down. Is this an expected change caused by the new OS or is this a bug that will be fixed when the stable version is released? Is there any guide/advice on this if this is an expected change?
2
0
1k
Jul ’22
PDFKit & WebKit problem with JPEG2000 in PDF
We have some PDFs that were created with JPEG2000 images in them (*.jp2 files). Using PDFKit, and also WebKit, the images in these PDFs in some cases don't display at all, and in others cases appear badly warped. You can view the PDF using either Adobe Reader, or the Chrome app, and the images appear fine, so it's clearly not an issue of a corrupt PDF. Also, 3rd-party commercial iOS controls like PSPDF and FoxIt display the images fine, so it's clearly an issue with PDFKit and WebKit. Any known workarounds?
1
0
1.4k
Jul ’22
Export SwiftUI View
I know this is a strange and easy question. but JUST CANT FIND ANY REFERENCE aaaaaaaa I'm using SwiftUI and wants to export to PDF (best I can find Creating PDFs on MacOS without UIKit) export to image export to HTML export to everything possible etc BONUS print the page I can only find UIKit support and they are all outdated. AND IF POSSIBLE how to integrate ShareLink to share these(PDF, Image, HTML, etc) and write them onto disk using NSSavePane? even better how to do this on a of the platforms (I know I'm greedy😂) Thanks for any help🙏
0
0
895
Jun ’22
How I can show/display pdf document to full screen on pdfView?
I took pdfView, and I am trying to load pdf document on this pdfView. Pdf is not displaying/showing full screen w.r.t its pdfView as I added in storyboard. It has some gaps from top and bottom. Here is the code, I wrote swift if let path = Bundle.main.path(forResource: "file-sample_150kB", ofType: "pdf") {             if let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) {                                  pdfView.autoresizesSubviews = true                 pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin]                 pdfView.displayDirection = .vertical                 pdfView.autoScales = true                 pdfView.displayMode =  .singlePage                 pdfView.displaysPageBreaks = true                 pdfView.document = pdfDocument                 pdfView.maxScaleFactor = 4.0                 pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit                 pdfView.usePageViewController(true, withViewOptions: [:])             }         } How I can remove that extra space from top and bottom and make/show/display that pdf document to full to screen w.r.t pdfView which I added in storyboard that same size. Any solution for this? Note - In my code/requirement displaying single page is needed i.e pdfView.displayMode =  .singlePage Here is project link - [https://github.com/MallikarjunH/TestPDFFullScreen1)
2
0
3.6k
Jun ’22
Page number of PDF in SwiftUI
I create a UIViewRepresentable to show my PDF inside my SwiftUI app. I want to access the current page number using currentPage?.pageRef?.pageNumber. from the view in which I display the pdf. How to make PDFView Created in func makeUIView(context: UIViewRepresentableContext<PDFDisplayRepresentedView>) -> PDFView Available in the view displaying the pdf so I can access its properties to obtain page number. import SwiftUI import PDFKit struct PDFDisplayView: View { @Binding var pdfDocument : PDFDocument? var body: some View { PDFDisplayRepresentedView(pdfDocument: pdfDocument!) } } struct PDFDisplayRepresentedView: UIViewRepresentable { let pdfDocument: PDFDocument init(pdfDocument: PDFDocument) { self.pdfDocument = pdfDocument } func makeUIView(context: UIViewRepresentableContext<PDFDisplayRepresentedView>) -> PDFView { return createPDFViewUsing(document: pdfDocument) } func updateUIView(_ pdfView: PDFView, context: UIViewRepresentableContext<PDFDisplayRepresentedView>) { pdfView.document = pdfDocument } private func createPDFViewUsing(document : PDFDocument) -> PDFView { let pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) pdfView.document = document ... set up pdfView attributes return pdfView } } view showing pdf where I want to know the page number pseudo code … @State private var pdfDisplayView : PDFDisplayView? …. var body: some View { load the pdf into this view. need to access the page number pdfDisplayView }
0
0
1.6k
May ’22
Printing dialog in lower left corner with PDFVIew.print()
Good afternoon (o; Doing a simple SwiftUI app where it fetches a PDF barcode from a web service to be printed on a thermal label printer. So I use this snippet to fetch the PDF and launch the printing dialog:         let pdfView = PDFView()         pdfView.document = PDFDocument(url: self.url!)         let wnd = NSWindow()         pdfView.autoScales = true         pdfView.displaysPageBreaks = false         wnd.setContentSize(pdfView.frame.size)         wnd.contentView = pdfView         pdfView.print(with: printInfo, autoRotate: false) But the printing dialog appears on the lower left corner of the screen...and when choosing "details" the dialog extends to the offscreen area.... Also no paper size is choosable. thanks in advance richard
0
0
1.1k
May ’22
iOS 15:- PDFKit Unlock feature not working
Hi, We need to develop a functionality where we need to lock and unlock Pdf. For this, We need to use inbuilt methods provided by the PDFKit framework. With that locking and unlocking features are working perfectly before updating to iOS 15. But when I upgrade to iOS 15 locking feature works very well but unlocking is not working. I have used the below method for unlocking PDF, unlock(withPassword:) func unlock(withPassword password: String) -> Bool https://developer.apple.com/documentation/pdfkit/pdfdocument/1436033-unlock been searching for this everywhere and can't find anything around this, I believe is a bug, maybe is not.
1
0
1k
May ’22
PDF checkbox on preview and ios devices does not show and cannot be edited
https://pdftron.s3.amazonaws.com/custom/test/jack/blank+(34).pdf Here is the pdf. You could download it. In the PDF, there is a checkbox. When we open the PDF in Acrobat and Chrome, it can be edited. However, when we open it in Mac Preview and IOS devices. The checkbox is hidden and cannot be edited anymore. It could be a bug from Preview and IOS PDF editor
0
0
677
Apr ’22
Request a new PDFView layout in PDFKit
Feature request: a new PDFView layout in PDFKit This feature request is from the Skim.app Sourceforge page https://sourceforge.net/p/skim-app/feature-requests/1640/ orignial feature request It would be nice if we can have a PDF Display option "Single-page Two-column Continuous" which I would explain below. I imagine we can have a layout like the "Two Pages Continuous", but the right-hand-side page is the same page as the left-hand-side page, continued from the bottom. Like this:   |  /| | / | |/ ↓ L  R This will be extremely helpful for short displays, as it take full advantage of the width of the display while still gives rather large fonts. response from the Skim team The page layout is implemented by Apple's PDFKit. If you want to have support for it, you should first ask Apple to provide it. My problem I have no idea how to ask Apple to provide it. If the provider of PDFKit can see this, that would be great. Or if anyone know what should I do to ask for this feature, please help. I suppose this can benefit more as it would not only be implemented in Skim.app but probably also Preview.app
0
0
529
Mar ’22
Highlighter Annotation Large Frame
I am using PDFKit to draw annotation over PDF view. While performing multiple highlighter annotation most of the time long pressing on the highlighter annotation is getting proper frame but in one PDF when long pressing on the highlighter annotation is getting large frame and it is selecting all the nearest highlighter. This method is giving the wrong location and this is the default method of PDFKit. let tapPageLocation = pdfView.convert(location, to: page)
Replies
0
Boosts
0
Views
1.5k
Activity
Aug ’22
How to create and store the pdf file
I'm using CGContext.init(withUrl) to create a pdf context and doing some rendering inside that context. I was able to save the pdf in the location which will be available in the url. But in my case i will not have a location while creating the CGContext. So in my case i need a create a CGPDFContext without the location. I tried using the CGDataConsumer, but that also not working. My Requirements 1. Have to create PDF file without the save location. 2. In certain time interval i have to save that pdf to the particular location
Replies
3
Boosts
0
Views
3.8k
Activity
Aug ’22
Enable Live Text on PDFKit
Hi! I watched WWDC2022's 10089 session "What's New in PDFKit?" where it's said that Live Text is now compatible with PDFKit. However, I can't seem to find anything related to it in documentation or code. ImageAnalyzer needs an UIImage to work. But that would mean retrieve the current PDFPage and then convert it to UIImage which is a performance hog. How can I enable Live Text in PDFKit? thanks.
Replies
1
Boosts
0
Views
1.8k
Activity
Aug ’22
Multipage PDF with PDFKit on macOS with swift
Hello everybody, After weeks and months of searching for a solution (with interruptions) I finally have to ask the question: is there a tutorial to generate PDF with multiple pages from a macOS app with swift / swiftui? I am programming a macOS app and want (must) save and print letters and other documents as PDFs at the touch of a button. All the examples that I have been able to find so far are only for iOS and simply turning "UIGraphicsPDFRenderer" into "NSGraphicsPDFRenderer" is not possible. It can't be that no PDF can be created under macOS. It has to work somehow, doesn't it? Alternatively, it would be enough for me if you could print a view from SwiftUI. But that doesn't seem to work that easily, too. I would be very grateful for your help.
Replies
1
Boosts
0
Views
2k
Activity
Aug ’22
Error loading a file from Firebase
Hi all, I have been facing a problem while loading a file from the firebase storage. Basically in my code i have a data model which is the file/document (pdf in this case), a manager which goes into the database of Firebase to fetch the object and finally two views, one to list the files fetched and another one to show the document. I can fetch all the documents with their specific data, pass them to my view and then show the document pdf in another view. Everything seems correct but the problem comes when opening one of this docs. First, the doc doesn't open at first so you need to close the view and try to open the doc again. Then when i want to open another doc from my list, when i click on it the previous document is shown and not the correct one, so i need to do the same, close the view and click again on the doc to open the correct one. So at the end what i'm looking for is to open the doc just clicking once but i don't know where is my problem. List of docs: 1st time: 2nd time: 2nd doc but 1st time: 2nd doc and 2nd time clicking on it: Here is my code Model: struct DocumentoPdf {     let titulo: String     let docUrl: URL?     let id: String     let storageUrl: String } Manager which fetches the documents from firebase: final class DatabaseManager { [...]     public func getNovedades(completion: @escaping ([DocumentoPdf]) -> Void) {         database.collection("novedades").getDocuments { snapshot, error in             guard let documents = snapshot?.documents.compactMap ({ $0.data() }), error == nil else {                 return             }             let novedades: [DocumentoPdf] = documents.compactMap({ dictionary in                 guard let id = dictionary["id"] as? String,                       let titulo = dictionary["titulo"] as? String,                       let docUrlString = dictionary["docUrl"] as? String,                       let storageUrl = dictionary["storageUrl"] as? String else {                           return nil                       }                 let novedad = DocumentoPdf(titulo: titulo,                                            docUrl: URL(string: docUrlString),                                            id: id,                                            storageUrl: storageUrl)                 return novedad             })             completion(novedades)         }     } } First View: class NovedadesViewControllerViewModel {     let docUrl: URL?     var docData: Data?     init(docUrl: URL?) {         self.docUrl = docUrl     } } class NovedadesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, PDFViewDelegate {     private var tableView =  UITableView()    private var doc = PDFDocument()     public func configureDocPdf(with viewModel: NovedadesViewControllerViewModel) {         if let data = viewModel.docData {             doc = PDFDocument(data: data)!         }         else if let url = viewModel.docUrl {             // fetch doc & cache             let task = URLSession.shared.dataTask(with: url) { [weak self] data, _, _ in                 guard let data = data else {                     return                 }                 viewModel.docData = data                 DispatchQueue.main.async {                     self?.doc = PDFDocument(data: data)!                 }             }             task.resume()         }     }     private var novedades: [DocumentoPdf] = []     private func obtenerNovedades() {         DatabaseManager.shared.getNovedades() { [weak self] novedades in             self?.novedades = novedades             DispatchQueue.main.async {                 self?.tableView.reloadData()             }         }     }     override func viewDidLoad() { [...]         obtenerNovedades() [...]     } [... sections, rows in section...]     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         let novedad = novedades[indexPath.row]         let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)         cell.textLabel?.text = novedad.titulo         return cell     }     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         let novedad = novedades[indexPath.row]         switch indexPath.section {         case 0:             configureDocPdf(with: .init(docUrl: novedad.docUrl))             let lectorPdfView = LectorPdfViewController(doc: self.doc, nameDoc: novedad.titulo)             self.present(lectorPdfView, animated: true, completion: nil)         default:             break         }     } } Second View to load the pdf: class LectorPdfViewController: UIViewController, PDFViewDelegate {     private let navBar = UINavigationBar()     private let pdf = PDFView()     let nameDoc: String     let doc: PDFDocument     init(doc: PDFDocument, nameDoc: String) {         self.doc = doc         self.nameDoc = nameDoc         super.init(nibName: nil, bundle: nil)     }     required init?(coder: NSCoder) {         fatalError()     }     override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .systemBackground         view.addSubview(navBar)         view.addSubview(pdf)         pdf.document = self.doc         pdf.delegate = self         let item = UINavigationItem(title: self.nameDoc)         navBar.setItems([item], animated: false)         navBar.barTintColor = .systemBackground     }     override func viewDidLayoutSubviews() {         navBar.frame = CGRect(x: 0,                               y: 0,                               width: view.frame.size.width,                               height: 50)         pdf.frame = CGRect(x: 0,                            y: navBar.frame.height,                            width: view.frame.size.width,                            height: view.frame.size.height - navBar.frame.height)     } } Please if someone can help me with this will be fantastic. I hope you understood my code and my problem. Sorry for my bad english Thank you so much in advance
Replies
4
Boosts
1
Views
1.9k
Activity
Aug ’22
PDFKit Link Annotations gets stripped off when saving
I'm using the following code to draw a text over PDF page.Everything works fine, but if you process a PDF with internal links eg: a Book with Content links to pages, the resultant PDF file seems to have the links stripped off.Why does this happen? let data = NSMutableData() let consumer = CGDataConsumer(data: data as CFMutableData)! let context = CGContext(consumer: consumer, mediaBox: nil, nil)! let pdffile=PDFDocument(url: input) for y in stride(from: 0, to: pagecount, by: 1) { let page: PDFPage = pdffile!.page(at: y)! var mediaBox = page.bounds(for: PDFDisplayBox.mediaBox) NSGraphicsContext.current = NSGraphicsContext(cgContext: context, flipped: false) let bounds = page.bounds(for: PDFDisplayBox.mediaBox) let size = bounds.size page.draw(with: .mediaBox, to: context) text.draw(in:drawrect,withAttributes:textFontAttributes); context.endPDFPage() } context.closePDF() try! data!.write(to: GetOutputFileName(inputfile: x), options[.atomicWrite]) What I have tried is saving the annotation of each page applying it before ending the page for annotation in pageannottaions                 {                     page.addAnnotation(annotation)                 } This also does not work.Please advice
Replies
0
Boosts
0
Views
716
Activity
Aug ’22
Export MacOS SwiftUI form to pdf
I am building a MacOS dedicated app where I want to build a document template using a form. Inside the form there are multiple data types: text, pickers, images, links to other pdfs and signatures. I want to be able to export the data in the form to pdf, retaining the formatting of the form. I have searched high and low for some sort of solution, where PDFKit and Quartz seem to come up but no viable solution. This really should not be a complex process... And I do not want to use storyboard but only use SwiftUI.
Replies
1
Boosts
0
Views
762
Activity
Aug ’22
Upside down drawings on iOS 16 preview
We are currently testing our mobile application on the iOS 16 preview. Our application allows you to draw and sign using the UIKit/PDFKit which results in an image that we store. When the image is opened it is displayed upside down. Is this an expected change caused by the new OS or is this a bug that will be fixed when the stable version is released? Is there any guide/advice on this if this is an expected change?
Replies
2
Boosts
0
Views
1k
Activity
Jul ’22
PDFKit & WebKit problem with JPEG2000 in PDF
We have some PDFs that were created with JPEG2000 images in them (*.jp2 files). Using PDFKit, and also WebKit, the images in these PDFs in some cases don't display at all, and in others cases appear badly warped. You can view the PDF using either Adobe Reader, or the Chrome app, and the images appear fine, so it's clearly not an issue of a corrupt PDF. Also, 3rd-party commercial iOS controls like PSPDF and FoxIt display the images fine, so it's clearly an issue with PDFKit and WebKit. Any known workarounds?
Replies
1
Boosts
0
Views
1.4k
Activity
Jul ’22
Export SwiftUI View
I know this is a strange and easy question. but JUST CANT FIND ANY REFERENCE aaaaaaaa I'm using SwiftUI and wants to export to PDF (best I can find Creating PDFs on MacOS without UIKit) export to image export to HTML export to everything possible etc BONUS print the page I can only find UIKit support and they are all outdated. AND IF POSSIBLE how to integrate ShareLink to share these(PDF, Image, HTML, etc) and write them onto disk using NSSavePane? even better how to do this on a of the platforms (I know I'm greedy😂) Thanks for any help🙏
Replies
0
Boosts
0
Views
895
Activity
Jun ’22
Errors in sample code
There are some errors when attempting to run the sample code: Cannot convert value of type 'String' to expected argument type 'PDFAnnotationSubtype' I understand the error but I'm unsure what it's looking for. I'm running Xcode 14, targeting iOS 12 Thx for any feedback!
Replies
4
Boosts
0
Views
1.1k
Activity
Jun ’22
How I can show/display pdf document to full screen on pdfView?
I took pdfView, and I am trying to load pdf document on this pdfView. Pdf is not displaying/showing full screen w.r.t its pdfView as I added in storyboard. It has some gaps from top and bottom. Here is the code, I wrote swift if let path = Bundle.main.path(forResource: "file-sample_150kB", ofType: "pdf") {             if let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) {                                  pdfView.autoresizesSubviews = true                 pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin]                 pdfView.displayDirection = .vertical                 pdfView.autoScales = true                 pdfView.displayMode =  .singlePage                 pdfView.displaysPageBreaks = true                 pdfView.document = pdfDocument                 pdfView.maxScaleFactor = 4.0                 pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit                 pdfView.usePageViewController(true, withViewOptions: [:])             }         } How I can remove that extra space from top and bottom and make/show/display that pdf document to full to screen w.r.t pdfView which I added in storyboard that same size. Any solution for this? Note - In my code/requirement displaying single page is needed i.e pdfView.displayMode =  .singlePage Here is project link - [https://github.com/MallikarjunH/TestPDFFullScreen1)
Replies
2
Boosts
0
Views
3.6k
Activity
Jun ’22
Page number of PDF in SwiftUI
I create a UIViewRepresentable to show my PDF inside my SwiftUI app. I want to access the current page number using currentPage?.pageRef?.pageNumber. from the view in which I display the pdf. How to make PDFView Created in func makeUIView(context: UIViewRepresentableContext<PDFDisplayRepresentedView>) -> PDFView Available in the view displaying the pdf so I can access its properties to obtain page number. import SwiftUI import PDFKit struct PDFDisplayView: View { @Binding var pdfDocument : PDFDocument? var body: some View { PDFDisplayRepresentedView(pdfDocument: pdfDocument!) } } struct PDFDisplayRepresentedView: UIViewRepresentable { let pdfDocument: PDFDocument init(pdfDocument: PDFDocument) { self.pdfDocument = pdfDocument } func makeUIView(context: UIViewRepresentableContext<PDFDisplayRepresentedView>) -> PDFView { return createPDFViewUsing(document: pdfDocument) } func updateUIView(_ pdfView: PDFView, context: UIViewRepresentableContext<PDFDisplayRepresentedView>) { pdfView.document = pdfDocument } private func createPDFViewUsing(document : PDFDocument) -> PDFView { let pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) pdfView.document = document ... set up pdfView attributes return pdfView } } view showing pdf where I want to know the page number pseudo code … @State private var pdfDisplayView : PDFDisplayView? …. var body: some View { load the pdf into this view. need to access the page number pdfDisplayView }
Replies
0
Boosts
0
Views
1.6k
Activity
May ’22
Printing dialog in lower left corner with PDFVIew.print()
Good afternoon (o; Doing a simple SwiftUI app where it fetches a PDF barcode from a web service to be printed on a thermal label printer. So I use this snippet to fetch the PDF and launch the printing dialog:         let pdfView = PDFView()         pdfView.document = PDFDocument(url: self.url!)         let wnd = NSWindow()         pdfView.autoScales = true         pdfView.displaysPageBreaks = false         wnd.setContentSize(pdfView.frame.size)         wnd.contentView = pdfView         pdfView.print(with: printInfo, autoRotate: false) But the printing dialog appears on the lower left corner of the screen...and when choosing "details" the dialog extends to the offscreen area.... Also no paper size is choosable. thanks in advance richard
Replies
0
Boosts
0
Views
1.1k
Activity
May ’22
iOS 15:- PDFKit Unlock feature not working
Hi, We need to develop a functionality where we need to lock and unlock Pdf. For this, We need to use inbuilt methods provided by the PDFKit framework. With that locking and unlocking features are working perfectly before updating to iOS 15. But when I upgrade to iOS 15 locking feature works very well but unlocking is not working. I have used the below method for unlocking PDF, unlock(withPassword:) func unlock(withPassword password: String) -> Bool https://developer.apple.com/documentation/pdfkit/pdfdocument/1436033-unlock been searching for this everywhere and can't find anything around this, I believe is a bug, maybe is not.
Replies
1
Boosts
0
Views
1k
Activity
May ’22
PDF checkbox on preview and ios devices does not show and cannot be edited
https://pdftron.s3.amazonaws.com/custom/test/jack/blank+(34).pdf Here is the pdf. You could download it. In the PDF, there is a checkbox. When we open the PDF in Acrobat and Chrome, it can be edited. However, when we open it in Mac Preview and IOS devices. The checkbox is hidden and cannot be edited anymore. It could be a bug from Preview and IOS PDF editor
Replies
0
Boosts
0
Views
677
Activity
Apr ’22
Request a new PDFView layout in PDFKit
Feature request: a new PDFView layout in PDFKit This feature request is from the Skim.app Sourceforge page https://sourceforge.net/p/skim-app/feature-requests/1640/ orignial feature request It would be nice if we can have a PDF Display option "Single-page Two-column Continuous" which I would explain below. I imagine we can have a layout like the "Two Pages Continuous", but the right-hand-side page is the same page as the left-hand-side page, continued from the bottom. Like this:   |  /| | / | |/ ↓ L  R This will be extremely helpful for short displays, as it take full advantage of the width of the display while still gives rather large fonts. response from the Skim team The page layout is implemented by Apple's PDFKit. If you want to have support for it, you should first ask Apple to provide it. My problem I have no idea how to ask Apple to provide it. If the provider of PDFKit can see this, that would be great. Or if anyone know what should I do to ask for this feature, please help. I suppose this can benefit more as it would not only be implemented in Skim.app but probably also Preview.app
Replies
0
Boosts
0
Views
529
Activity
Mar ’22