Last active
February 12, 2021 09:40
-
-
Save debdutdeb/a01842bef8b759f108e0f709bd36ee59 to your computer and use it in GitHub Desktop.
This is going to be so helpful in the compress-pdf application :D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __COMPRESS_H__ | |
#define __COMPRESS_H__ | |
#include "iapi.h" | |
#include <string> | |
#include <cstring> | |
#include <iostream> | |
#include <errno.h> | |
static int GSDLLCALL gs_stdout | |
(void *caller_handle, const char* buf, int len) | |
{ | |
return len; | |
} | |
static int GSDLLCALL gs_stderr | |
(void *caller_handle, const char* buf, int len) | |
{ | |
return len; | |
} | |
static int GSDLLCALL gs_stdin | |
(void *caller_handle, char *buf, int len) | |
{ | |
return len; | |
} | |
namespace PDFTool { | |
int compress (char*); | |
} | |
int PDFTool::compress | |
(char *input_file, char *output_file) | |
{ | |
void *gs = nullptr; | |
char *gsargs[] = { | |
"", | |
"-sDEVICE=pdfwrite", | |
"-dPDFSETTINGS=/ebook", | |
"-dNOPAUSE", | |
"-dQUIET", | |
"-dBATCH", | |
"-sOutputFile=\"output.pdf\"", | |
input_file | |
}; | |
int ret_code = gsapi_new_instance (&gs, NULL); | |
if (ret_code < 0) | |
return EXIT_FAILURE; | |
gsapi_set_stdio (gs, gs_stdin, gs_stdout, gs_stderr); | |
ret_code = gsapi_set_arg_encoding (gs, GS_ARG_ENCODING_UTF8); | |
if (ret_code) | |
ret_code = gsapi_init_with_args (gs, 8, gsargs); | |
gsapi_delete_instance(gs); | |
gsapi_exit(gs); | |
return ret_code; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment