OpenPrinting / libcupsfilters

Apache License 2.0
7 stars 26 forks source link

Universal filter does not respect input pagesize #68

Open colinleroy opened 1 month ago

colinleroy commented 1 month ago

Hi,

When converting from PS to PDF using cfUniversalFilter, the input file's page size is lost and the output is US Letter regardless.

Minimal example:

/* Build with
 * gcc $(pkg-config --cflags libcupsfilters) main.c $(pkg-config --libs libcupsfilters) -o testps2pdf
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <cups/cups.h>
#include <cupsfilters/filter.h>

int main(int argc, char *argv[]) {
  int input, output, status;
  cf_filter_data_t filter_data;
  cf_filter_universal_parameter_t filter_params;

  input = open("test.ps", O_RDONLY);
  if (input > 0) {
    output = open ("test.pdf", O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
    if (output > 0) {
      memset(&filter_data, 0, sizeof filter_data);
      memset(&filter_params, 0, sizeof filter_params);
      filter_data.logfunc = cfCUPSLogFunc;
      filter_data.printer = NULL;
      filter_data.content_type = strdup("application/postscript");
      filter_data.final_content_type = strdup("application/pdf");
      filter_data.copies = 1;
      status = cfFilterUniversal(input, output, 1, &filter_data, &filter_params);
      printf("Printer: Filter status %d\n", status);
      close(output);
    } else {
      close(input);
      return -1;
    }
    close(input);
  } else {
    return -1;
  }
  return 0;
}

Output:

DEBUG: cfFilterUniversal: Converting from application/postscript to application/pdf
DEBUG: cfFilterUniversal: Final output format for job: application/pdf
DEBUG: cfFilterUniversal: Adding ghostscript to chain
INFO: cfFilterChain: Running filter: ghostscript
INFO: cfFilterChain: ghostscript (PID 707462) started.
DEBUG: cfFilterGhostscript: Output format: PDF
DEBUG: cfFilterGhostscript: Copying input to temp file "/tmp/acb86672ad480"
DEBUG: cfFilterGhostscript: Input format: PostScript
DEBUG: Color space requested: Default
DEBUG: Final output format: CUPS Raster
WARN: Could not determine the output page dimensions, falling back to US Letter format
WARN: cfFilterPDFToPDF: Could not determine the width of the left margin, falling back to 18 pt/6.35 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the bottom margin, falling back to 36 pt/12.7 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the right margin, falling back to 18 pt/6.35 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the top margin, falling back to 36 pt/12.7 mm
DEBUG: Print rendering intent = 
DEBUG: Color Manager: Calibration Mode/Off
DEBUG: Color Manager: Invalid printer name.
DEBUG: Color Manager: Invalid input - Unable to find profile.
DEBUG: cfFilterGhostscript: Ghostscript using Any-Part-of-Pixel method to fill paths.
DEBUG: cfFilterGhostscript: Ghostscript command line: gs -dQUIET -dSAFER -dNOPAUSE -dBATCH -dNOINTERPOLATE -dNOMEDIAATTRS -dUsePDFX3Profile -sstdout=%stderr -sOutputFile=%stdout -sDEVICE=pdfwrite -dDoNumCopies -dShowAcroForm -dCompatibilityLevel=1.3 -dAutoRotatePages=/None -dAutoFilterColorImages=false -dNOPLATFONTS -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/default -dColorConversionStrategy=/LeaveColorUnchanged -r300x300 -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sOutputICCProfile=srgb.icc -c -f -_
DEBUG: cfFilterGhostscript: Started Ghostscript (PID 707466)
DEBUG: cfFilterGhostscript: Started logging (PID 707467)
DEBUG: cfFilterGhostscript: Input data feed completed
DEBUG: cfFilterGhostscript: Ghostscript (PID 707466) exited with no errors.
DEBUG: cfFilterGhostscript: Logging (PID 707467) exited with no errors.
DEBUG: cfFilterChain: ghostscript completed with status 0.
INFO: cfFilterChain: ghostscript (PID 707462) exited with no errors.
Printer: Filter status 0