libpoppler-qt4: How to save form changes
Question
I'm using libpoppler with the included qt bindings to edit forms in a PDF file.
// sample code
Poppler::Document* doc = Poppler::Document::load(filename);
Poppler::Page* page = doc->page(0);
QList<Poppler::FormField *> forms = page->formFields();
for(int j = 0; j < forms.length(); j++) {
Poppler::FormField * form = forms.at(j);
// fill it out or whatever...
...
But how can i save the changes made to a file? I know that poppler offers this possibility, eg for the Glib bindings: poppler_document_save(). How do I do this with the QT bindings? There's no Poppler::Document::save()
method or anything, what am I missing?
Solution
I found it out by myself after some digging in the Okular source: One has to use the Poppler::PDFConverter
class. Below provided is a sample method:
bool saveToFile(const QString &filename, const Poppler::Document* doc) {
Poppler::PDFConverter *pdfConv = doc->pdfConverter();
pdfConv->setOutputFileName(filename);
pdfConv->setPDFOptions(pdfConv->pdfOptions()|Poppler::PDFConverter::WithChanges);
bool success = pdfConv->convert();
delete pdfConv;
return success;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow