Integrate MuPDF Swift - IOS project
Asked Answered
P

0

0

After I created a Objective-c class in my project based on JosephH example. I imported it in my bridging header file. I was actually able to make it work using a .pdf file in the main bundle

NSString *file = [[NSBundle mainBundle] pathForResource:@"hello-world" ofType:@"pdf"];.

which returns:

"/var/containers/Bundle/Application/63F34E6B-75A7-4CC0-9149-9DF2861DF3A2/sempre-editora.app/hello-world.pdf"

It did render everything all right, zooming and everything. but when I try to render a file in my "Documents" folder it just doesn't work. I even tried to just put this "hello-world.pdf" file inside my "Documents" to try it out and it still doesn't work. This is the path of my documents file:

"/var/mobile/Containers/Data/Application/AF776E50-FAAC-4274-824F-4F9634E072F6/Documents/70-10"

What could be the problem? I'm sure this is the correct path for my file, and it actually exists, the framework doesn't throw any error but I just get a gray background.

I thought it could be because my file doesn't have an extension but when I add a .pdf to my file and try to render it, it crashes.

Screen Example

After some tests I realised that when the PDF has two pages, and I go to the second page, it actually renders the pdf.

Perlman answered 8/6, 2016 at 13:18 Comment(4)
I wonder if the crash when you add the .pdf is a clue - whereabouts is it crashing? Does the same PDF file display okay in the example?Strand
It crashes when I initialize my MuDocumentController, it says "Cannot load document". When I try to render from a file inside my project and presentViewController it renders fine. When I try start a pageViewController with it (same file inside my project), it doesn't render, only when I pass pagePerlman
I think there's probably several different things going on here. To get to the bottom of it we need to apply a systematic approach and start from a simple point that should work, then make one change at a time till it doesn't work, and then diagnose why that change didn't work. If you do exactly what github.com/jogu/MuPDF-example/blob/master/MuPDF-example/… what is the first thing that goes wrong and what is the exact error message? (I cannot find the error you mention, "Cannot load document", anywhere in the code.)Strand
Basically if I try to display using "self.presentViewController" it renders normally... If I try to display it using a page View Controller it doesn't render ... No errors, or anything... but if the pdf has two pages or more and I go to the second page, it renders...Perlman

© 2022 - 2024 — McMap. All rights reserved.