stream .pdf error [duplicate]
Possible Duplicate:
convert a file (.txt,.pdf..) into a stream file
std::string fil= "/home/sensor.pdf";
std::ifstream t(fil.c_str());
if (t)
{
string res;
string line;
while (getline(t, line, '\n'))
{
res=res+line;
}
std::string p;
p=(((reinterpret_cast<const unsigned char *> (res.c_str())),res.size()));
std::string f_data=p;
char *token = strtok( const_cast<开发者_开发百科char*>(fil.c_str() ), "/" );
std::string name;
std::vector<int> values;
while ( token != NULL )
{
name=token;
token = strtok( NULL, "/" );
}
std::strig f_name=name;
}
When I try to load the .pdf file I have an error "unable to read. PDF IS DAMAGED". WHY? This code works for .txt files and .cpp files. I've tested it. I am currently working in ubuntu c++ code. I've also used the base_64 encode/decode because this was the request.
Try this: http://sourceforge.net/projects/libharu/
I saw it recommended in a few different places, including a couple different SO questions - but all they gave was the link.
It's a free, open-souce library for PDF reading. It probably isn't as easy as you want, but I think its as easy as you're gonna get and its free.
It's also multi-platform so should work on UNIX and windows.
Try opening with:
ifstream file ("/home/sensor.pdf", ios::in|ios::binary);
精彩评论