Display and manipulate PDF documents in your applications using PDFKit.

Posts under PDFKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

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
713
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
758
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.3k
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
885
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
671
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
522
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
984
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
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
713
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
758
Activity
Aug ’22
Can FileProvider provide the full quicklook experience for PDF's?
For local files, it's an amazing feature to be able to space-bar open a PDF document and quickly swipe through the contents of it. How can I enable this for pdf files stored on a volume exposed by FileProvider? Thanks David
Replies
1
Boosts
0
Views
1.7k
Activity
Jul ’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.3k
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
885
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
671
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
793
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
522
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
491
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
984
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