hi guys!

today i tried file writing through VC++ 2010. suddenly a point stroke in my mind to create a file which may not be read by notepad or it gives error or some wrong output as it is mostly seen on opening a pdf file in notepad. for this i tried different formats, (for example: pdf) but this format is also very easy for notepad to read. even the acrobat reader is not reading this file. if anyone can help me, please let me know how to create a pdf file through VC++ or any other format, but the condition is that, file reading must not be possible by notepad.

thanks

Dani AI

Generated

Short version: the file being opened by Notepad is almost certainly plain text that was simply renamed. As pointed out, changing an extension does not change the bytes inside a file; Notepad will open any file and display raw characters. Acrobat failing to open the same file means it is not a valid PDF document — a real PDF has a specific structure (header like %PDF-1.x, objects, a cross-reference table and %%EOF) and is produced by a PDF generator or library, not by merely renaming a .txt.

Two practical routes depending on the goal:

  • Produce a genuine PDF that Acrobat can open: use a PDF library or SDK (libharu, PoDoFo, MuPDF/PDFium or a commercial SDK) or export via a print-to-PDF driver. That produces the correct binary/ASCII mix required by the PDF spec; Notepad can still display raw bytes but will not render the document.
  • Make a file unreadable as plain text: write binary data or encrypt/encode the contents. As suggested, writing structures in binary prevents casual reading; for confidentiality, use real encryption (not ad-hoc obfuscation).

Minimal VC++ example that writes binary (and demonstrates simple XOR obfuscation — not secure for real secrets):

#include <fstream>
#include <string>

int main() {
    std::ofstream out("out.bin", std::ios::binary);
    if (!out) return 1;
    std::string plain = "Secret text line\n";
    unsigned char key = 0xAA; // simple obfuscation — not a secure encryption
    for (size_t i = 0; i < plain.size(); ++i) {
        unsigned char enc = static_cast<unsigned char>(plain[i]) ^ key;
        out.put(static_cast<char>(enc));
    }
    return 0;
}

Quick checks and cautions: verify a PDF with a hex editor (look for %PDF-1. at the start and %%EOF at the end), open with Acrobat to confirm validity, and prefer standard tools for password-protecting or encrypting PDFs if confidentiality is required. Simple obfuscation only stops casual viewing in Notepad; real protection requires standard cryptography or PDF password features.

Recommended Answers

All 3 Replies

Ah... How about using .doc format? Don't think notepad reads doc or docx files. I didn't even know it read pdf..
-FH

You're probably creating a text file, but then you're just naming it like a PDF. Just changing the file extension doesn't change the data inside the file, it's still just text. That would be like calling your chicken a pig, slaughtering it, and expecting it to taste like pork.

I didn't even know it read pdf..

It doesn't. It can, however, read a text file renamed so it says ".PDF" at the end.

To continue Tumlee's point if you want the data to be in an unbeadable form than you are going to need to learn how to create a data structure and then write the structure to file in binary. One cavet of this is that text is still text in binary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.