}
n = fread_or_die(buf, 1, sizeof(buf) - 1, file);
+ if (!n){
+ _log("Input is empty, outputting empty file.\n");
+ return 1;
+ }
buf[n] = '\0';
type = guess_file_type(buf, n, &startpos);
/* We do not use any JCL preceeded to the inputr data, as it is simply
static int pdf_count_pages(const char *filename)
{
char gscommand[CMDLINE_MAX];
- char output[31] = "";
+ char output[63] = "";
int pagecount;
size_t bytes;
if (!pd)
rip_die(EXIT_STARVED, "Failed to execute ghostscript to determine number of input pages!\n");
- bytes = fread_or_die(output, 1, 31, pd);
+ bytes = fread_or_die(output, 1, 63, pd);
pclose(pd);
if (bytes <= 0 || sscanf(output, "PageCount: %d", &pagecount) < 1)
- pagecount = -1;
+ {
+ if(bytes <= 0 || sscanf(output, " **** Error: Too many pages in Page tree.\nPageCount: %d", &pagecount) < 1)
+ pagecount = -1;
+ }
return pagecount;
}
page_count = pdf_count_pages(filename);
- if (page_count <= 0)
+ if (page_count < 0)
rip_die(EXIT_JOBERR, "Unable to determine number of pages, page count: %d\n", page_count);
+ if (page_count == 0)
+ {
+ _log("No pages left, outputting empty file.\n");
+ return 1;
+ }
_log("File contains %d pages\n", page_count);
optionset_copy_values(optionset("header"), optionset("currentpage"));
pid_t rendererpid = 0;
FILE *rendererhandle = NULL;
+ int empty = 1;
int retval;
dstr_t *tmp = create_dstr();
/* No renderer running, start it */
dstrcpy(tmp, psheader->data);
dstrcat(tmp, psfifo->data);
+ empty = 0;
get_renderer_handle(tmp, &rendererhandle, &rendererpid);
/* psfifo is sent out, flush it */
dstrclear(psfifo);
} while ((maxlines == 0 || linect < maxlines) && more_stuff != 0);
+ if (empty)
+ {
+ _log("No pages left, outputting empty file.\n");
+ return;
+ }
+
/* Some buffer still containing data? Send it out to the renderer */
if (more_stuff || inheader || !isempty(psfifo->data)) {
/* Flush psfifo and send the remaining data to the renderer, this