rastertopdf: Fixed handling of empty input
@@ -1305,7 +1305,7 @@ int main(int argc, char **argv)
{
char *outformat_env = NULL;
OutFormatType outformat; /* Output format */
- int fd, Page;
+ int fd, Page, empty = 1;
struct pdf_info pdf;
FILE * input = NULL;
cups_raster_t *ras; /* Raster stream for printing */
@@ -1400,20 +1400,6 @@ int main(int argc, char **argv)
// Process pages as needed...
Page = 0;
- // Create PDF file
- if (create_pdf_file(&pdf, outformat) != 0)
- die("Unable to create PDF file");
-
- struct stat buf;
- fstat(fd, &buf);
- int size = buf.st_size;
- if(size <= 4)
- {
- close_pdf_file(&pdf);
- cupsRasterClose(ras);
- return 0;
- }
-
/* Get PCLm attributes from PPD */
if (ppd && outformat == OUTPUT_FORMAT_PCLM)
{
@@ -1497,6 +1483,14 @@ int main(int argc, char **argv)
while (cupsRasterReadHeader2(ras, &header))
{
+ if (empty)
+ {
+ empty = 0;
+ // We have a valid input page, so create PDF file
+ if (create_pdf_file(&pdf, outformat) != 0)
+ die("Unable to create PDF file");
+ }
+
// Write a status message with the page number
Page ++;
fprintf(stderr, "INFO: Starting page %d.\n", Page);
@@ -1526,6 +1520,13 @@ int main(int argc, char **argv)
die("Failed to convert page bitmap");
}
+ if (empty)
+ {
+ fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n");
+ cupsRasterClose(ras);
+ return 0;
+ }
+
close_pdf_file(&pdf); // will output to stdout
if (colorProfile != NULL) {
