I'm creating a Qt application that writes a pdf file using libharu. The true-type-font that is used in the pdf file shall be embedded into the binary file, so it is available on all platforms. For this, I want to use the Qt resource system.
The font file should be used as follows
const char* fontName = HPDF_LoadTTFontFromFile(doc,"path/to/myfont.ttf",HPDF_TRUE);
documentFont = HPDF_GetFont(doc,fontName,"ISO8859-2");
where I want the filename and path to be replaced by a resource name (e.g. :/fonts/myfont.ttf
).
Is there a way to achieve this?
The options that I think of:
- Somehow pass the file content as a string or char array (as it is suggested here). This is not possible as the functions in libharu require a filename. There are no functions that require the actual file content.
- Save the resource content to a temporary file and use the temporary file name in the libharu function.
Are there any other more simple solutions for this? Thanks.
Solution:
Actually the second option was easier than expected. With the answer by robin.thoni and this question, I obtained this pretty simple solution:
std::string fontFile = std::tmpnam(nullptr);
QFile::copy(":/fonts/myfont.ttf",QString::fromStdString(fontFile));
const char* fontName = HPDF_LoadTTFontFromFile(doc,fontFile.c_str(),HPDF_TRUE);