Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QApplication>
- #include <QPrinter>
- #include <QWebEngineProfile>
- #include <QWebEngineView>
- #include <iostream>
- auto html = "<!DOCTYPE html>"
- "<html lang=\"en\">"
- "<head>"
- " <meta charset=\"UTF-8\">"
- " <style>"
- " img { max-width:100%; max-height:100%; }"
- " div { height: 270px; width: 540px; }"
- " body { margin: 0; background-color: red; }"
- " </style>"
- "</head>"
- "<body>"
- "<div>"
- " <img src=\"https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x5400x2700.png\">"
- "</div>"
- "</body>"
- "</html>"
- ;
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- QWebEngineView view;
- view.show();
- view.resize(540, 270);
- QObject::connect(&view, &QWebEngineView::loadFinished, [&view](bool isOk) {
- if (!isOk) {
- std::cout << "Error";
- return;
- }
- view.grab().save("page.png", "PNG");
- view.close();
- });
- view.setHtml(html);
- return app.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement