How load HTML file to DataBase
-
Hi
The pictures is not inside the HTML file.
The HTML points to them either on the web or on local disk.Can you show a part of a html file you have `?
-
Hi
The pictures is not inside the HTML file.
The HTML points to them either on the web or on local disk.Can you show a part of a html file you have `?
-
Hi
So the jpg files lives in
C:\tempDirHtmlResume\tempResumeHtmlFile.files\so the task is to save the HTML AND the images to a (sqllite) database ?
and later be able to load a HTML With the images and show in Qt app ?
The main issues is that the html is pointing to disk for these files.
So when you later load the HTML from database, the images MUST be in that location
to be shown.So you also want to save the jpg files to the database ?
-
@mrjj said in How load HTML file to DataBase:
Yes. I am nedd load to DataBase text and images, and after used it's in program.
Ok, this is not easy. Images MUST be saved in database ?
1: find the images in the HTML to be able to store in database
https://stackoverflow.com/questions/51252529/how-to-get-the-src-of-an-image-tag-using-qregexp-and-qstring2: save the images into the database , see here.
https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite3:
When loading an HTML, you must the take all images that it has. ( you must store this info somehow)
and copy each image back to the
c:\tempDirHtmlResume\tempResumeHtmlFile.files\
location.
Else the img src="file:/// no longer work.Alternatively, you must change the HTML to point to other location, where you then copy the images.
But just saving the HTML til database, wont save the images with it. so if you really, really want to store the images in db,
then you need to handle that yourself. -
@Mikeeeeee
well it can use it, but it links to files also.
Images are never embedded in the rich text as far as i know. -
Hi
What type of app are you making ?
You could also print the HTML to pdf and save pdf in databse.
Then images would be included in that case.
But it would not be HTML nor would images be editable in any way. ever. -
Hi,
If you want to have an independent page, you would have to integrated your images as base64 encoded, but that's going to make them heavy.
-
I converted the picture into text
//convert image to string QImage imageForResume("C:\\tempDirHtmlResume\\tempResumeHtmlFile.files\\image001.jpg"); QByteArray byteArrayForImage; QBuffer buffer(&byteArrayForImage); imageForResume.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer QString textImage = byteArrayForImage.toBase64();``` I have HTML-file QString HTMLResume; How to insert textImage in HTMLResume?
-
It's work:
QImage imageForResume("C:\\tempDirHtmlResume\\tempResumeHtmlFile.files\\image001.jpg"); QByteArray byteArrayForImage; QBuffer buffer(&byteArrayForImage); imageForResume.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer QString textImage = byteArrayForImage.toBase64(); HTMLResume.replace(QRegExp("src=\"tempResumeHtmlFile.files/image001.jpg\">"), " src=\"data:image/png;base64," + textImage + "\"/>"); //замена символов //add text Images ui->ResumeHHTextEdit->setHtml(HTMLResume);