I am writing a rich text editor using C++ and Qt.
For now, I would like it to support (at least) the .odt format.
I found QTextDocumentWriter for writing the contents of the QTextDocument to a file, but I can't seem to find anything to read that back into the QTextDocument, which obviously makes saving it sort of useless in the first place.
So the question is, how do I load an .odt document into a QTextDocument?
Qt does not currently support the ODT format. Okular has code that does parses ODT to a QTextDocument. Beware: Okular source code is released under GPL license.
Related
Hi have a c++ program that generates a CSV file, all works fine but when I open the CSV file it looks rather messy and I have to manually expand columns to read all the text.
My question is, is there a way in Qt to do ay kind of formatting when generating CSV file e.g. make columns a certain width?
The QString class has several methods that you can use to format the fields of a CSV file.
As an example consider the QString::leftJustified method (link to Qt docs here). Also, you may want to check the right equivalent.
The main advantage of using Qt APIs, in this case, is that you do not have to split formatting and arguments as with standard C++ APIs based on streams.
Anyhow the best API, among those of the QString class, depends on your specs. Check the Qt docs to learn more.
I'd like to have rich text processing for large documents in Qt. The documentation says:
QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML-style tags, or Markdown format. It is optimized to handle large documents and to respond quickly to user input.
However, both QTextEdit widget and TextEdit QML type seem to be slow. I opened official examples like this one and pasted hundreds of pages of rich text. I also did the same in Microsoft Word. As a result, operations on the text in QTextEdit got really slow while in Microsoft Word it's all fine.
So, is there a way to optimize allegedly optimized TextEdit (widget or QML type) in Qt? Or all the difference is due to Microsoft Wording working on just a visible part of the document while TextEdit is not? To that end, could we reasonably use model/view with QTextEdit?
I was trying to output a string to a file using File I/O of C++, but I decided to change the extension of the output file to .pdf, .docx and so on.
None of them seem to open up.
So are there any more internal translations required in order to make that file a proper(file which opens) pdf or docx??
void convert(char *file){
ifstream in(file);
ofstream out("out.pdf",ios::out);
char str;
while(in && out){
in.get(str);
out.put(str);
}
in.close();
out.close();
cout<<"Done!!!";
}
PDF is (and also docx which actually is OOXML; and of course also OpenDocument & DocBook) a file format (and quite a complex one), specified in a complex English document (the ISO 32000 standard) defining which sequences of bytes are valid (and what they represent).
Grossly speaking a PDF file contains elementary steps to draw ink on paper or pixels on screen. With gross simplification, these steps include things like "move the pen to position x=23 y=50", "choose the Arial font of 10pt", "draw the word abc in that font at that position", "choose the pink color for the pen" etc etc, but the details are much more complex.
File extensions don't mean anything (except as an important convention).
To generate a PDF file, you either need to spend weeks or months to study the specification of that PDF format, or to use some library for that (see this question, and also podofo, poppler and several other libraries). Even with the help of a library, you need to understand something about that format.
Are there any more internal translations required in order to make that file
I'm not sure to understand what you mean by translation (a better word would be "converter"). You could generate PDF by sending some other content to a suitable program emitting PDF. You might consider using some document formatter (like LaTeX thru pdflatex, or Lout, or some older variant of troff, etc..) which you would feed with a higher-level file format containing text formatting directives mixed with (some encoding of) the text to be formatted. On Unix like systems you might even use some command pipeline (to avoid writing some "temporary" file), perhaps using popen(3) and related functions.
To write a pdf, docx, etc. you need to setup a file header, and format the data correctly. Changing the extension does not really do much if anything at all.
You will have to use an outside an outside library or format the code yourself. Below are a couple of examples of extensions you can use:
PDF
docx
Is there any library in C++ for creating Epub files, I need to use it with Qt.
My program can export html & css, but I don't know how to convert that to an Epub.
from my googling efforts it appears that most of it is hand written and their isnt a globally accepted SDK. i found a nice tutorial for you which walks you through making epub files. and i did see some other links about using it with QT. maybe someone knows of a good open source project thats somewhere?
epub tutorial
Once you've got the HTML and CSS, you're most of the way there; what remains is the content.opf file, which basically lists all the files in the epub document and the overall metadata (author, publisher, ISBN, etc); and the table of contents. epub 2.0.1 uses the toc.ncx file as a table of contents--it's basically an xml document. epub 3.0 uses the toc.xhtml, which is much more intuitive--it's essentially an ordered list in a nav element. You can do either epub 2.0.1 or epub 3.0; there's enough backwards compatibility built in that older devices will be able to read an epub 3.0 file--as long as you include both a toc.ncx and a toc.xhtml.
You may have to tinker with your CSS; epub doesn't support everything, and the device manufacturers all seem to interpret things differently; it's very "browser wars"-ish.
I find the IDPF's epub spec is the best place to go for formatting info. Here's the relevant bits:
content.opf
toc.xhtml
toc.ncx
I am doing a project in C++ and I want to open PDF files. How can I do it in turbo c++? Do I have to switch to another IDE?
Edited:
I am doing an "E-book management" in c++. After managing the software i wanted to open pdf file through my program and do no access adobe reader or aome other. Sorry for incomplete question.
You can add PDF support to your application with TechSoft's PDF library. Which IDE you use shouldn't matter.
If your intention is to open the PDF for viewing (like you probably do with your PDF viewer, e.g. Acrobat Reader), and not to open the file programmically, you cannot do it in Turbo C++ IDE.
Try opening the IDE in non-full-screen window, and you will be able to see the IDE and the PDF (in the Acrobat Reader) at the same time.
The Poppler library is a C++ library for rendering PDFs to any arbitrary format, whether to screen or image. It's very easy to extend, and I wrote a program for rendering PDFs to a custom image format in about 150 lines, in a little under 5 hours - and most of that work was in exporting the custom image format. A simple renderer came in under 50 lines and took me less than an hour to write.