Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
PDF to Image Conversion
-
I download a pdf file via Safari and I "open it" with a Pythonista script, thus the script runs in Appex mode.
The script splits the PDF into its pages (using pyPDF2).
I want to display each PDF page (one at a time, asking the user if he wants to keep this page or not) as the background of the share extension view.
I already have done that with a photo but, here, I need to **convert the PDF page file into either an image, either a JPG/PNG **file...
Somebody can help me? -
You may not be able to do this in Pythonista, Objective C may have some kind of method though.
Check out this stackoverflow question for some info on a Python approach. You might have some luck converting this objective-c code into Pythonista code.
-
Thanks for your so quick answer.
I had searched through the forum, but I guess I gave bad search arguments...sorry -
Even the console.quicklook does not display something with a pdf file.
If I click on a PDF in Pythonista, the little menu (open in or Quick Look), if I click "Quick Look" displays the PDF correctly.
Strange -
Huh. You wouldn't be able to display a UI on top of that anyway I don't think.
-
In other scripts, in apex mode, I start a ui.view as background of the share sheet.
And in the ui.view, I display a ui.ImageView with the background bounds, filled with a photo,
or an ui.WebView.
Thus I hoped to transform the pdf into a jpg and display the jpg in the ui.ImageView as background of my Share Sheet window.
I'm not sure I'm clear enough in my poor English... -
Web views can render PDFs, so maybe you can split the original PDF into multiple (1-page) PDF files (using PyPDF2), and then show them (one after another) using a web view?
-
...it would also be possible to render a PDF into a JPEG/PNG image using
objc_util
of course, but I think the approach I outlined above would be easier, and it doesn't seem like you'd need the image for anything other than displaying it in the UI. -
Thanks, I'll try with the WebView, because using objc_util seems to complex for me..
But how can I load a pdf local file in WebView, I only know load_url and load_html, sorry -
@cvp You can load local files in a web view using a file:// URL. Here's a snippet for converting from a file path to a file URL (from this StackOverflow answer):
import urlparse, urllib def path2url(path): return urlparse.urljoin( 'file:', urllib.pathname2url(path))
-
Thanks
I'am sorry because I should be able to find that my-self...
I really love your app for all I can do with it. -
This post is deleted! -
This post is deleted! -
I do hate reading a post and then finding out the question was asked 5 years ago... It would be nice if somehow the most recent question is what pops up when I visit something like this... (don't worry, I'm sending this to nodebb as well!)
-
This information useful for me. I can use it and do file sharing for free to share it with everyone! Thank you for this information.