Visual c++ load rtf document contains images and text in richedit box? - c++

I am currently working on a project. I have an rtf file which contains some text and images both. I need to display those images and text from rtf to richtextbox in Visual C++. We are not using .Net frameworks or MFC's so everything is in Visual C++ only.
I do'nt have any idea how to do it. If anyone can guide me then it will be really helpful. Thanks in advance.

RichTextBox cannot load HTML. It can load only RTF or plain text.
There are 3rd party components that can convert HTML to RTF, but they don't really do a good job especially when dealing with images. I had done intensive research on this for my sticky notes product Notezilla.
You can use the Web Browser control to show your HTML.

Related

Converting HTML file to PDF using Win32/MFC

As part of my application, my client has requested that I include an automated e-mailing system. As part of this system, I generate HTML code and use automation to send it via. Outlook.
However, they also require a PDF copy of the HTML document to be sent as an attachment. My initial attempts involved using libHaru, which proved difficult to use efficiently, as I was required to create the PDF document from scratch, which required computation of the position of each of the lines in a table, and positioning of all the text, etc.
I was wondering if there would be a way to programmatically convert HTML code (or an HTML file if need be) into a PDF document either by using Win32/MFC itself or an external library.
Thanks in advance!
EDIT: Just to clarify, I am looking for solutions which minimize external dependencies.
You should evaluate this utility wkhtmltopdf:
http://code.google.com/p/wkhtmltopdf/
You can call it from the command line without the need to run a setup.
I use it generating my output documents as html then cal a ShellExecute(...) to convert it to PDF. It's great!
Inside uses webkit + qt. So compability with modern HTML is OK.
Hope it helps.
I'd take a look at PDF Creator, which can be used as a COM object (that acts pretty much like a printer). I haven't used it to print HTML, so I'm not sure, but my guess is that you'll probably end up having to instantiate a web browser control to render the HTML, and then feed it from there to the PDF control.
Some possible answers are in this thread:
C++ Library to Convert HTML to PDF?
Not sure if they will satisfy your particular requirements, but these might at least get you started.
Edit:
Some other possible options here.
Not MFC but you can try QtWebKit. It can render and export HTML to PDF, PNG, JPEG

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.

Inserting an image into RTF data in C++ with MFC

I have to create a RTF file using C++ and MFC. This RTF file will contain images with a link on each of them.
The RTF is always in memory, it's never written on the hard disk.
I need to insert an image in the RTF file at runtime(the image is not always the same). Is it possible to do so with MFC? I'm not sure if CRichEditCtrl can do that...
Thanks
See Insert image into Rich Edit.
Finally, the method at this page worked:
http://www.codeguru.com/Cpp/controls/richedit/article.php/c5383

ColdFusion - converting HTML webpage to Word or PDF document

I have a webpage, where user has a possible to Print this page OR to save it on his/her computer.
How may I save it as a Word or PDF document?
Thanks.
For the MS Word requirement, most versions of Office can interpret basic html/xml. So you might consider the old cfcontent hack as a simpler alternative to POI. (The Word package is not quite as mature as the spreadsheet package.)
Basically you generate html, but use cfheader/cfcontent to tell the browser the content is really a Word document. It is obviously not a true MS Word file. But it is simpler than most options.
http://msdn.microsoft.com/en-us/library/aa155477.aspx
<cfheader name="Content-Disposition" value="attachment; filename=someFile.doc">
<cfcontent type="application/msword">
... your html code here ...
For microsoft office documents you can use the Apache POI project. This means in your coldfusion code you need to use some basic java code to call the poi methods.
However, if you choose the pdf document things are quite easier. You can use the cfdocument tag with the PDF format option
Using the POI or OpenOffice interface (depending on your version) you can create a Word doc. Using the built-in PDF generation tools, you can create a PDF doc. HOwever, you can only present that as an option.
There is no way to override the save/print menu functions. No matter how you handle it, I cna save the source document instead of the .doc or .pdf. Similarly, you cannot prevent me from printing the original document, instead of a prepared PDF.
Here is a method that has worked for me:
Create PDF or FlashPaper with ColdFusion
However, just like printing, you will have to sacrifice some graphics, so this would be best used for exporting content (but as you did not specify, I'm just clarifying that this is possible but at a cost).
Hope that helps.
Use cfdocument to display as a PDF, then they can just click the disk image to save it to their computer. Or you can use the filename= attribute of cfdocument to assign a filename to it, and it will prompt them to save it instead of displaying in the browser.

Printing PDF to HDC (MFC device context)

I'm modifying a C++ application and I'd like to add the ability to print and existing PDF using the MFC printing logic (OnPrint...)
Is there any method to print a PDF into the MFC? Now I'm converting the PDF to a BMP but sometimes the quality is not so great.
Unless something's changed recently you need a 3rd party library to print PDF files. One direction you can take is to convert to PS and then use ghostscript to translate to printer speak. Ghostscript also has the power to convert PDF to PS.
I don't think MFC's own printing logic will work.
Adobe distributes a PDF ActiveX control (primarily for viewing PDFs in IE) that can also be hosted in an MFC application. It includes the following methods: Print, PrintAll, PrintAllFit, PrintPages, PrintPagesFit and PrintWithDialog.