Problem loading .pdf file from qrc
Hi,
I have a qrc resource file which contains some image, htm and pdf file. I'm able to load the images and htm files perfectly without any problem, however whenever I try to load the PDF files(using poppler), I get the following error :
Couldn't open file 'qrc:/file/money.pdf' : Invalid argument "
HOWEVER,
When I open the PDF file from outside the resource, it works flawlessly.
Below is a code snippet of what I'm trying to do :
Code:
........
txt = new QWebView(this);
QUrl url
("qrc:/file/00101.htm");
//THE .HTM FILE LOADS FLAWLESSLY txt->load(url);
Poppler::Document *document = Poppler::Document::load("qrc:/file/money.pdf"); // DOESEN'T WORK IF I LOAD FROM RESOURCE
Poppler::Document *document = Poppler::Document::load("C:/Users/el33t/Documents/QT EXPERIMENTS/Pro1/file/money.pdf"); // WORKS FLAWLESSLY IF I LOAD IT EXTERNALLY.
Any help would be greatly appreciated.
Regards,
Re: Problem loading .pdf file from qrc
If the load operation is being done by the PDF viewer then likely it doesn't know how to access something from a QRC.
And putting large files in a QRC is a bad idea anyway -- it's really only intended for small files. Putting large files in a QRC increases the amount of main store occupied by your program, makes it load slower, and generally hoses things up.
Re: Problem loading .pdf file from qrc
Quote:
Originally Posted by
DanH
And putting large files in a QRC is a bad idea anyway -- it's really only intended for small files. Putting large files in a QRC increases the amount of main store occupied by your program, makes it load slower, and generally hoses things up.
But then using resources is the only way(as far as I know) of 'hiding' my files so that people don't just leech them off when I release my program.
Re: Problem loading .pdf file from qrc
They can be placed in the private directory of the app. This isn't perfectly secure, but they're inaccessible to any on-phone tools.
Re: Problem loading .pdf file from qrc
Quote:
Originally Posted by
el33t
But then using resources is the only way(as far as I know) of 'hiding' my files so that people don't just leech them off when I release my program.
Security through obscurity is never a good idea. And extracting this pdf file from your binary (or directly from memory) is pretty simple so if one really wants to do it, you won't stop him.
Re: Problem loading .pdf file from qrc
ummm... I already had a discussion regarding this...so let's just stick to the topic's purpose.
What's wrong with my program? Why isin't the pdf loading from the .qrc ?
Regards
Re: Problem loading .pdf file from qrc
You have already been told why Poppler, which knows nothing about the Qt mechanism for embedding resources or the pseudo-filesystem used to access them, cannot open the embedded file using a pseudo file name.
If you really must have the PDF embedded then you could:
- Use the Poppler API call that loads from data in-memory and use that after reading the resource into a QByteArray: Poppler::Document::loadFromData().
- Copy the file out of resources into a temporary file and then open that with Poppler::Document::load()
Incidentally, you refer to a "file" in the resources as ":/path/to/file"... the "qrc:" scheme is for use in URLs.
Re: Problem loading .pdf file from qrc
Quote:
Originally Posted by
ChrisW67
You have already been told why Poppler, which knows nothing about the Qt mechanism for embedding resources or the pseudo-filesystem used to access them, cannot open the embedded file using a pseudo file name.
If you really must have the PDF embedded then you could:
- Use the Poppler API call that loads from data in-memory and use that after reading the resource into a QByteArray: Poppler::Document::loadFromData().
- Copy the file out of resources into a temporary file and then open that with Poppler::Document::load()
Incidentally, you refer to a "file" in the resources as ":/path/to/file"... the "qrc:" scheme is for use in URLs.
WHOA!!! I followed your advice of reading the pdf into a array and voila! it works!! Thanks A LOT!
Also, I'd like to thanks the rest others who participated in this thread.
Anyways, if anyone else facing a similar problem want to see what code modification/addition I did to resolve the issue, here is the snippet :
Code:
f.setFileName(":/file/money.pdf");
Poppler::Document *document = Poppler::Document::loadFromData(pdf);
Regards...