Skip to content

Commit

Permalink
Restrict PDF output to 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Aug 10, 2024
1 parent 90fb06f commit 10bf653
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ For debugging. Similar to [rasterview](https://github.com/michaelrsweet/rastervi
## pdf2printable
Takes a PDF document and makes it suitable for printing, by:
- rotate and scale to fit as needed to a desired page size
- convert to PDF 1.5, Postscript 2 or PWG/URF raster
- convert to PDF 1.7¹, Postscript level 2 or PWG/URF raster

1. PDF 1.5 if using Cairo < 1.18.

## baselinify
Takes a JPEG and losslessly repacks it to the baseline ecoding profile, keeping only JFIF and Exif headers.
Expand Down
1 change: 1 addition & 0 deletions lib/libfuncs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FUNC(cairo, cairo_surface_t*, cairo_ps_surface_create_for_stream, cairo_write_fu
FUNC(cairo, void, cairo_ps_surface_restrict_to_level, cairo_surface_t*, cairo_ps_level_t);
FUNC(cairo, cairo_surface_t*, cairo_image_surface_create, cairo_format_t, int, int);
FUNC(cairo, cairo_surface_t*, cairo_pdf_surface_create_for_stream, cairo_write_func_t, void*, double, double);
FUNC(cairo, void, cairo_pdf_surface_restrict_to_version, cairo_surface_t*, cairo_pdf_version_t);
FUNC(cairo, void, cairo_pdf_surface_set_metadata, cairo_surface_t*, cairo_pdf_metadata_t, const char*);
FUNC(cairo, void, cairo_translate, cairo_t*, double, double);
FUNC(cairo, void, cairo_scale, cairo_t*, double, double);
Expand Down
6 changes: 6 additions & 0 deletions lib/pdf2printable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ Error pdf_to_printable(std::string inFile, WriteFun writeFun, const PrintParamet
surface = cairo_pdf_surface_create_for_stream(bytestream_writer, &outBts,
params.getPaperSizeWInPoints(),
params.getPaperSizeHInPoints());
#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 18, 0)
// Cairo is robust against setting "too new" versions - pretend we know about 1.7 even if we don't
#define CAIRO_PDF_VERSION_1_7 (cairo_pdf_version_t)(CAIRO_PDF_VERSION_1_5 + 2)
#endif
// 1.7 aka ISO32000 is the recommended version according to PWG5100.14
cairo_pdf_surface_restrict_to_version(surface, CAIRO_PDF_VERSION_1_7);
cairo_pdf_surface_set_metadata(surface, CAIRO_PDF_METADATA_CREATOR, PDF_CREATOR);
}
else if(params.format == PrintParameters::Postscript)
Expand Down

0 comments on commit 10bf653

Please sign in to comment.