README.StdoutWinFix [1999-09-18] This update fixes a bug that affects Windows 95/98/NT platforms only when writing the PDF output to "stdout" (standard output). If you are on other platforms, this update is optional. ## PROBLEM: Symptoms of the problem are mulformed or damaged PDF files that occur only when the output is sent directly to stdout instead of to a file. Files created by redirection of stdout (by "> file") are also affected by this bug. E.g., output via cpdf_savePDFmemoryStreamToFile("testfile.pdf"); works fine, but cpdf_savePDFmemoryStreamToFile("-"); generates bad PDF files. ## CAUSE: It is just plain awkward to make Windows do binary I/O, especially with stdin/stdout. ## FIX: Please replace cpdfMemBuf.c and cpdfInit.c in the source directory with the one enclosed in this package. Versions for both ClibPDF 1.10-7e and v2.00-r1 are available in separate directories. And then recompile and reinstall the library. If you use the following scheme to perform PDF output: bufPDF = cpdf_getBufferForPDF(pdf, &length); printf("Content-Type: application/pdf%c", 10); printf("Content-Length: %d%c%c", length, 10, 10); fwrite((void *)bufPDF, 1, (size_t)length, stdout); /* Send PDF now */ Change that to: #if defined(_WIN32) || defined(WIN32) #include extern int setmode(int filenum, int mode); #endif .... bufPDF = cpdf_getBufferForPDF(pdf, &length); setmode(fileno(stdout), O_BINARY); /* add this line to change stdout to binary */ printf("Content-Type: application/pdf%c", 10); printf("Content-Length: %d%c%c", length, 10, 10); fwrite((void *)bufPDF, 1, (size_t)length, stdout); /* Send PDF now */