简体   繁体   中英

How to read and write doc, pdf files using files in c++

I m writing a c++ program using files and i need to take the input from existing files such as doc files and pdf files. how to program it in c++? And after getting the inputs, how can i write those details into a new doc or pdf files? Can anyone explain me with an example?

C++ as a language doesn't equip you with such features as "write to DOC file" or "read from PDF file". The only staff available to you aa programmer is raw byte-by-byte reading or writing. To make your new brand file as PDF/DOC/etc compatible you have to conform the chosen file format. The same about reading - you should understand which portions of raw byte array are responsible for what.

In common, this task named as "parsing" or "serialization". And it's a good idea to use one of existing parsers for particular file format instead of reinventing the wheel. Moreover, some file formats can be patent-pending so you may be not allowed to deal with it without license purchase.

Some clues so far:

There are some libraries available on the web now(the question is from 2013, maybe that time there weren't many).

Apart from the links in selected answer, you can try PDFTron. It also supports new features, eg. Linearization.

Here is one of their samples is -> https://www.pdftron.com/documentation/samples/cpp/TextExtractTest

(That program itself contains 4 if blocks, with slightly different features of the library/SDK, to try)

There should be more, search on the web for PDF parsing libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM