Display and manipulate PDF documents in your applications using PDFKit.

Posts under PDFKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

how to change overlay View in PDFPageOverlayViewProvider
I’m using PDFPageOverlayViewProvider with pdfview. I want to control the visibility of the overlay view using a button. However, the view updates only when it disappears and reappears. I would like the changes to be reflected immediately. How can I achieve this? struct PDFKitView: View { let bookId: UUID let bookTitle: String @State private var currentPage = "1" @State private var isSideTab = false @State private var selectedNote: [SelectedNote] = [] var body: some View { let pdfDocument = openPDF(at: bookId.uuidString) ZStack(alignment: .trailing) { HStack(spacing: 0) { PDFKitRepresentableView( bookId: bookId, selectedNote: $selectedNote, currentPage: $currentPage, pdfDocument: pdfDocument ) if isSideTab { SideView() .transition(.move(edge: .trailing)) .zIndex(1) .frame(maxWidth: 260) } } .padding(.top, 73) } .onAppear { getAllNote(bookId: bookId) } .customNavigationBar(back: true) { Text("\(currentPage)/\(pdfDocument.pageCount)") .pretendard(.CaptionRegular) .foregroundStyle(Color.Text.primary) } TrailingView: { Button(action: { withAnimation { isSideTab.toggle() } }) { Image(systemName: SFSymbol.squareStack3dDownForwardFill.icon) .sfPro(.IconMedium) .foregroundStyle(Color.Text.primary) } } } @ViewBuilder func SideView() -> some View { VStack(spacing: 16) { HStack(spacing: 4) { Image(systemName: SFSymbol.squareStack3dDownForwardFill.icon) .sfPro(.IconSmall) .foregroundStyle(Color.Text.primary) Text(Literals.sideTabTitle) .pretendard(.P2Bold) .foregroundStyle(Color.Text.primary) Spacer() } .padding(16) .background { Color.Background.white } ScrollView { ForEach($selectedNote, id: \.noteId) { note in NoteCellView(note: note) } } .background { Color.Fill.white } } .background { Color.Background.blueGray } } @ViewBuilder func NoteCellView(note: Binding<SelectedNote>) -> some View { HStack(alignment: .top, spacing: 16) { Image(.writingNote) .resizable() .scaledToFit() .frame(width: 42, height: 60) VStack(alignment: .leading, spacing: 8) { Text(note.wrappedValue.noteId == bookId.uuidString ? "345" : "123") .foregroundStyle(Color.Text.secondary) .padding(.horizontal, 8) .background { Rectangle() .strokeBorder(Color.Layout.secondary) } Text(bookTitle) .lineLimit(2) Toggle("", isOn: note.selected) .labelsHidden() .tint(Color.Fill.activePrimary) } } .padding(EdgeInsets(top: 20, leading: 16, bottom: 16, trailing: 16)) } } struct PDFKitRepresentableView: UIViewRepresentable { let bookId: UUID @Binding var selectedNote: [SelectedNote] @Binding var currentPage: String let pdfDocument: PDFDocument let pdfView = PDFView() let toolPicker = PKToolPicker() func makeUIView(context: Context) -> PDFView { pdfView.displayMode = .singlePageContinuous pdfView.usePageViewController(false) pdfView.displayDirection = .vertical pdfView.pageOverlayViewProvider = context.coordinator pdfView.autoScales = true pdfDocument.delegate = context.coordinator pdfView.document = pdfDocument return pdfView } func updateUIView(_ uiView: PDFView, context: Context) { if let localNote = selectedNote.first(where: {$0.noteId == bookId.uuidString}), !localNote.selected { toolPicker.setVisible(false, forFirstResponder: uiView) } else { toolPicker.setVisible(true, forFirstResponder: uiView) } uiView.becomeFirstResponder() } func makeCoordinator() -> CanvasProvider { return CanvasProvider(parent: self) } } final class CanvasProvider: NSObject, PDFPageOverlayViewProvider, PDFDocumentDelegate { var localNotes = [PDFPage: PKCanvasView]() var passNotes = [PDFPage: Image]() let parent: PDFKitRepresentableView init(parent: PDFKitRepresentableView) { self.parent = parent super.init() getDrawingDatas( bookId: parent.bookId.uuidString, selectedNote: parent.selectedNote, document: parent.pdfDocument ) } func pdfView(_ view: PDFView, overlayViewFor page: PDFPage) -> UIView? { var coverView: PKCanvasView? = PKCanvasView() if let view = localNotes[page], parent.selectedNote.first(where: { $0.noteId == parent.bookId.uuidString })?.selected ?? false { view.backgroundColor = .clear view.isOpaque = true view.drawingPolicy = .anyInput view.delegate = self parent.toolPicker.addObserver(view) coverView = view (page as? CanvasPDFPage)?.canvasView = view } else { coverView = nil } for subView in view.documentView?.subviews ?? [] { if subView.theClassName == "PDFPageView" { subView.isUserInteractionEnabled = true } } return coverView } func pdfView(_ pdfView: PDFView, willDisplayOverlayView overlayView: UIView, for page: PDFPage) { } func pdfView(_ pdfView: PDFView, willEndDisplayingOverlayView overlayView: UIView, for page: PDFPage) { } }
0
0
1k
Aug ’24
Receiving NSMallocException on Real devices while using DrawPDFPage
Hi We're using CGPDFDocument to retrieve the PDF document and draw it in the UIView using CGContext.DrawPDFPage. While doing this operation, I was able to get an NSMallocException with a specific document. I was able to get this exception only on real devices; emulators are working fine. The device used is the iPad (5th generation), which has iOS 16.7.8. Steps to replicate: Open the application at the link (we have attached the sample with PDF file with the issue in the link) https://www.dropbox.com/scl/fi/mosvcnqc0nvxwdjf8k0m5/SimplePDFVieweriOS.zip?rlkey=0ntj75yjg71kjwtwwe06uax5v&st=mmv08e2f&dl=0 Navigate through the pages using the next button. After the page navigation to page 7, and the application will throw an NSMallocException with the reason: Failed to grow buffer Platform: Xamarin.iOS Development tool: Visual Studio 2022 Stack trace for the issue: Native stack trace: 0 CoreFoundation 0x00000001b32e9418 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 37912 1 libobjc.A.dylib 0x00000001ac63dc28 objc_exception_throw + 56 2 CoreFoundation 0x00000001b347c5c8 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 1689032 3 CoreFoundation 0x00000001b3474504 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 1656068 4 CoreFoundation 0x00000001b3363160 __CFSafelyReallocate + 68 5 CoreFoundation 0x00000001b33aae9c 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 831132 6 CoreFoundation 0x00000001b335af2c CFDataSetLength + 152 7 CoreGraphics 0x00000001b4ca71a4 CGDataProviderCopyData + 240 8 ImageIO 0x00000001b7fafd38 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 32056 9 ImageIO 0x00000001b7fb1124 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 37156 10 ImageIO 0x00000001b7ff7124 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 323876 11 ImageIO 0x00000001b7fb0fe0 CGImageSourceCreateWithDataProvider + 176 12 CoreGraphics 0x00000001b4d7ac0c EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 1018892 13 CoreGraphics 0x00000001b4d7a9a0 CGPDFImageCreateImage + 208 14 CoreGraphics 0x00000001b4decbc8 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 1485768 15 CoreGraphics 0x00000001b4d26e34 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 675380 16 CoreGraphics 0x00000001b4d2f7c4 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 710596 17 CoreGraphics 0x00000001b4ce16dc CGPDFScannerScan + 436 18 CoreGraphics 0x00000001b5073198 CGPDFDrawingContextDraw + 112 19 CoreGraphics 0x00000001b4d271b0 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 676272 20 CoreGraphics 0x00000001b4d2f7c4 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 710596 21 CoreGraphics 0x00000001b4ce16dc CGPDFScannerScan + 436 22 CoreGraphics 0x00000001b4d3f68c CGContextDrawPDFPageWithDrawingCallbacks + 2680 23 CoreGraphics 0x00000001b4cdb04c CGContextDrawPDFPage + 32 24 SimplePDFViewer 0x0000000100f0cb90 SimplePDFViewer + 1969040 25 SimplePDFViewer 0x0000000100eeb3c0 SimplePDFViewer + 1831872 26 SimplePDFViewer 0x0000000100d35b14 SimplePDFViewer + 39700 27 SimplePDFViewer 0x0000000100e8eb80 SimplePDFViewer + 1452928 28 SimplePDFViewer 0x0000000100f483f4 mono_pmip + 25092 29 SimplePDFViewer 0x0000000100fd8b90 mono_pmip + 616864 30 SimplePDFViewer 0x0000000100fdc014 mono_pmip + 630308 31 SimplePDFViewer 0x0000000100d32450 SimplePDFViewer + 25680 32 SimplePDFViewer 0x0000000100d32328 SimplePDFViewer + 25384 33 UIKitCore 0x00000001b5412150 27A9C298-B702-3C39-8C06-07196E4CD16B + 1667408 34 QuartzCore 0x00000001b47990e8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 119016 35 QuartzCore 0x00000001b480adb8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 585144 36 QuartzCore 0x00000001b47987a8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 116648 37 QuartzCore 0x00000001b4798034 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 114740 38 QuartzCore 0x00000001b47a89f0 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 182768 39 QuartzCore 0x00000001b47d5dc0 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 368064 40 QuartzCore 0x00000001b47c0dc8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 282056 41 CoreFoundation 0x00000001b33698e8 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 563432 42 CoreFoundation 0x00000001b32f951c 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 103708 43 CoreFoundation 0x00000001b3355214 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 479764 44 CoreFoundation 0x00000001b3359d20 CFRunLoopRunSpecific + 584 45 GraphicsServices 0x00000001eab69998 GSEventRunModal + 160 46 UIKitCore 0x00000001b55ec448 27A9C298-B702-3C39-8C06-07196E4CD16B + 3609672 47 UIKitCore 0x00000001b55ec0c0 UIApplicationMain + 312 48 SimplePDFViewer 0x000000010106b350 xamarin_UIApplicationMain + 60 49 SimplePDFViewer 0x0000000100f0de18 SimplePDFViewer + 1973784 50 SimplePDFViewer 0x0000000100eecd4c SimplePDFViewer + 1838412 51 SimplePDFViewer 0x0000000100eece70 SimplePDFViewer + 1838704 52 SimplePDFViewer 0x0000000100d33ad0 SimplePDFViewer + 31440 53 SimplePDFViewer 0x0000000100e8eb80 SimplePDFViewer + 1452928 54 SimplePDFViewer 0x0000000100f483f4 mono_pmip + 25092 55 SimplePDFViewer 0x0000000100fd8b90 mono_pmip + 616864 56 SimplePDFViewer 0x0000000100fddbdc mono_pmip + 637420 57 SimplePDFViewer 0x0000000100f2d5ec SimplePDFViewer + 2102764 58 SimplePDFViewer 0x00000001010802dc xamarin_log + 22464 59 SimplePDFViewer 0x0000000100d334bc SimplePDFViewer + 29884 60 dyld 0x00000001d0b04344 8A4B89B7-D348-375B-97B1-FC8A84E3E5CE + 82756 Kindly let us know if you need any further details regarding this issue.
0
0
749
Aug ’24
PDFKit deletes certificates on document load
Why does PDFKit delete signature widgets that have already been digitally signed? This should not happen. Is there an undocumented flag that needs to be set so that PDFKit doesn't remove them when loading or saving the PDF? It's difficult to tell if it is happening at PDFDocument(url: fileURL) or document.write(to: outputURL) If a document is signed and still allows annotations, form filling, comments, etc. we should be able to load the PDF into a PDFDocument and save it without losing the certs. Instead the certs are gone and only the signature annotation widgets are present. Here is a simple example of loading and then saving the PDF with out any changes and it shows that the data is actually being changed... ... import UIKit import PDFKit class ViewController: UIViewController { var pdfView: PDFView! @IBOutlet weak var myButton: UIButton! override func viewDidLoad() { super.viewDidLoad() pdfView = PDFView(frame: self.view.bounds) pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.view.addSubview(pdfView) self.view.bringSubviewToFront(myButton) // Load and compare the PDF data if let originalData = loadPDF() { if let loadedData = getRawDataFromLoadedPDF() { let isDataEqual = comparePDFData(originalData, loadedData) print("Is original data equal to loaded data? \(isDataEqual)") } } } @IBAction func onSave(_ sender: Any) { if let savedData = savePDF() { if let originalData = loadPDF() { let isDataEqual = comparePDFData(originalData, savedData) print("Is original data equal to saved data? \(isDataEqual)") } } } func loadPDF() -&gt; Data? { guard let fileURL = Bundle.main.url(forResource: "document", withExtension: "pdf") else { print("Error: document.pdf not found in bundle.") return nil } do { let originalData = try Data(contentsOf: fileURL) if let document = PDFDocument(url: fileURL) { pdfView.document = document print("PDF loaded successfully.") return originalData } else { print("Error: Unable to load PDF document.") return nil } } catch { print("Error reading PDF data: \(error)") return nil } } func getRawDataFromLoadedPDF() -&gt; Data? { guard let document = pdfView.document else { print("Error: No document is currently loaded in pdfView.") return nil } if let data = document.dataRepresentation() { return data } else { print("Error: Unable to get raw data from loaded PDF document.") return nil } } func comparePDFData(_ data1: Data, _ data2: Data) -&gt; Bool { return data1 == data2 } func savePDF() -&gt; Data? { guard let document = pdfView.document else { print("Error: No document is currently loaded in pdfView.") return nil } let fileManager = FileManager.default let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask) guard let documentsURL = urls.first else { print("Error: Could not find the documents directory.") return nil } let outputURL = documentsURL.appendingPathComponent("document_out.pdf") if document.write(to: outputURL) { print("PDF saved successfully to \(outputURL.path)") do { let savedData = try Data(contentsOf: outputURL) return savedData } catch { print("Error reading saved PDF data: \(error)") return nil } } else { print("Error: Unable to save PDF document.") return nil } } }
1
1
728
Aug ’24
If you select a character in the content of PFDView using PDfkit with a long press, the Editmenu is displayed too late.
It's the same as the title, and when I checked the log, there were hundreds to thousands of lines with the following content. The larger the page index of the Pdf from which you select letters, the more logs will be recorded. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. . . . can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-Identity-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-Identity-UCS2'. can't create CMap Adobe-Identity-UCS2'. can't create CMap `Adobe-Identity-UCS2'. I don't know why this is happening. Is there a solution?
0
0
762
Aug ’24
How to append or Save a PDF Document in PDFKit incrementally
Hi - I am using PDFKit to create annotations (drawings), comments, and filling out forms of PDF Templates that are digitally signed. The signature permissions allow for form filling and annotations. How can I save the document incrementally or by appending the changes to the end of a PDF so that it doesn't invalidate the signature and its hash. I didn't see any flag options for this in the PDF write (toFile/URL) or dataRepresentation functions, but it seems noting has been added or changed since iOS 11.0. Is there a flag to allow this with PDFDocumentWriteOption or is there another method I should be using? Thank you.
0
0
748
Aug ’24
PDF Text Selection Crashes When Cursor Moves Over QR Code Only on iOS 18
We are experiencing a crash when selecting text in a PDF and moving the cursor over a QR code. This happens when the QR code at the end of the PDF file with no text following it. [Only on iOS 18] Steps to Reproduce: Clone the repository: git clone https://github.com/aliakhtar49/ios18-pdf-crash/tree/main cd ios18-pdf-crash Run the application to load the provided PDF Select some text and move the cursor over the QR code several times Observe the crash. You can see the gif in the repo Expected Behavior: The application should not crash Actual Behavior: The application crashes: Environment: iOS version: 18.0 Device: iPhone 15 Pro, iPhone 12 Pro Max Additional Context: This issue occurs when the QR code is at the end of the PDF file with no text following it StackTrace `thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x19f3e6ec0) * frame #0: 0x000000019f3e6ec0 CoreGraphics`void PageLayout::ConvertTextRangesToStringRanges<std::__1::span<CFRange, 18446744073709551615ul>, std::__1::back_insert_iterator<std::__1::vector<CFRange, std::__1::allocator<CFRange>>>>(std::__1::span<CFRange, 18446744073709551615ul>&&, std::__1::back_insert_iterator<std::__1::vector<CFRange, std::__1::allocator<CFRange>>>&&) const + 664 frame #1: 0x000000019f424c5c CoreGraphics`CGPDFPageLayoutGetStringRangeIndexNearestPoint + 100 frame #2: 0x000000022b4c096c PDFKit`-[PDFPage characterIndexNearestPoint:] + 128 frame #3: 0x000000022b450950 PDFKit`-[PDFTextInputView _closestPositionToPoint:withinRange:] + 420 frame #4: 0x00000001a0bd02f0 UIKitCore`-[UITextSelectionInteraction _hasTextAlternativesAtLocation:] + 120 frame #5: 0x00000001a03e3834 UIKitCore`-[_UIRemoteKeyboardsEventObserver _hasTextAlternativesForTouch:] + 256 frame #6: 0x000000019fa4e0f8 UIKitCore`-[_UIRemoteKeyboardsEventObserver _endTrackingForTouch:] + 212 frame #7: 0x000000019fa4ca38 UIKitCore`-[_UIRemoteKeyboardsEventObserver _trackTouch:] + 132 frame #8: 0x000000019fa4c94c UIKitCore`-[_UIRemoteKeyboardsEventObserver peekApplicationEvent:] + 220 frame #9: 0x000000019fa4c304 UIKitCore`-[_UIRemoteKeyboards peekApplicationEvent:] + 84 frame #10: 0x000000019fa35dc4 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 4180 frame #11: 0x000000019fa3ef7c UIKitCore`__processEventQueue + 5696 frame #12: 0x000000019f936df4 UIKitCore`updateCycleEntry + 160 frame #13: 0x000000019f934d28 UIKitCore`_UIUpdateSequenceRun + 84 frame #14: 0x000000019f934978 UIKitCore`schedulerStepScheduledMainSection + 172 frame #15: 0x000000019f93580c UIKitCore`runloopSourceCallback + 92 frame #16: 0x000000019d126f9c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 frame #17: 0x000000019d126f30 CoreFoundation`__CFRunLoopDoSource0 + 176 frame #18: 0x000000019d124a08 CoreFoundation`__CFRunLoopDoSources0 + 244 frame #19: 0x000000019d123c14 CoreFoundation`__CFRunLoopRun + 856 frame #20: 0x000000019d123424 CoreFoundation`CFRunLoopRunSpecific + 608 frame #21: 0x00000001e93211c4 GraphicsServices`GSEventRunModal + 164 frame #22: 0x000000019fc6a130 UIKitCore`-[UIApplication _run] + 816 frame #23: 0x000000019fd1855c UIKitCore`UIApplicationMain + 340 frame #24: 0x0000000105e77c38 MyApp.debug.dylib`main at HSAppDelegate.swift:19:20 frame #25: 0x00000001c3058a74 dyld`start + 2724`
3
1
1.2k
Aug ’24
How do I correctly show a PDF document?
How do I correctly show a PDF document? iPad and Xcode 15.4 Within my GameViewController, I have: func presentScene(_ theScene: SKScene) { theScene.scaleMode = .resizeFill if let skView = self.view as? SKView { skView.ignoresSiblingOrder = true skView.showsFPS = true skView.showsNodeCount = true #if os(iOS) let theTransition = SKTransition.doorway(withDuration: 2.0) skView.presentScene(theScene, transition: theTransition) #elseif os(tvOS) skView.presentScene(theScene) #endif } } // presentScene I believe presentScene(theScene) goes to the sceneDidLoad() func of theScene which adds various SKSpriteNodes to the scene via a call to addChild(theNode). So far so good ... Until I have a SKScene wherein I wish to display a PDF. I use this snippet to display this PDF with this call within the SKScene's sceneDisLoad(): displayPDF("ABOUT_OLD_WEST_LOCOMOTIVE") func displayPDF(_ itsName:String) { let pdfView = PDFView() guard let path = Bundle.main.path(forResource: itsName, ofType: "pdf") else { return } print("path") guard let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) else { return } print("pdfDocument") pdfView.displayMode = .singlePageContinuous pdfView.autoScales = true pdfView.displayDirection = .vertical pdfView.document = pdfDocument } // displayPDF The 2 print statements show, yet the SKScene does not display the PDF via pdfView.document = pdfDocument? Anyone have a clue what errors I have committed? Appreciate it.
4
0
1.2k
Jul ’24
Saving edited PDFs directly to application from QuickLook
I'm stuck on a problem where I need to be able to have the same editing capabilities as in .quickLookPreview and be able to save the edited file to the application with the "Done" button. So, in nutshell, I need to implement the same functionality many other applications provide including Apple's Files. However with .quickLookPreview I don't get the ability to save edited files directly to the application, and I've had no luck finding help from the internet (thus this question). Perhaps somebody has implemented this before and could give me a lead somewhere? PS. I'm trying to find a solution without any third party libraries
1
0
1k
Jul ’24
TextKit2 to PDF WITHOUT Font embedding
I can render text from TextKit2 into a PDF everything is fine. But in this case the font is embedded into the PDF. I need the Pdf to contains only the paths / glyphs and not font. I can't find a solution yet. I don't want to create an image or using UIViews etc. It would be nice to get the bezier path of the text I have done this with TextKit1 but the glyphs are gone with TextKit2 Can anyone help me ? Thanks :)
1
0
1.3k
Jun ’24
UIPrintPageRenderer hangs app after iPhone update
After updating iPhone from 17.4 to 17.5.1 UIPrintPageRenderer completely hangs app when getting NumberOfPages from Renderer. var render = new UIPrintPageRenderer(); if (webViewPages != null && reportIndex < webViewPages.Length) { render.AddPrintFormatter( webViewPages[reportIndex].ViewPrintFormatter, 0); } else { render.AddPrintFormatter( new UIMarkupTextPrintFormatter(reportContent), 0); } var printable = CoreGraphics.CGRectExtensions.Inset(page, 0, 0); render.SetValueForKey(NSValue.FromCGRect(page), new NSString("paperRect")); render.SetValueForKey(NSValue.FromCGRect(printable), new NSString("printableRect")); var pdfData = new NSMutableData(); UIGraphics.BeginPDFContext(pdfData, page, null); int pageNum = 0; for (pageNum = 0; pageNum < render.NumberOfPages; pageNum++) { UIGraphics.BeginPDFPage(); var bounds = UIGraphics.PDFContextBounds; render.DrawPage(pageNum, bounds); } UIGraphics.EndPDFContext();
0
1
664
Jun ’24
PDF reading using PDFKit cannot render some text in iOS 17
Hello y'all, I would like to discuss here if anyone else is noticing that some PDF files are not rendered as expected in iOS/iPadOS 17, it seems that some text with background (screenshot attached) are not rendered and you can only see the back color. The issue is reproducible on Preview, Safari, where I guess Apple is using PDFKit framework too. We submitted different issues with Feedback Assistant, however I've not hear back from Apple yet. Is anyone else able to reproduce the issue? Thanks,
12
6
3.7k
May ’24
PDFKIT, Static Text, on MacOS
Hi community: I'm trying to create a form PDF form a script in swift on Mac First approach was trying to add a simple and static text not collapsible. But I tried multiple options. And all ends on something that is not a static text. The best approach was to create a textfield not editable with widget PDFKit, but when you go to the preview app on Mac and pass the the mouse over the field, it is highlighted in blue ... Thanks for the support.
0
0
861
Apr ’24
Rotate PDF Annotation
I'm working with PDFKit and trying to rotate PDFAnnotation from a PDFView: Here is my code for a normal case(no rotated): class ImageAnnotation: PDFAnnotation { var image: UIImage? init(image: UIImage?, bounds: CGRect) { self.image = image super.init(bounds: bounds, forType: .stamp, withProperties: nil) } override func draw(with box: PDFDisplayBox, in context: CGContext) { guard let cgImage = self.image?.cgImage else { return } context.draw(cgImage, in: bound) } } And here is the way I used to rotate PDFAnnotation: init(image: UIImage?, bounds: CGRect) { self.image = image super.init(bounds: bounds.applying(CGAffineTransform(rotationAngle: -CGFloat.pi/12)), forType: .stamp, withProperties: nil) } override func draw(with box: PDFDisplayBox, in context: CGContext) { guard let cgImage = self.image?.cgImage else { return } context.rotate(by: CGFloat.pi/12) context.draw(cgImage, in: bounds) } But it doesn't work as expected. Can you help me? Thank you.
0
0
788
Apr ’24
how to change overlay View in PDFPageOverlayViewProvider
I’m using PDFPageOverlayViewProvider with pdfview. I want to control the visibility of the overlay view using a button. However, the view updates only when it disappears and reappears. I would like the changes to be reflected immediately. How can I achieve this? struct PDFKitView: View { let bookId: UUID let bookTitle: String @State private var currentPage = "1" @State private var isSideTab = false @State private var selectedNote: [SelectedNote] = [] var body: some View { let pdfDocument = openPDF(at: bookId.uuidString) ZStack(alignment: .trailing) { HStack(spacing: 0) { PDFKitRepresentableView( bookId: bookId, selectedNote: $selectedNote, currentPage: $currentPage, pdfDocument: pdfDocument ) if isSideTab { SideView() .transition(.move(edge: .trailing)) .zIndex(1) .frame(maxWidth: 260) } } .padding(.top, 73) } .onAppear { getAllNote(bookId: bookId) } .customNavigationBar(back: true) { Text("\(currentPage)/\(pdfDocument.pageCount)") .pretendard(.CaptionRegular) .foregroundStyle(Color.Text.primary) } TrailingView: { Button(action: { withAnimation { isSideTab.toggle() } }) { Image(systemName: SFSymbol.squareStack3dDownForwardFill.icon) .sfPro(.IconMedium) .foregroundStyle(Color.Text.primary) } } } @ViewBuilder func SideView() -> some View { VStack(spacing: 16) { HStack(spacing: 4) { Image(systemName: SFSymbol.squareStack3dDownForwardFill.icon) .sfPro(.IconSmall) .foregroundStyle(Color.Text.primary) Text(Literals.sideTabTitle) .pretendard(.P2Bold) .foregroundStyle(Color.Text.primary) Spacer() } .padding(16) .background { Color.Background.white } ScrollView { ForEach($selectedNote, id: \.noteId) { note in NoteCellView(note: note) } } .background { Color.Fill.white } } .background { Color.Background.blueGray } } @ViewBuilder func NoteCellView(note: Binding<SelectedNote>) -> some View { HStack(alignment: .top, spacing: 16) { Image(.writingNote) .resizable() .scaledToFit() .frame(width: 42, height: 60) VStack(alignment: .leading, spacing: 8) { Text(note.wrappedValue.noteId == bookId.uuidString ? "345" : "123") .foregroundStyle(Color.Text.secondary) .padding(.horizontal, 8) .background { Rectangle() .strokeBorder(Color.Layout.secondary) } Text(bookTitle) .lineLimit(2) Toggle("", isOn: note.selected) .labelsHidden() .tint(Color.Fill.activePrimary) } } .padding(EdgeInsets(top: 20, leading: 16, bottom: 16, trailing: 16)) } } struct PDFKitRepresentableView: UIViewRepresentable { let bookId: UUID @Binding var selectedNote: [SelectedNote] @Binding var currentPage: String let pdfDocument: PDFDocument let pdfView = PDFView() let toolPicker = PKToolPicker() func makeUIView(context: Context) -> PDFView { pdfView.displayMode = .singlePageContinuous pdfView.usePageViewController(false) pdfView.displayDirection = .vertical pdfView.pageOverlayViewProvider = context.coordinator pdfView.autoScales = true pdfDocument.delegate = context.coordinator pdfView.document = pdfDocument return pdfView } func updateUIView(_ uiView: PDFView, context: Context) { if let localNote = selectedNote.first(where: {$0.noteId == bookId.uuidString}), !localNote.selected { toolPicker.setVisible(false, forFirstResponder: uiView) } else { toolPicker.setVisible(true, forFirstResponder: uiView) } uiView.becomeFirstResponder() } func makeCoordinator() -> CanvasProvider { return CanvasProvider(parent: self) } } final class CanvasProvider: NSObject, PDFPageOverlayViewProvider, PDFDocumentDelegate { var localNotes = [PDFPage: PKCanvasView]() var passNotes = [PDFPage: Image]() let parent: PDFKitRepresentableView init(parent: PDFKitRepresentableView) { self.parent = parent super.init() getDrawingDatas( bookId: parent.bookId.uuidString, selectedNote: parent.selectedNote, document: parent.pdfDocument ) } func pdfView(_ view: PDFView, overlayViewFor page: PDFPage) -> UIView? { var coverView: PKCanvasView? = PKCanvasView() if let view = localNotes[page], parent.selectedNote.first(where: { $0.noteId == parent.bookId.uuidString })?.selected ?? false { view.backgroundColor = .clear view.isOpaque = true view.drawingPolicy = .anyInput view.delegate = self parent.toolPicker.addObserver(view) coverView = view (page as? CanvasPDFPage)?.canvasView = view } else { coverView = nil } for subView in view.documentView?.subviews ?? [] { if subView.theClassName == "PDFPageView" { subView.isUserInteractionEnabled = true } } return coverView } func pdfView(_ pdfView: PDFView, willDisplayOverlayView overlayView: UIView, for page: PDFPage) { } func pdfView(_ pdfView: PDFView, willEndDisplayingOverlayView overlayView: UIView, for page: PDFPage) { } }
Replies
0
Boosts
0
Views
1k
Activity
Aug ’24
Receiving NSMallocException on Real devices while using DrawPDFPage
Hi We're using CGPDFDocument to retrieve the PDF document and draw it in the UIView using CGContext.DrawPDFPage. While doing this operation, I was able to get an NSMallocException with a specific document. I was able to get this exception only on real devices; emulators are working fine. The device used is the iPad (5th generation), which has iOS 16.7.8. Steps to replicate: Open the application at the link (we have attached the sample with PDF file with the issue in the link) https://www.dropbox.com/scl/fi/mosvcnqc0nvxwdjf8k0m5/SimplePDFVieweriOS.zip?rlkey=0ntj75yjg71kjwtwwe06uax5v&st=mmv08e2f&dl=0 Navigate through the pages using the next button. After the page navigation to page 7, and the application will throw an NSMallocException with the reason: Failed to grow buffer Platform: Xamarin.iOS Development tool: Visual Studio 2022 Stack trace for the issue: Native stack trace: 0 CoreFoundation 0x00000001b32e9418 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 37912 1 libobjc.A.dylib 0x00000001ac63dc28 objc_exception_throw + 56 2 CoreFoundation 0x00000001b347c5c8 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 1689032 3 CoreFoundation 0x00000001b3474504 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 1656068 4 CoreFoundation 0x00000001b3363160 __CFSafelyReallocate + 68 5 CoreFoundation 0x00000001b33aae9c 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 831132 6 CoreFoundation 0x00000001b335af2c CFDataSetLength + 152 7 CoreGraphics 0x00000001b4ca71a4 CGDataProviderCopyData + 240 8 ImageIO 0x00000001b7fafd38 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 32056 9 ImageIO 0x00000001b7fb1124 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 37156 10 ImageIO 0x00000001b7ff7124 7E9A543E-EE3C-34B7-9EFE-D5F6357F2FA3 + 323876 11 ImageIO 0x00000001b7fb0fe0 CGImageSourceCreateWithDataProvider + 176 12 CoreGraphics 0x00000001b4d7ac0c EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 1018892 13 CoreGraphics 0x00000001b4d7a9a0 CGPDFImageCreateImage + 208 14 CoreGraphics 0x00000001b4decbc8 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 1485768 15 CoreGraphics 0x00000001b4d26e34 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 675380 16 CoreGraphics 0x00000001b4d2f7c4 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 710596 17 CoreGraphics 0x00000001b4ce16dc CGPDFScannerScan + 436 18 CoreGraphics 0x00000001b5073198 CGPDFDrawingContextDraw + 112 19 CoreGraphics 0x00000001b4d271b0 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 676272 20 CoreGraphics 0x00000001b4d2f7c4 EDFE1CE3-C3C4-30A2-AC92-099D20347781 + 710596 21 CoreGraphics 0x00000001b4ce16dc CGPDFScannerScan + 436 22 CoreGraphics 0x00000001b4d3f68c CGContextDrawPDFPageWithDrawingCallbacks + 2680 23 CoreGraphics 0x00000001b4cdb04c CGContextDrawPDFPage + 32 24 SimplePDFViewer 0x0000000100f0cb90 SimplePDFViewer + 1969040 25 SimplePDFViewer 0x0000000100eeb3c0 SimplePDFViewer + 1831872 26 SimplePDFViewer 0x0000000100d35b14 SimplePDFViewer + 39700 27 SimplePDFViewer 0x0000000100e8eb80 SimplePDFViewer + 1452928 28 SimplePDFViewer 0x0000000100f483f4 mono_pmip + 25092 29 SimplePDFViewer 0x0000000100fd8b90 mono_pmip + 616864 30 SimplePDFViewer 0x0000000100fdc014 mono_pmip + 630308 31 SimplePDFViewer 0x0000000100d32450 SimplePDFViewer + 25680 32 SimplePDFViewer 0x0000000100d32328 SimplePDFViewer + 25384 33 UIKitCore 0x00000001b5412150 27A9C298-B702-3C39-8C06-07196E4CD16B + 1667408 34 QuartzCore 0x00000001b47990e8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 119016 35 QuartzCore 0x00000001b480adb8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 585144 36 QuartzCore 0x00000001b47987a8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 116648 37 QuartzCore 0x00000001b4798034 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 114740 38 QuartzCore 0x00000001b47a89f0 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 182768 39 QuartzCore 0x00000001b47d5dc0 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 368064 40 QuartzCore 0x00000001b47c0dc8 9E40B2EB-260C-3AF1-AE45-A1A551A8C1B9 + 282056 41 CoreFoundation 0x00000001b33698e8 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 563432 42 CoreFoundation 0x00000001b32f951c 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 103708 43 CoreFoundation 0x00000001b3355214 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 479764 44 CoreFoundation 0x00000001b3359d20 CFRunLoopRunSpecific + 584 45 GraphicsServices 0x00000001eab69998 GSEventRunModal + 160 46 UIKitCore 0x00000001b55ec448 27A9C298-B702-3C39-8C06-07196E4CD16B + 3609672 47 UIKitCore 0x00000001b55ec0c0 UIApplicationMain + 312 48 SimplePDFViewer 0x000000010106b350 xamarin_UIApplicationMain + 60 49 SimplePDFViewer 0x0000000100f0de18 SimplePDFViewer + 1973784 50 SimplePDFViewer 0x0000000100eecd4c SimplePDFViewer + 1838412 51 SimplePDFViewer 0x0000000100eece70 SimplePDFViewer + 1838704 52 SimplePDFViewer 0x0000000100d33ad0 SimplePDFViewer + 31440 53 SimplePDFViewer 0x0000000100e8eb80 SimplePDFViewer + 1452928 54 SimplePDFViewer 0x0000000100f483f4 mono_pmip + 25092 55 SimplePDFViewer 0x0000000100fd8b90 mono_pmip + 616864 56 SimplePDFViewer 0x0000000100fddbdc mono_pmip + 637420 57 SimplePDFViewer 0x0000000100f2d5ec SimplePDFViewer + 2102764 58 SimplePDFViewer 0x00000001010802dc xamarin_log + 22464 59 SimplePDFViewer 0x0000000100d334bc SimplePDFViewer + 29884 60 dyld 0x00000001d0b04344 8A4B89B7-D348-375B-97B1-FC8A84E3E5CE + 82756 Kindly let us know if you need any further details regarding this issue.
Replies
0
Boosts
0
Views
749
Activity
Aug ’24
LARGE PDF HANDLING PROBLEM IN PREVIEW
hi when I try to open any large pdf it loads but zoom in zoomout not working… same happening in iPadOS 18 beta also
Replies
1
Boosts
0
Views
737
Activity
Aug ’24
PDFKit deletes certificates on document load
Why does PDFKit delete signature widgets that have already been digitally signed? This should not happen. Is there an undocumented flag that needs to be set so that PDFKit doesn't remove them when loading or saving the PDF? It's difficult to tell if it is happening at PDFDocument(url: fileURL) or document.write(to: outputURL) If a document is signed and still allows annotations, form filling, comments, etc. we should be able to load the PDF into a PDFDocument and save it without losing the certs. Instead the certs are gone and only the signature annotation widgets are present. Here is a simple example of loading and then saving the PDF with out any changes and it shows that the data is actually being changed... ... import UIKit import PDFKit class ViewController: UIViewController { var pdfView: PDFView! @IBOutlet weak var myButton: UIButton! override func viewDidLoad() { super.viewDidLoad() pdfView = PDFView(frame: self.view.bounds) pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.view.addSubview(pdfView) self.view.bringSubviewToFront(myButton) // Load and compare the PDF data if let originalData = loadPDF() { if let loadedData = getRawDataFromLoadedPDF() { let isDataEqual = comparePDFData(originalData, loadedData) print("Is original data equal to loaded data? \(isDataEqual)") } } } @IBAction func onSave(_ sender: Any) { if let savedData = savePDF() { if let originalData = loadPDF() { let isDataEqual = comparePDFData(originalData, savedData) print("Is original data equal to saved data? \(isDataEqual)") } } } func loadPDF() -&gt; Data? { guard let fileURL = Bundle.main.url(forResource: "document", withExtension: "pdf") else { print("Error: document.pdf not found in bundle.") return nil } do { let originalData = try Data(contentsOf: fileURL) if let document = PDFDocument(url: fileURL) { pdfView.document = document print("PDF loaded successfully.") return originalData } else { print("Error: Unable to load PDF document.") return nil } } catch { print("Error reading PDF data: \(error)") return nil } } func getRawDataFromLoadedPDF() -&gt; Data? { guard let document = pdfView.document else { print("Error: No document is currently loaded in pdfView.") return nil } if let data = document.dataRepresentation() { return data } else { print("Error: Unable to get raw data from loaded PDF document.") return nil } } func comparePDFData(_ data1: Data, _ data2: Data) -&gt; Bool { return data1 == data2 } func savePDF() -&gt; Data? { guard let document = pdfView.document else { print("Error: No document is currently loaded in pdfView.") return nil } let fileManager = FileManager.default let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask) guard let documentsURL = urls.first else { print("Error: Could not find the documents directory.") return nil } let outputURL = documentsURL.appendingPathComponent("document_out.pdf") if document.write(to: outputURL) { print("PDF saved successfully to \(outputURL.path)") do { let savedData = try Data(contentsOf: outputURL) return savedData } catch { print("Error reading saved PDF data: \(error)") return nil } } else { print("Error: Unable to save PDF document.") return nil } } }
Replies
1
Boosts
1
Views
728
Activity
Aug ’24
If you select a character in the content of PFDView using PDfkit with a long press, the Editmenu is displayed too late.
It's the same as the title, and when I checked the log, there were hundreds to thousands of lines with the following content. The larger the page index of the Pdf from which you select letters, the more logs will be recorded. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. .notdef: no mapping. . . . can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-Identity-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-KR1-UCS2'. can't create CMap Adobe-Identity-UCS2'. can't create CMap Adobe-Identity-UCS2'. can't create CMap `Adobe-Identity-UCS2'. I don't know why this is happening. Is there a solution?
Replies
0
Boosts
0
Views
762
Activity
Aug ’24
How to append or Save a PDF Document in PDFKit incrementally
Hi - I am using PDFKit to create annotations (drawings), comments, and filling out forms of PDF Templates that are digitally signed. The signature permissions allow for form filling and annotations. How can I save the document incrementally or by appending the changes to the end of a PDF so that it doesn't invalidate the signature and its hash. I didn't see any flag options for this in the PDF write (toFile/URL) or dataRepresentation functions, but it seems noting has been added or changed since iOS 11.0. Is there a flag to allow this with PDFDocumentWriteOption or is there another method I should be using? Thank you.
Replies
0
Boosts
0
Views
748
Activity
Aug ’24
PDF Text Selection Crashes When Cursor Moves Over QR Code Only on iOS 18
We are experiencing a crash when selecting text in a PDF and moving the cursor over a QR code. This happens when the QR code at the end of the PDF file with no text following it. [Only on iOS 18] Steps to Reproduce: Clone the repository: git clone https://github.com/aliakhtar49/ios18-pdf-crash/tree/main cd ios18-pdf-crash Run the application to load the provided PDF Select some text and move the cursor over the QR code several times Observe the crash. You can see the gif in the repo Expected Behavior: The application should not crash Actual Behavior: The application crashes: Environment: iOS version: 18.0 Device: iPhone 15 Pro, iPhone 12 Pro Max Additional Context: This issue occurs when the QR code is at the end of the PDF file with no text following it StackTrace `thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x19f3e6ec0) * frame #0: 0x000000019f3e6ec0 CoreGraphics`void PageLayout::ConvertTextRangesToStringRanges<std::__1::span<CFRange, 18446744073709551615ul>, std::__1::back_insert_iterator<std::__1::vector<CFRange, std::__1::allocator<CFRange>>>>(std::__1::span<CFRange, 18446744073709551615ul>&&, std::__1::back_insert_iterator<std::__1::vector<CFRange, std::__1::allocator<CFRange>>>&&) const + 664 frame #1: 0x000000019f424c5c CoreGraphics`CGPDFPageLayoutGetStringRangeIndexNearestPoint + 100 frame #2: 0x000000022b4c096c PDFKit`-[PDFPage characterIndexNearestPoint:] + 128 frame #3: 0x000000022b450950 PDFKit`-[PDFTextInputView _closestPositionToPoint:withinRange:] + 420 frame #4: 0x00000001a0bd02f0 UIKitCore`-[UITextSelectionInteraction _hasTextAlternativesAtLocation:] + 120 frame #5: 0x00000001a03e3834 UIKitCore`-[_UIRemoteKeyboardsEventObserver _hasTextAlternativesForTouch:] + 256 frame #6: 0x000000019fa4e0f8 UIKitCore`-[_UIRemoteKeyboardsEventObserver _endTrackingForTouch:] + 212 frame #7: 0x000000019fa4ca38 UIKitCore`-[_UIRemoteKeyboardsEventObserver _trackTouch:] + 132 frame #8: 0x000000019fa4c94c UIKitCore`-[_UIRemoteKeyboardsEventObserver peekApplicationEvent:] + 220 frame #9: 0x000000019fa4c304 UIKitCore`-[_UIRemoteKeyboards peekApplicationEvent:] + 84 frame #10: 0x000000019fa35dc4 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 4180 frame #11: 0x000000019fa3ef7c UIKitCore`__processEventQueue + 5696 frame #12: 0x000000019f936df4 UIKitCore`updateCycleEntry + 160 frame #13: 0x000000019f934d28 UIKitCore`_UIUpdateSequenceRun + 84 frame #14: 0x000000019f934978 UIKitCore`schedulerStepScheduledMainSection + 172 frame #15: 0x000000019f93580c UIKitCore`runloopSourceCallback + 92 frame #16: 0x000000019d126f9c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 frame #17: 0x000000019d126f30 CoreFoundation`__CFRunLoopDoSource0 + 176 frame #18: 0x000000019d124a08 CoreFoundation`__CFRunLoopDoSources0 + 244 frame #19: 0x000000019d123c14 CoreFoundation`__CFRunLoopRun + 856 frame #20: 0x000000019d123424 CoreFoundation`CFRunLoopRunSpecific + 608 frame #21: 0x00000001e93211c4 GraphicsServices`GSEventRunModal + 164 frame #22: 0x000000019fc6a130 UIKitCore`-[UIApplication _run] + 816 frame #23: 0x000000019fd1855c UIKitCore`UIApplicationMain + 340 frame #24: 0x0000000105e77c38 MyApp.debug.dylib`main at HSAppDelegate.swift:19:20 frame #25: 0x00000001c3058a74 dyld`start + 2724`
Replies
3
Boosts
1
Views
1.2k
Activity
Aug ’24
How do I correctly show a PDF document?
How do I correctly show a PDF document? iPad and Xcode 15.4 Within my GameViewController, I have: func presentScene(_ theScene: SKScene) { theScene.scaleMode = .resizeFill if let skView = self.view as? SKView { skView.ignoresSiblingOrder = true skView.showsFPS = true skView.showsNodeCount = true #if os(iOS) let theTransition = SKTransition.doorway(withDuration: 2.0) skView.presentScene(theScene, transition: theTransition) #elseif os(tvOS) skView.presentScene(theScene) #endif } } // presentScene I believe presentScene(theScene) goes to the sceneDidLoad() func of theScene which adds various SKSpriteNodes to the scene via a call to addChild(theNode). So far so good ... Until I have a SKScene wherein I wish to display a PDF. I use this snippet to display this PDF with this call within the SKScene's sceneDisLoad(): displayPDF("ABOUT_OLD_WEST_LOCOMOTIVE") func displayPDF(_ itsName:String) { let pdfView = PDFView() guard let path = Bundle.main.path(forResource: itsName, ofType: "pdf") else { return } print("path") guard let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) else { return } print("pdfDocument") pdfView.displayMode = .singlePageContinuous pdfView.autoScales = true pdfView.displayDirection = .vertical pdfView.document = pdfDocument } // displayPDF The 2 print statements show, yet the SKScene does not display the PDF via pdfView.document = pdfDocument? Anyone have a clue what errors I have committed? Appreciate it.
Replies
4
Boosts
0
Views
1.2k
Activity
Jul ’24
PDFKit and PencilKit
Does anybody knows how to implement draw on pdf function for iOS? Approach is the same as Files app. Telegram and Whatsapp using the same technique.
Replies
0
Boosts
0
Views
969
Activity
Jul ’24
Convert a local DOC file to PDF in swift
We have to convert a local DOC file to PDF without any server interaction. It will be in offline mode. Any suggestion will be appreciated.
Replies
0
Boosts
0
Views
836
Activity
Jul ’24
We have to convert a local DOC file to PDF without any server interaction.
We are building our own Cocoapod file. We have to convert a local DOC file to PDF without any server interaction. It will be in offline mode. Any suggestion will be appreciated.
Replies
0
Boosts
0
Views
554
Activity
Jul ’24
Saving edited PDFs directly to application from QuickLook
I'm stuck on a problem where I need to be able to have the same editing capabilities as in .quickLookPreview and be able to save the edited file to the application with the "Done" button. So, in nutshell, I need to implement the same functionality many other applications provide including Apple's Files. However with .quickLookPreview I don't get the ability to save edited files directly to the application, and I've had no luck finding help from the internet (thus this question). Perhaps somebody has implemented this before and could give me a lead somewhere? PS. I'm trying to find a solution without any third party libraries
Replies
1
Boosts
0
Views
1k
Activity
Jul ’24
How i can to export pdf to xml?
Hi, I need export pdf file to xml file across my app for macos. how i can do it?
Replies
0
Boosts
0
Views
648
Activity
Jun ’24
TextKit2 to PDF WITHOUT Font embedding
I can render text from TextKit2 into a PDF everything is fine. But in this case the font is embedded into the PDF. I need the Pdf to contains only the paths / glyphs and not font. I can't find a solution yet. I don't want to create an image or using UIViews etc. It would be nice to get the bezier path of the text I have done this with TextKit1 but the glyphs are gone with TextKit2 Can anyone help me ? Thanks :)
Replies
1
Boosts
0
Views
1.3k
Activity
Jun ’24
UIPrintPageRenderer hangs app after iPhone update
After updating iPhone from 17.4 to 17.5.1 UIPrintPageRenderer completely hangs app when getting NumberOfPages from Renderer. var render = new UIPrintPageRenderer(); if (webViewPages != null && reportIndex < webViewPages.Length) { render.AddPrintFormatter( webViewPages[reportIndex].ViewPrintFormatter, 0); } else { render.AddPrintFormatter( new UIMarkupTextPrintFormatter(reportContent), 0); } var printable = CoreGraphics.CGRectExtensions.Inset(page, 0, 0); render.SetValueForKey(NSValue.FromCGRect(page), new NSString("paperRect")); render.SetValueForKey(NSValue.FromCGRect(printable), new NSString("printableRect")); var pdfData = new NSMutableData(); UIGraphics.BeginPDFContext(pdfData, page, null); int pageNum = 0; for (pageNum = 0; pageNum < render.NumberOfPages; pageNum++) { UIGraphics.BeginPDFPage(); var bounds = UIGraphics.PDFContextBounds; render.DrawPage(pageNum, bounds); } UIGraphics.EndPDFContext();
Replies
0
Boosts
1
Views
664
Activity
Jun ’24
How to customize the UIMenuController that pops up after selecting a text in PDFKit
How to Hide the UIMenuController pop-up in PDFKit. Customize the UIMenuItem in the UIMenuController
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
0
Boosts
0
Views
560
Activity
Jun ’24
PDF reading using PDFKit cannot render some text in iOS 17
Hello y'all, I would like to discuss here if anyone else is noticing that some PDF files are not rendered as expected in iOS/iPadOS 17, it seems that some text with background (screenshot attached) are not rendered and you can only see the back color. The issue is reproducible on Preview, Safari, where I guess Apple is using PDFKit framework too. We submitted different issues with Feedback Assistant, however I've not hear back from Apple yet. Is anyone else able to reproduce the issue? Thanks,
Replies
12
Boosts
6
Views
3.7k
Activity
May ’24
PDFKIT, Static Text, on MacOS
Hi community: I'm trying to create a form PDF form a script in swift on Mac First approach was trying to add a simple and static text not collapsible. But I tried multiple options. And all ends on something that is not a static text. The best approach was to create a textfield not editable with widget PDFKit, but when you go to the preview app on Mac and pass the the mouse over the field, it is highlighted in blue ... Thanks for the support.
Replies
0
Boosts
0
Views
861
Activity
Apr ’24
Rotate PDF Annotation
I'm working with PDFKit and trying to rotate PDFAnnotation from a PDFView: Here is my code for a normal case(no rotated): class ImageAnnotation: PDFAnnotation { var image: UIImage? init(image: UIImage?, bounds: CGRect) { self.image = image super.init(bounds: bounds, forType: .stamp, withProperties: nil) } override func draw(with box: PDFDisplayBox, in context: CGContext) { guard let cgImage = self.image?.cgImage else { return } context.draw(cgImage, in: bound) } } And here is the way I used to rotate PDFAnnotation: init(image: UIImage?, bounds: CGRect) { self.image = image super.init(bounds: bounds.applying(CGAffineTransform(rotationAngle: -CGFloat.pi/12)), forType: .stamp, withProperties: nil) } override func draw(with box: PDFDisplayBox, in context: CGContext) { guard let cgImage = self.image?.cgImage else { return } context.rotate(by: CGFloat.pi/12) context.draw(cgImage, in: bounds) } But it doesn't work as expected. Can you help me? Thank you.
Replies
0
Boosts
0
Views
788
Activity
Apr ’24
PDF document upload from OneDrive business getting failed.
I am uploading pdf document through document picker from One drive. When I am uploading pdf document from OneDrive personal account it is working fine but when I am uploading from OneDrive business account it is getting failed.
Replies
0
Boosts
0
Views
913
Activity
Apr ’24