In QT, how to add high resolution images to textdocument
-
I am generating a word document report in qt. I want to insert a high resolution image to qtextdocument. The textdocumnet is written into odt format using textdocument writer.Below listed is my problem W.R.T generating the report:
- inserting high resolution images results in only a small part of image getting displayed in the resulting word document.
- how to have multiple pages in the word doc with each page having its own size. I am stuck with this from days.. Any help will be helfull.Thanks.
QTextDocument testdoc;
QTextCursor testcursor(&testdoc);
QImage img(pixNotesPage.toImage());
testcursor.insertImage(img);here pixNotesPage is a high resolution pixmap rendered from a scene..
-
Hi
- inserting high resolution images results in only a small part of image getting displayed in the resulting word document.
Well if image is wider than the page, you must scale it down so it fits.
Is that what you are seeing ?
- how to have multiple pages in the word doc with each page having its own size.
As far as i know its not possible as each page shares its size with rest of the document.
But you can use multiple documents to get same effect.
-
@mrjj thank you for the response.
-
I tried scaling down the image. I am losing the resolution of the image after scaling down. I want to add a high resolution image.(note:i did use smooth transformation mode)
-
is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
Thank you in advance..
-
-
- I tried scaling down the image. I am losing the resolution of the image after scaling down. I want to add a high resolution image.(note:i did use smooth transformation mode)
But if image is bigger than page, there is no way around down sizing it.
What about generating the image to be the right size from the beginning ?
- is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
As far as i know, nope.
But cant you use
https://doc.qt.io/qt-5/qtextdocumentwriter.html#write
and write multiple QTextDocument to same output ?
-
@mrjj
-is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
As far as i know, nope.
But cant you use
https://doc.qt.io/qt-5/qtextdocumentwriter.html#write
and write multiple QTextDocument to same output ?* I tried this.Only the latest textdocument is being outputted to the word doc.
QTextDocumentWriter writer("/Users/sachinr/Desktop/test.odt"); writer.setFormat("odf"); // same as writer.setFormat("ODF"); writer.write(&qtdoc); writer.write(&testdoc);
-
Hi
Thats odd as code goesbool QTextDocumentWriter::write(const QTextDocument *document) { QByteArray suffix; if (d->device && d->format.isEmpty()) { // if there's no format, see if device is a file, and if so, find // the file suffix if (QFile *file = qobject_cast<QFile *>(d->device)) suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1(); } QByteArray format = !d->format.isEmpty() ? d->format.toLower() : suffix; #ifndef QT_NO_TEXTODFWRITER if (format == "odf" || format == "opendocumentformat" || format == "odt") { QTextOdfWriter writer(*document, d->device); #if QT_CONFIG(textcodec) writer.setCodec(d->codec); #endif return writer.writeAll(); } #endif // QT_NO_TEXTODFWRITER
and seems not to close d->device
so not sure why only last is saved.
-
@mrjj
Thanks for the response.
So is there any way i could generate a word doc report with multiple pages of different sizes or i already have a pdf file generated. Can i convert the pdf file to doc format in qt ?(in that case i dont have to generate textdoc itself)..Is there any reliable 3rd party library as such?Thank you