How to extract selected area of the gui component to PDF in QT - c++

I need to make the tool like Snagit and to take the picture the selected area of the component. I'm searching how to make this tool in Qt.
I firstly prefer using Qt native library but if there is no library which fullfills this requirement, any good c++ libray can be accepted for me.
Any help will be appreciated.
Thanks

I'm not sure to understand exactly what you want. I assume you want to take a screen shot ? and then put this picture into a PDF document.
To take a screenshot with Qt, have a look at this :
http://doc.qt.nokia.com/4.0/widgets-screenshot.html
This will show you how to take a screenshot (using QDesktopWidget) and get a QPixmap.
You can then display this QPixmap into a QTextDocument (see QTextDocument::addResource) and print this document into a PDF file. Something like this :
QPrinter MyPrinter(QPrinter::HighResolution);
MyPrinter.setOutputFormat(QPrinter::PdfFormat);
MyPrinter.setOutputFileName("test.pdf");
MyPrinter.setPageSize(QPrinter::Letter);
MyPrinter.setColorMode(QPrinter::GrayScale);
MyPrinter.setOrientation(QPrinter::Landscape);
MyTextDocument.print(&MyPrinter);

Related

QPdfDocument/QPdfView: How to display an animated PDF?

I implemented a PDF Viewing widget in C++ using Qt, loosely based on https://doc.qt.io/qt-5/qtpdf-pdfviewer-example.html, using the pdfwidgets module. (For this question, we can assume that I copied the code in that link 1:1).
This works well so far.
But now the thing is, the PDF I want to display happens to be an animated PDF. Opened in a regular viewer like Acrobat, it will show a short sequence. That sequence is located on a single page, the frames are not different slides.
In the documentation of the QPdfDocument and the QPdfPageNavigation classes, I can't find any functionality that deals with animated pages. It would suffice if I had any way to set the current animation phase.
Is this possible at all? If so, how?
It's not implemented at the moment. On Windows, you could use an ActiveQt widget to embed Acrobat Reader inside your application, if present. Otherwise you'd need to find a PDF rendering library - most likely a commercial one - that has such support.

how to write and read a text to and from a LineEdit using QT Creator?

I am working with QT Creator. I have a form that contains a push button and an Line Edit. I would like to print a string that i give programatically in this LineEdit.Secondly I would also like to the from the LineBox a string that I fill in and print it using QMessageBox.
How to do it? Need some help. I don't know how to access the displayText() to write and read from a LineEdit.
I would like to specify that I put the push button and the lineedit on the Form using drag and drop.
I am working in c++ under Ubuntu
Appreciate.
You use QLineEdit::setText() to change the text and QLineEdit::text() to read.
Your questions are very basic and show a clear lack of studying the documentation and experimenting thing yourself. Qt is one of the better documented frameworks out there and with lots of examples. Please take your time to go through them.

How to open and display a PDF file using Qt/C++?

I am trying to open and read a PDF file using Qt, but there is no specific way to do that.
I know the subject is a bit old, but...
I found a really simple way to render PDFs in Qt via QtWebKit using pdf.js (http://mozilla.github.com/pdf.js/).
Here is my realization of the idea for Qt5 and the WebEngine: https://github.com/Archie3d/qpdf
Qt itself does not include PDF reading/rendering functionality as far as I know. You might want to have a look at libpoppler which has Qt bindings.
I found this very interesting article on qt-project.org - "Handling PDF - Qt Project".
This page discusses various available options for working with PDF documents in a Qt application. The page does not exactly show how to "open and display an existing PDF document" but it can help you deduce something useful out of all that is explained there.
Here, the page says:
For rendering pages or elements from existing PDF documents to image
files or in-memory pixmaps (useful e.g. for thumbnail generation or
implementing custom viewers), third-party libraries can be used (for
example: poppler-qt4 (freedesktop.org) and muPDF (mupdf.com)).
Alternatively, the task can be delegated to existing command-line
tools (like poppler-utils (freedesktop.org) and muPDF (mupdf.com)).
You can use PdfViewer which is a lightweight PDF viewer that only uses Qt. It contains a PdfView widget which can be easily embedded in your application.
Simple answer : it is not supported in the Qt API.
Other answer : you can code it, I suggest you have a look at this Qt application which uses Ghostscript
The best way I have found to open a pdf is using QProcess in Qt.
You may want to use okular for pdf proccessing.
I know this is an old post, but I stumbled on it during my initial search so I figured I would post some documentation from the solutions I used.
As of Qt 5.10
Check out the QPdfDocument Class. This class can open a PDF and you can use the render function to render a page to an image. I use the QQuickPaintedItem to then "draw" this image but I am sure there are more ways to handle the QImage output.
Prior to Qt 5.10
I used libpoppler to do a VERY similar process.
#include <poppler/qt5/poppler-qt5.h>
Use the Poppler::Document Class to load and handle the entire PDF document and look at the Poppler::Page::renderToImage function to output the page as a QImage.
Qt does not support reading PDF files out of the box and among many approaches you can use Adobe's PDF Reader ActiveX object along with a QAxObject.
You may want to check out this link which describes how to read PDF files in Qt/C++ using ActiveX and has a downloadable example project.

HTML renderer drop-in, C++ code

I want to drop in an HTML renderer that will basically be used for render-to-texture operations.
If I can render the HTML to an HDC, that would be perfect.
I found HTMLayout, which isn't bad. But it isn't open source. But I'm wondering if there's a way to somehow tap into IE or Mozilla/Gecko code, how realisitic/difficult this will be, and possibly some pointers on how to do it.
It will be for a regular straight C++ directx application
Edit
Wow! Mozilla has an embedding kit!
Take a look at WebKit.
Qt can do it, render to a QPainter. See for example http://doc.trolltech.com/4.6/qwebpage.html But not sure if it's easily used if you are not already using Qt.

Barcode generation in Qt4

Any ideas for barcode generation into a textbox in c++ under Qt4?
The idea is to have it in some kind of text format to save it and be able to read it later on.
What about generating the image for printing?
Thanks in advance.
Generating a barcode is as simple as using a barcode font. You can embed the font in your application, and create barcode wherever you can put text.
It depends on what kind of a barcode you are talking about, however, a search on Codeproject yielded this interesting library that is written in C#, however it can generate Code 39, Code 128, Interleaved 2 of 5, to name but a few. Perhaps, this could be recompiled to make it look like a COM object using Runtime Callable COM Wrapper (RCCW), meaning on the C++ side, it looks like a COM library? And hence interact with it from a QT/C++ runtime environment.
Hope this helps,
Best regards,
Tom.
Generating barcode with Qt is quite easy - as Reverend Gonzo pointed out, you use a barcode font.
Then you can paint it with QPainter onto anything. Or print it.
I wrote a post/tutorial on generating code128 with Qt, github example included.
How to generate barcode with a font in Qt
Please check out zint, which can be found on Sourceforge.