Skip to content

Commit

Permalink
Fix Poppler detection and debug logging for ipptransform (Issue #267)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Mar 20, 2023
1 parent 2fc9274 commit 9a26723
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tools/ipptransform.c
Original file line number Diff line number Diff line change
Expand Up @@ -3718,15 +3718,23 @@ xform_document(
// Xpdf and the one that comes with Poppler which forked from Xpdf in the
// v3.0 days. Unfortunately, the two commands have drifted apart so we need
// to determine *which* pdftoppm command is available...
if ((fp = popen("pdftoppm -v", "r")) != NULL)
#if _WIN32
if ((fp = _popen("pdftoppm -v", "r")) != NULL)
#else
if ((fp = popen("pdftoppm -v 2>&1", "r")) != NULL)
#endif // _WIN32
{
while (fgets(output, sizeof(output), fp))
{
if (strstr(output, "oppler"))
poppler = true;
}

#if _WIN32
_pclose(fp);
#else
pclose(fp);
#endif // _WIN32

fprintf(stderr, "DEBUG: Using %s version of pdftoppm.\n", poppler ? "Poppler" : "Xpdf");
}
Expand All @@ -3750,7 +3758,7 @@ xform_document(

fprintf(stderr, "DEBUG: Running \"%s\".\n", command);
#if _WIN32
if ((fp = popen(command, "rb")) == NULL)
if ((fp = _popen(command, "rb")) == NULL)
#else
if ((fp = popen(command, "r")) == NULL)
#endif // _WIN32
Expand Down Expand Up @@ -3784,14 +3792,20 @@ xform_document(
}

if (Verbosity)
{
header[strlen(header) - 1] = '\0';
fprintf(stderr, "DEBUG: '%s'\n", header);
}

// Now get the bitmap dimensions...
if (!fgets(header, sizeof(header), fp))
break;

if (Verbosity)
{
header[strlen(header) - 1] = '\0';
fprintf(stderr, "DEBUG: '%s'\n", header);
}

if (sscanf(header, "%u%u", &width, &height) != 2)
{
Expand Down Expand Up @@ -3840,6 +3854,7 @@ xform_document(

if (Verbosity)
{
header[strlen(header) - 1] = '\0';
fprintf(stderr, "DEBUG: '%s'\n", header);
fprintf(stderr, "DEBUG: width=%u, height=%u, bpp=%u, ystart=%u, yend=%u\n", width, height, bpp, ystart, yend);
}
Expand Down Expand Up @@ -3899,7 +3914,11 @@ xform_document(
}

// Close things out...
#if _WIN32
_pclose(fp);
#else
pclose(fp);
#endif // _WIN32

// Write a separator sheet as needed...
switch (options->separator_type)
Expand Down

0 comments on commit 9a26723

Please sign in to comment.