Skip to content

Instantly share code, notes, and snippets.

@mtyaka
Last active February 3, 2017 20:59
Show Gist options
  • Save mtyaka/6267472 to your computer and use it in GitHub Desktop.
Save mtyaka/6267472 to your computer and use it in GitHub Desktop.
Patches poppler's pdftocairo to be able to set jpeg quality parameter. Tested with pdftocairo 0.22.5.
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index bf7072c..743016d 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -99,6 +99,7 @@ static GBool mono = gFalse;
static GBool gray = gFalse;
static GBool transp = gFalse;
static GooString icc;
+static int jpegQuality = -1;
static GBool level2 = gFalse;
static GBool level3 = gFalse;
@@ -127,6 +128,8 @@ static const ArgDesc argDesc[] = {
#if ENABLE_LIBJPEG
{"-jpeg", argFlag, &jpeg, 0,
"generate a JPEG file"},
+ {"-jpegquality", argInt, &jpegQuality, 0,
+ "set JPEG quality (0 - 100)"},
#endif
#if ENABLE_LIBTIFF
{"-tiff", argFlag, &tiff, 0,
@@ -293,9 +296,9 @@ void writePageImage(GooString *filename)
} else if (jpeg) {
#if ENABLE_LIBJPEG
if (gray)
- writer = new JpegWriter(JpegWriter::GRAY);
+ writer = new JpegWriter(jpegQuality, false, JpegWriter::GRAY);
else
- writer = new JpegWriter(JpegWriter::RGB);
+ writer = new JpegWriter(jpegQuality, false, JpegWriter::RGB);
#endif
} else if (tiff) {
#if ENABLE_LIBTIFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment