123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include <windows.h>
- #include <stdio.h>
- #define CUSTOM_FORMAT RegisterClipboardFormatA("Portable Document Format")
- int main(int argc, char* argv[])
- {
-
- const char* outputFile = "output.pdf";
- if(2 == argc)
- outputFile = argv[1];
-
- if (!OpenClipboard(NULL)) {
- printf("Failed to open clipboard.\n");
- return 1;
- }
-
- HANDLE hData = GetClipboardData(CUSTOM_FORMAT);
- if (!hData) {
- printf("Failed to get clipboard data.\n");
- CloseClipboard();
- return 1;
- }
-
- void* pdfData = GlobalLock(hData);
- if (!pdfData) {
- printf("Failed to lock global memory.\n");
- CloseClipboard();
- return 1;
- }
-
- size_t fileSize = GlobalSize(hData);
-
- FILE* file = fopen(outputFile, "wb");
- if (!file) {
- printf("Failed to open output file.\n");
- GlobalUnlock(hData);
- CloseClipboard();
- return 1;
- }
- fwrite(pdfData, 1, fileSize, file);
- fclose(file);
-
- GlobalUnlock(hData);
- CloseClipboard();
- printf("PDF binary data from clipboard saved to file: %s\n", outputFile);
- return 0;
- }
|