C ++读取PDF文件 [英] C++ Reading a PDF file

查看:1293
本文介绍了C ++读取PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码来阅读PDF文件的内容:

I'm using the following code to read the content of a PDF file:

string document;
FILE * f;
f = fopen ( path , "rb");
unsigned char buffer[1024];
while(!feof(f)){   
    int bytes = fread(buffer,1,1024,f);
    for(int i = 0; i < bytes; i++){
        document += buffer[i];
        cout << buffer[i];
    }
}
fclose ( f );

问题是,字符与我在文本编辑器中打开文件时不一样。
例如,此文件
files.flashfan.ch/file.png

The problem is, that the chars are not the same as when I open the file in a text editor. For example this file files.flashfan.ch/file.png

导致此输出:
files.flashfan.ch /output.png

results in this output: files.flashfan.ch/output.png

如何读取文件,以使字符与编辑器中的字符完全相同?
我想解析PDF文件,但没有原始的字符我不能这样。
我测试了这个文件的代码(它不是一个PDF文件,只是其中的一部分,所以你不能显示它):

How can I read the file, so that the chars are exactly the same as in the editor? I want to parse PDF files, but without the original chars I cant to this. I've testet the code with this file (its not a PDF file, just a part of one, so you can't display it):

PDF Head.pdf

感谢您的帮助!

推荐答案

我没有看到您读取文件的任何错误我的Linux框,当我重定向输出到一个文件)。也许问题是在控制角色搞砸与控制台。尝试输出到文件并与输入进行比较。

I don't see any errors in the way you read the file (the code actually works on my Linux box when I redirect the output to a file). Probably the issue is in the control characters that mess up with the console. Try to output to a file and compare with the input.

这篇关于C ++读取PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆