[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    unable to add image to QTextDocument saved as .odt file
From:       Roberta Fagandini <robifagandini () gmail ! com>
Date:       2022-08-16 12:08:29
Message-ID: CAFFLmWLMfwc_vRh0=kU847xcBkQLZv3OggUHn2Nc-XoYwmaakw () mail ! gmail ! com
[Download RAW message or body]

Hi all,
I have developed a QGIS python plugin whose output is an .odt file with
text and images. In order to create the .odt file I have written the
folowing code block:
'''
*html_text = '<!DOCTYPE html><html><head></head><body>\*
*<p>My text</p>\*
*<p style="text-align:center; vertical-align: middle;">\*

*<img src="path/to/image/logo.png"></p>\</body></html>'*


*doc = QTextDocument()doc.setHtml( html_text )*




*writer =
QTextDocumentWriter()writer.setFormat(QByteArray(b'ODF'))writer.setFileName('path/to/file/test.odt')writer.write(doc)*


'''
The code above  works perfectly till QGIS 3.16 version wich was compiled
with Qt 5.11. In the later QGIS versions (3.22 - 3.24 - 3.26) compiled with
Qt 5.15, the odt file is correctly created but the image is not added to
the file. If I change the file format, for instance
*writer.setFormat(QByteArray(b'HTML'))*, the image is added to the created
html file also with Qt 5.15.
I have the same problem using QTextCursor.insertImage():
'''








*doc = QtGui.QTextDocument()cursor =
QtGui.QTextCursor(doc)cursor.insertText('Hello
world')cursor.insertImage('path/to/image/logo.png')writer =
QtGui.QTextDocumentWriter()writer.setFormat( QByteArray(b'ODF')
)writer.setFileName(' path/to/file /test.odt')*
'''
The image is correctly added to the odt file with Qt 5.11 while it is not
added to the odt file with Qt 5.15.

Is this a bug or somenthing change in the QTextDocument
and QTextDocumentWriter classes? Looking at the documentation the html img
tag is still supported by the setHtml function (
https://doc.qt.io/qt-5/richtext-html-subset.html).

Any idea?

Thanks in advance!!
Roberta

-- 
*Arch. Roberta Fagandini, PhD*
*GIS and Remote Sensing Technician*
*Gter srl (Unige spin-off)*
*Via Jacopo Ruffini 9/1A - 16128 Genova*
*P.IVA/CF 01998770992*
*www.gter.it* <http://www.gter.it/>
*--*
*Gter social*
*www.twitter.com/Gteronline* <http://www.twitter.com/Gteronline>* - *
*www.facebook.com/Gteronline* <http://www.facebook.com/Gteronline>* -*
*www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis
<http://www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis>*


[Attachment #3 (text/html)]

<div dir="ltr">Hi all,<div>I have developed a QGIS python plugin whose output is an \
.odt file with text and images. In order to create the .odt file I have written the \
folowing code block:</div><div>&#39;&#39;&#39;</div><div><i>html_text = \
&#39;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;\</i></div><div><div><i>&lt;p&gt;My \
text&lt;/p&gt;\</i></div><i>&lt;p style=&quot;text-align:center; vertical-align: \
middle;&quot;&gt;\</i></div><div><i>&lt;img \
src=&quot;path/to/image/logo.png&quot;&gt;&lt;/p&gt;\<br>&lt;/body&gt;&lt;/html&gt;&#39;</i></div><div><i><br>doc \
= QTextDocument()<br>doc.setHtml( html_text  )</i></div><div><i><br>writer = \
QTextDocumentWriter()<br>writer.setFormat(QByteArray(b&#39;ODF&#39;))<br>writer.setFil \
eName(&#39;path/to/file/test.odt&#39;)<br>writer.write(doc)</i></div><div><br></div><div>&#39;&#39;&#39;</div><div>The \
code above   works perfectly till QGIS 3.16 version wich was compiled with Qt 5.11. \
In the later QGIS versions (3.22 - 3.24 - 3.26) compiled with Qt 5.15, the odt file \
is correctly created but the image is not added to the file. If I change the file \
format, for instance    <i>writer.setFormat(QByteArray(b&#39;HTML&#39;))</i>, the \
image is added to the created html file also with Qt 5.15.  </div><div>I have the \
same problem using  QTextCursor.insertImage():</div><div>&#39;&#39;&#39;</div><div><i>doc \
= QtGui.QTextDocument()<br>cursor = \
QtGui.QTextCursor(doc)<br><br>cursor.insertText(&#39;Hello \
world&#39;)<br>cursor.insertImage(&#39;path/to/image/logo.png&#39;)<br><br>writer = \
QtGui.QTextDocumentWriter()<br>writer.setFormat( QByteArray(b&#39;ODF&#39;)   \
)<br>writer.setFileName(&#39; path/to/file  \
/test.odt&#39;)</i><br></div><div>&#39;&#39;&#39;</div><div>The image is correctly \
added to the odt file with Qt 5.11 while it is not added to the odt file with Qt \
5.15.<br clear="all"><div><br></div><div>Is this a bug or somenthing change in the \
QTextDocument and  QTextDocumentWriter classes? Looking at the documentation the html \
img tag is still supported by the setHtml function (<a \
href="https://doc.qt.io/qt-5/richtext-html-subset.html" \
target="_blank">https://doc.qt.io/qt-5/richtext-html-subset.html</a>).</div><div><br></div><div>Any \
idea?</div><div><br></div><div>Thanks in \
advance!!</div><div>Roberta</div></div><div><br></div>-- <br><div dir="ltr" \
class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div \
dir="ltr"><div style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><i><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Arch. Roberta Fagandini, \
PhD</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">GIS and Remote Sensing \
Technician</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Gter srl (Unige \
spin-off)</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i \
style="font-size:13.3333px"><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Via Jacopo Ruffini 9/1A - 16128 \
Genova</span></span></span></i><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">P.IVA/CF \
01998770992</span></span></span></i></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><a \
href="http://www.gter.it/" style="color:rgb(89,143,222)" target="_blank"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">www.gter.it</span></span></span></i></a><i><span \
style="font-size:10px"></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><i><span \
style="font-size:10px"></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">--</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Gter social</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><a \
href="http://www.twitter.com/Gteronline" style="color:rgb(89,143,222)" \
target="_blank"><i><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">www.twitter.com/Gteronline</span></span></span></i></a><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">  -  </span></span></span></i><a \
href="http://www.facebook.com/Gteronline" style="color:rgb(89,143,222)" \
target="_blank"><i><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">www.facebook.com/Gteronline</span></span></span></i></a><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">  -</span></span></span></i><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="color:rgb(89,143,222);font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"><a \
href="http://www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis" \
style="color:rgb(89,143,222)" \
target="_blank">www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis</a></span></span></span></i><br></div><div><i><span \
style="color:rgb(89,143,222);font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><br></span></span></i></div></div></div></div></div>




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic