Display and manipulate PDF documents in your applications using PDFKit.

Posts under PDFKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

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.5k
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
659
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
516
Mar ’22
SwiftUI View to PDF margin question
Hi, I am trying to export the following SwiftUI View to PDF using UIGraphicsPDFRenderer. The problem I am getting is there is somehow a margin on top of the exported PDF. The code I am using import SwiftUI struct ContentView: View {     var body: some View {         let pressGesture = TapGesture()                .onEnded { value in                    let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!                    let outputFileURL = documentDirectory.appendingPathComponent("SwiftUI.pdf")                    let pdfVC = UIHostingController(rootView: self)                    let pageSize = CGSize(width: 2.625 * 72.0, height: 1.0 * 72.0)                    pdfVC.view.frame = CGRect(origin: .zero, size: pageSize)                    let rootVC = UIApplication.shared.windows.first?.rootViewController                    rootVC?.addChild(pdfVC)                    rootVC?.view.insertSubview(pdfVC.view, at: 0)                    let pdfRenderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: pageSize.width, height: pageSize.height))                    DispatchQueue.main.async {                         do {                                                                                 try pdfRenderer.writePDF(to: outputFileURL, withActions: { (context) in                                 context.beginPage()                                 pdfVC.view.layer.render(in: context.cgContext)                             })                             print("wrote file to: (outputFileURL.path)")                             pdfVC.removeFromParent()                             pdfVC.view.removeFromSuperview()                                              } catch {                             print("Could not create PDF file: (error.localizedDescription)")                         }                     }                                }         VStack(){                 Text("Hello")         }         .frame(width: 2.625 * 72.0, height: 1.0 * 72.0, alignment: .center)         .gesture(pressGesture)         .background(Color.red)     } } May I know what am I doing wrong? Thanks in advance.
0
0
1.1k
Mar ’22
CGPDFDocument and PDFDocument fail
I have a bunch of PDF files that I try to open either with CGPDFDocument or PDFDocument (PDFKit) and the init return NULL. Where can I get some feedback why this is happening? I cannot find anything on Console (for connected iOS device) or the Xcode Debug Output window. Let me say that this is not true for all PDF files, some open and some do not. It is also not a problem with permissions, the files are accessible by the app.
0
0
981
Mar ’22
How to make pdfView zoom=100% to fit screen size
So I have this pdfView and I wanna make it so its first display is a zoom of 100% of the page, but the problem is that what I have now is zooming in to much and the UI is not pretty to be like that. It just like zooms to much and I want it to be perfectly zoomed to fit the screen size. I have tried and can't find a solution. My code is this: &#9;&#9;pdfView.translatesAutoresizingMaskIntoConstraints = false &#9;&#9;pdfView.autoScales = true &#9;&#9;pdfView.maxScaleFactor = 4.0 &#9;&#9;pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit &#9;&#9;view.addSubview(pdfView) &#9;&#9;pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true &#9;&#9;pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true &#9;&#9;pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true &#9;&#9;pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true &#9;&#9; &#9;&#9; &#9;&#9;guard let path = Bundle.main.url(forResource: materia , withExtension: "pdf") else { return } &#9;&#9;if let document = PDFDocument(url: path) { &#9;&#9;&#9;&#9;pdfView.document = document &#9;&#9;}
1
2
4.5k
Mar ’22
pdfPage.draw ios15 strange results
when calling PDFPage.draw the first page of the pdf prints by repeating the first word over and over. Only in iOS15 all other iOS versions print the page normally. Resaving the document in acrobat with 'optimized' on fixes the issue. However, we can't guarantee our users will do that before uploading a pdf in our system.
5
0
1.3k
Feb ’22
Creating PDFs on MacOS without UIKit
Greetings, this may be an odd question but I was not able to find an answer to this. So I am developing this pure MacOS program for a client and one thing he wants is to create some PDFs along the way. Great chance I thought to try out this fancy Swift 5 with SwiftUI and so far it's going great, most of the program is up and running but I've hit a wall with the PDF generation, which I thought would be one of the easiest parts. Since it's a pure MacOS program, UIKit is not available but there is not a single tutorial out there for generating PDFs which is not using UIKit to do it. It seems people only want to create PDFs on iOS. Can someone give me a small breakdown or starter or tutorial or skeleton on how I would do that? Thanks and have a nice day
4
0
2k
Jan ’22
PDFPage thumbnail (UIImage) does not respect PDFPage orientation in iOS 13 (Xcode 13.1)
Description I am having issue with UIImage "generated" from PDFPage via method .thumbnail(of:for). UIImage, which I later display in UIImageView does not respect rotation of the PDF page, but for iOS 13 only. When PDF page is rotated for example by 90° and presented in PDFView all is good and shown correctly. But when I want to take the UIImage (i.e. thumbnail) of the PDFPage and show it in UIImageView, for some reason, iOS 13 does not respect the initial rotation of the PDF page and present it in UIImageView incorrectly. Please behold on below sample code and example screenshots. Testing environment iOS 13 on simulator only, not having real device Xcode 13.1 Sample code for sake of shorter example, I force unwrap where optionals occur import UIKit import PDFKit class TestingViewController: UIViewController { lazy var imageView: UIImageView = { let iv = UIImageView() iv.translatesAutoresizingMaskIntoConstraints = false return iv }() // Pass URL of the PDF document when instantiating this VC init(withURL: URL) { super.init(nibName: nil, bundle: nil) let pdfDoc = PDFDocument(url: withURL) let pdfPage = pdfDoc!.page(at: 0) // Getting first page of the doc let pdfPageRect = pdfPage!.bounds(for: .mediaBox) imageView.image = pdfPage!.thumbnail(of: pdfPageRect.size, for: .mediaBox) // Getting the UIImage of the PDF page and assign it to the needed image view imageView.contentMode = .scaleAspectFit imageView.clipsToBounds = true print("\(pdfPage?.rotation)") // Prints the correct rotation value, even though UIImageView does not respect it } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } // Layout only override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemPink view.addSubview(imageView) NSLayoutConstraint.activate([ imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), imageView.widthAnchor.constraint(equalToConstant: 350), imageView.heightAnchor.constraint(equalToConstant: 700), ]) } } Example screenshots from simulator ✅ Presented correctly (iOS 15) ❌ Presented incorrectly (iOS 13.2)
0
0
1.5k
Jan ’22
Display a PDF does not work correctly in iOS 15 using CoreGraphics libraries
I have an application coded in objective-c that are using CoreGraphics and CGPDFDocument, it's a PDF reader. With the release of iOS 15 i'm having problems with the rendering of certain pages in certain PDF files. The problem is not present with PDFKit. I have also downloaded the ZoomingPDFViewer example (https://developer.apple.com/library/archive/samplecode/ZoomingPDFViewer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010281) from the official apple documentation page and i see that the same thing happens. See the problem
1
0
1.6k
Jan ’22
Bad quality of scanned documents
Hey guys, facing the issue that scanned documents on my iPhone 12 Pro Max with Files app are pretty bad quality. Guess it started with iOS 15 beta 3. Unfortunately issue still persists with current non beta iOS 15 release. It‘s the same on iPad OS 15. When I launch ‚scan with iPhone’ using Preview app on macOS quality is good as always. Hence looks like issue is related on files app or PDF processing on iPhone. Have anybody else seen the same? Thanx and cheers, Flory
33
1
15k
Jan ’22
PDFKit with 3D annotations/overlay?
I'm currently using PDFKit with Annotations in a unique way. The Annotations are Icons that serve as a link to an asset on a technical drawing. In this way, the user can view the asset details or find the asset from the asset details. I'm using flat images as annotation icons but would like to use 3D assets, preferably 'real' 3D assets where the prospective changes as the user moves the PDF. I'm curious on the best way to accomplish this task. The specific need for the PDF is because it holds the annotation text, which serves as a location indicator (X,Y) to place my Annotation image on top of. PDFs also hold a very high resolution at a relatively low file size, which is good for viewing the rest of the technical document. SceneKit Solution: From my research, I believe SceneKit would accomplish this by utilizing a PDF as a texture (or converting to high resolution PNG). However, I'm unsure how I would take the Annotation location in this method. I believe I can accomplish this by using PDFKit to extract the (X,Y) then place it in the comparable SceneKit scene, but have not tested this theory. I'm wondering if there is an easier or more direct way of accomplishing this task?
0
0
886
Jan ’22
When saving PDFDocument some important information about the content might be lost.
After saving document via PDFKit (using PDFDocument function "write(to: )" ) some important information might be lost. For example, original document generated via Google Drive: "doc_original.pdf" https://www.dropbox.com/s/y0kfdlp2eo9zohs/doc_original.pdf?dl=0 Document after saving via PDFKit: "doc_saved_pdfkit.pdf" https://www.dropbox.com/s/fpegfcifb6yd1oc/doc_saved_pdfkit.pdf?dl=0 If you open files via any PDF viewer (ex. Preview), both looks the same. But if you try to search through doc_saved_pdfkit.pdf, the search won't work (in the original document it works) I've investigated this issue and found that when document saved via PDFDocument function "write(to: )" (even without any modifications) font parameter /ToUnicode being modified and information how to convert glyph codes to unicode is lost (see attached decoded stream contents). That's why it's impossible to find text or copy text from that doc. /ToUnicode stream content for "doc_original.pdf" /ToUnicode content for "doc_saved_pdfkit.pdf" The issue reproduces with Verdana and Roboto font families on iPhone on iOS15.1 and iOS15. Also I've checked on the simulator, it reproduces in iOS 13.5 as well
1
0
745
Jan ’22
Using PencilKit with PDFKit
I'm developing an app that allows you to view PDFs (music notes). I'm using PDFkit to display the pdf and need the pencilkit functionality while viewing the pdf (in the same way that you could mark up a book you are reading in iBooks when you click on the "Mark up" button). I am able to add a canvas on top of the pdf view however, I cannot save the canvas to be merged with the PDF. QuickLook offers a solution because the pencilkit looks to be built into it and works perfectly just the way I need it to, however, I don't need the other things that come with QuickLook. I desperately need your help with how I can get the pencilkit functionality on my custom PDF viewing app. At this point, I can't even find a solution for the "Mark up" button (pencil.tip.crop.circle) to be filled when tapped. Thank you in advance!
2
0
2.2k
Jan ’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.5k
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
659
Activity
Apr ’22
Applying color filters to PDFView
Is there a way to apply color filters to the contents of a PDF displayed in a PDFView? My desired effect is to display the PDF with colors inverted. CIFilter and compositingFilter seem relevant, but I couldn't get to a working example. Any guidance appreciated!
Replies
0
Boosts
0
Views
787
Activity
Mar ’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
516
Activity
Mar ’22
Other Actions
Hello! I need help on getting rid of these other actions whenever saving pdf files.
Replies
1
Boosts
0
Views
486
Activity
Mar ’22
SwiftUI View to PDF margin question
Hi, I am trying to export the following SwiftUI View to PDF using UIGraphicsPDFRenderer. The problem I am getting is there is somehow a margin on top of the exported PDF. The code I am using import SwiftUI struct ContentView: View {     var body: some View {         let pressGesture = TapGesture()                .onEnded { value in                    let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!                    let outputFileURL = documentDirectory.appendingPathComponent("SwiftUI.pdf")                    let pdfVC = UIHostingController(rootView: self)                    let pageSize = CGSize(width: 2.625 * 72.0, height: 1.0 * 72.0)                    pdfVC.view.frame = CGRect(origin: .zero, size: pageSize)                    let rootVC = UIApplication.shared.windows.first?.rootViewController                    rootVC?.addChild(pdfVC)                    rootVC?.view.insertSubview(pdfVC.view, at: 0)                    let pdfRenderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: pageSize.width, height: pageSize.height))                    DispatchQueue.main.async {                         do {                                                                                 try pdfRenderer.writePDF(to: outputFileURL, withActions: { (context) in                                 context.beginPage()                                 pdfVC.view.layer.render(in: context.cgContext)                             })                             print("wrote file to: (outputFileURL.path)")                             pdfVC.removeFromParent()                             pdfVC.view.removeFromSuperview()                                              } catch {                             print("Could not create PDF file: (error.localizedDescription)")                         }                     }                                }         VStack(){                 Text("Hello")         }         .frame(width: 2.625 * 72.0, height: 1.0 * 72.0, alignment: .center)         .gesture(pressGesture)         .background(Color.red)     } } May I know what am I doing wrong? Thanks in advance.
Replies
0
Boosts
0
Views
1.1k
Activity
Mar ’22
CGPDFDocument and PDFDocument fail
I have a bunch of PDF files that I try to open either with CGPDFDocument or PDFDocument (PDFKit) and the init return NULL. Where can I get some feedback why this is happening? I cannot find anything on Console (for connected iOS device) or the Xcode Debug Output window. Let me say that this is not true for all PDF files, some open and some do not. It is also not a problem with permissions, the files are accessible by the app.
Replies
0
Boosts
0
Views
981
Activity
Mar ’22
How to make pdfView zoom=100% to fit screen size
So I have this pdfView and I wanna make it so its first display is a zoom of 100% of the page, but the problem is that what I have now is zooming in to much and the UI is not pretty to be like that. It just like zooms to much and I want it to be perfectly zoomed to fit the screen size. I have tried and can't find a solution. My code is this: &#9;&#9;pdfView.translatesAutoresizingMaskIntoConstraints = false &#9;&#9;pdfView.autoScales = true &#9;&#9;pdfView.maxScaleFactor = 4.0 &#9;&#9;pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit &#9;&#9;view.addSubview(pdfView) &#9;&#9;pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true &#9;&#9;pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true &#9;&#9;pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true &#9;&#9;pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true &#9;&#9; &#9;&#9; &#9;&#9;guard let path = Bundle.main.url(forResource: materia , withExtension: "pdf") else { return } &#9;&#9;if let document = PDFDocument(url: path) { &#9;&#9;&#9;&#9;pdfView.document = document &#9;&#9;}
Replies
1
Boosts
2
Views
4.5k
Activity
Mar ’22
pdfPage.draw ios15 strange results
when calling PDFPage.draw the first page of the pdf prints by repeating the first word over and over. Only in iOS15 all other iOS versions print the page normally. Resaving the document in acrobat with 'optimized' on fixes the issue. However, we can't guarantee our users will do that before uploading a pdf in our system.
Replies
5
Boosts
0
Views
1.3k
Activity
Feb ’22
Creating PDFs on MacOS without UIKit
Greetings, this may be an odd question but I was not able to find an answer to this. So I am developing this pure MacOS program for a client and one thing he wants is to create some PDFs along the way. Great chance I thought to try out this fancy Swift 5 with SwiftUI and so far it's going great, most of the program is up and running but I've hit a wall with the PDF generation, which I thought would be one of the easiest parts. Since it's a pure MacOS program, UIKit is not available but there is not a single tutorial out there for generating PDFs which is not using UIKit to do it. It seems people only want to create PDFs on iOS. Can someone give me a small breakdown or starter or tutorial or skeleton on how I would do that? Thanks and have a nice day
Replies
4
Boosts
0
Views
2k
Activity
Jan ’22
PDFPage thumbnail (UIImage) does not respect PDFPage orientation in iOS 13 (Xcode 13.1)
Description I am having issue with UIImage "generated" from PDFPage via method .thumbnail(of:for). UIImage, which I later display in UIImageView does not respect rotation of the PDF page, but for iOS 13 only. When PDF page is rotated for example by 90° and presented in PDFView all is good and shown correctly. But when I want to take the UIImage (i.e. thumbnail) of the PDFPage and show it in UIImageView, for some reason, iOS 13 does not respect the initial rotation of the PDF page and present it in UIImageView incorrectly. Please behold on below sample code and example screenshots. Testing environment iOS 13 on simulator only, not having real device Xcode 13.1 Sample code for sake of shorter example, I force unwrap where optionals occur import UIKit import PDFKit class TestingViewController: UIViewController { lazy var imageView: UIImageView = { let iv = UIImageView() iv.translatesAutoresizingMaskIntoConstraints = false return iv }() // Pass URL of the PDF document when instantiating this VC init(withURL: URL) { super.init(nibName: nil, bundle: nil) let pdfDoc = PDFDocument(url: withURL) let pdfPage = pdfDoc!.page(at: 0) // Getting first page of the doc let pdfPageRect = pdfPage!.bounds(for: .mediaBox) imageView.image = pdfPage!.thumbnail(of: pdfPageRect.size, for: .mediaBox) // Getting the UIImage of the PDF page and assign it to the needed image view imageView.contentMode = .scaleAspectFit imageView.clipsToBounds = true print("\(pdfPage?.rotation)") // Prints the correct rotation value, even though UIImageView does not respect it } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } // Layout only override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemPink view.addSubview(imageView) NSLayoutConstraint.activate([ imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), imageView.widthAnchor.constraint(equalToConstant: 350), imageView.heightAnchor.constraint(equalToConstant: 700), ]) } } Example screenshots from simulator ✅ Presented correctly (iOS 15) ❌ Presented incorrectly (iOS 13.2)
Replies
0
Boosts
0
Views
1.5k
Activity
Jan ’22
Display a PDF does not work correctly in iOS 15 using CoreGraphics libraries
I have an application coded in objective-c that are using CoreGraphics and CGPDFDocument, it's a PDF reader. With the release of iOS 15 i'm having problems with the rendering of certain pages in certain PDF files. The problem is not present with PDFKit. I have also downloaded the ZoomingPDFViewer example (https://developer.apple.com/library/archive/samplecode/ZoomingPDFViewer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010281) from the official apple documentation page and i see that the same thing happens. See the problem
Replies
1
Boosts
0
Views
1.6k
Activity
Jan ’22
Bad quality of scanned documents
Hey guys, facing the issue that scanned documents on my iPhone 12 Pro Max with Files app are pretty bad quality. Guess it started with iOS 15 beta 3. Unfortunately issue still persists with current non beta iOS 15 release. It‘s the same on iPad OS 15. When I launch ‚scan with iPhone’ using Preview app on macOS quality is good as always. Hence looks like issue is related on files app or PDF processing on iPhone. Have anybody else seen the same? Thanx and cheers, Flory
Replies
33
Boosts
1
Views
15k
Activity
Jan ’22
PDFKit with 3D annotations/overlay?
I'm currently using PDFKit with Annotations in a unique way. The Annotations are Icons that serve as a link to an asset on a technical drawing. In this way, the user can view the asset details or find the asset from the asset details. I'm using flat images as annotation icons but would like to use 3D assets, preferably 'real' 3D assets where the prospective changes as the user moves the PDF. I'm curious on the best way to accomplish this task. The specific need for the PDF is because it holds the annotation text, which serves as a location indicator (X,Y) to place my Annotation image on top of. PDFs also hold a very high resolution at a relatively low file size, which is good for viewing the rest of the technical document. SceneKit Solution: From my research, I believe SceneKit would accomplish this by utilizing a PDF as a texture (or converting to high resolution PNG). However, I'm unsure how I would take the Annotation location in this method. I believe I can accomplish this by using PDFKit to extract the (X,Y) then place it in the comparable SceneKit scene, but have not tested this theory. I'm wondering if there is an easier or more direct way of accomplishing this task?
Replies
0
Boosts
0
Views
886
Activity
Jan ’22
When saving PDFDocument some important information about the content might be lost.
After saving document via PDFKit (using PDFDocument function "write(to: )" ) some important information might be lost. For example, original document generated via Google Drive: "doc_original.pdf" https://www.dropbox.com/s/y0kfdlp2eo9zohs/doc_original.pdf?dl=0 Document after saving via PDFKit: "doc_saved_pdfkit.pdf" https://www.dropbox.com/s/fpegfcifb6yd1oc/doc_saved_pdfkit.pdf?dl=0 If you open files via any PDF viewer (ex. Preview), both looks the same. But if you try to search through doc_saved_pdfkit.pdf, the search won't work (in the original document it works) I've investigated this issue and found that when document saved via PDFDocument function "write(to: )" (even without any modifications) font parameter /ToUnicode being modified and information how to convert glyph codes to unicode is lost (see attached decoded stream contents). That's why it's impossible to find text or copy text from that doc. /ToUnicode stream content for "doc_original.pdf" /ToUnicode content for "doc_saved_pdfkit.pdf" The issue reproduces with Verdana and Roboto font families on iPhone on iOS15.1 and iOS15. Also I've checked on the simulator, it reproduces in iOS 13.5 as well
Replies
1
Boosts
0
Views
745
Activity
Jan ’22
Using PencilKit with PDFKit
I'm developing an app that allows you to view PDFs (music notes). I'm using PDFkit to display the pdf and need the pencilkit functionality while viewing the pdf (in the same way that you could mark up a book you are reading in iBooks when you click on the "Mark up" button). I am able to add a canvas on top of the pdf view however, I cannot save the canvas to be merged with the PDF. QuickLook offers a solution because the pencilkit looks to be built into it and works perfectly just the way I need it to, however, I don't need the other things that come with QuickLook. I desperately need your help with how I can get the pencilkit functionality on my custom PDF viewing app. At this point, I can't even find a solution for the "Mark up" button (pencil.tip.crop.circle) to be filled when tapped. Thank you in advance!
Replies
2
Boosts
0
Views
2.2k
Activity
Jan ’22