Converting PDF to tif (Images are getting distorted)

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
srace
Posts: 6
Joined: 2019-10-21T07:37:24-07:00
Authentication code: 1152

Converting PDF to tif (Images are getting distorted)

Post by srace » 2019-10-21T08:07:13-07:00

Hello Friends,

I am new member to this group hope I will get the solution for my problem.

I am converting PDF file to MULTI-page tif images and I am facing some issues while converting ONLY certain pdf's to tiff images the converted images are getting distorted adding a black bars to right which is covering almost 30-40% (right side of image) of the converted image file.

Version details: <PackageReference Include="Magick.NET-Q8-x64" Version="7.14.4" />

Code Settings:

Code: Select all

var settings = new MagickReadSettings
            {
                Density = new Density(150, 150),
                Compression = CompressionMethod.LZW
            };

using (var tif = new MagickImageCollection())
                {
                    foreach (var page in pages)
                    {
                        page.Depth = 4;
                        page.Format = MagickFormat.Tif;
                        page.Alpha(AlphaOption.Remove);
                        tif.Add(page);
                    }

                    image = tif.ToByteArray(MagickFormat.Tif);
                }
Any help from group or setting which I can try to address my distorted issues. Thank you!

User avatar
fmw42
Posts: 25662
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDF to tif (Images are getting distorted)

Post by fmw42 » 2019-10-21T09:49:23-07:00

Post an example PDF that shows this behavior to some free hosting site and put the URL here.

srace
Posts: 6
Joined: 2019-10-21T07:37:24-07:00
Authentication code: 1152

Re: Converting PDF to tif (Images are getting distorted)

Post by srace » 2019-10-21T12:51:56-07:00

Thank you @fmw42 below is the link for the converted image file from pdf
https://ibb.co/xY27RtL

User avatar
dlemstra
Posts: 1576
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting PDF to tif (Images are getting distorted)

Post by dlemstra » 2019-10-21T13:16:10-07:00

Which version of Ghostscript are you using? Could be an issue in that library.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

User avatar
fmw42
Posts: 25662
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDF to tif (Images are getting distorted)

Post by fmw42 » 2019-10-21T13:24:27-07:00

Post a link to the input PDF, so we can see if it is a problem or if it is your version of Ghostscript as dlemstra suggested. What is your version of Ghostscript?

srace
Posts: 6
Joined: 2019-10-21T07:37:24-07:00
Authentication code: 1152

Re: Converting PDF to tif (Images are getting distorted)

Post by srace » 2019-10-21T17:39:18-07:00

I am using gs 9.27..

I don't see any issues with pdf its opens fine with adobe or any other pdf extensions. Its not happening with all pdf's that makes tough to debug the issue

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting PDF to tif (Images are getting distorted)

Post by snibgo » 2019-10-21T18:02:06-07:00

Ghostscript 9.27 may be the problem.

If you post a link to the PDF, we might narrow the problem down to Ghostscript, or ImageMaick, or Magick.NET, or your code.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25662
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDF to tif (Images are getting distorted)

Post by fmw42 » 2019-10-21T18:55:41-07:00

I suggest you downgrade Ghostscript to 9.25, 9.24 or 9.23. I have heard of issue with 9.26 and 9.27.

srace
Posts: 6
Joined: 2019-10-21T07:37:24-07:00
Authentication code: 1152

Re: Converting PDF to tif (Images are getting distorted)

Post by srace » 2019-10-24T07:11:32-07:00

Thank you everyone for the replies. I was able to resolve the issue after upgrading to version 7.12.0 but after that having new issue everything works fine on Windows and Mac OS and when I deployed the code on my dev server which running on linux OS getting the below error message. Can you one please suggest how can I resolve this issue on Linux OS

Below are code changes which I have done from my previous post on the top:

var settings = new MagickReadSettings
{
Density = new Density(150, 150),
Compression = CompressionMethod.LZW,
UseMonochrome = true
};

var settings = new MagickReadSettings
{
Density = new Density(150, 150),
Compression = CompressionMethod.LZW,
UseMonochrome = true
};

using (var pages = new MagickImageCollection())
{
// Add all the pages of the pdf file to the collection
pages.Read(pdf, settings);

using (var tif = new MagickImageCollection())
{
foreach (var page in pages)
{
page.Depth = 4;
page.Format = MagickFormat.Tif;
page.Alpha(AlphaOption.Remove);
tif.Add(page);
}

image = tif.ToByteArray(MagickFormat.Tif);
}
}

Error Message getting ONLY on Linux OS:

[19:39:02 ERR] An unhandled exception has occurred: FailedToExecuteCommand `'fs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pbmraw' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r150x150' -dUseCIEColor '-sOutputFile=/tmp/magick-1or6UExEpALs7%d' '-f/tmp/magick-1PoPoTSWPfA1H' '-f/tmp/magick-1-eE9459XgqAi'' (1) @ error/pdf.c/InvokePDFDelegate/291
ImageMagick.MagickDelegateErrorException: FailedToExecuteCommand `'fs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pbmraw' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r150x150' -dUseCIEColor '-sOutputFile=/tmp/magick-1or6UExEpALs7%d' '-f/tmp/magick-1PoPoTSWPfA1H' '-f/tmp/magick-1-eE9459XgqAi'' (1) @ error/pdf.c/InvokePDFDelegate/291
at ImageMagick.MagickImageCollection.NativeMagickImageCollection.ReadBlob(MagickSettings settings, Byte[] data, Int32 offset, Int32 length)
at ImageMagick.MagickImageCollection.AddImages(Byte[] data, Int32 offset, Int32 count, MagickReadSettings readSettings, Boolean ping)

snibgo
Posts: 12289
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting PDF to tif (Images are getting distorted)

Post by snibgo » 2019-10-24T07:38:36-07:00

srace wrote:FailedToExecuteCommand `'fs'
What is the "fs" command? When reading a PDF, ImageMagick should execute Ghostscript, possibly "gs". Has your delegates.xml file changed? Perhaps been badly edited?
snibgo's IM pages: im.snibgo.com

srace
Posts: 6
Joined: 2019-10-21T07:37:24-07:00
Authentication code: 1152

Re: Converting PDF to tif (Images are getting distorted)

Post by srace » 2019-10-24T07:46:55-07:00

I am not sure about delegates.xml. I haven't touched that file. I just updated to version 7.12.0 and deployed the code in Dev which is running on Linux OS getting the above error message. I am not having any issues when I run locally which is on Windows and I even tested on Mac OS which also not having any issues. Not sure why its failing on Linux OS

User avatar
fmw42
Posts: 25662
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDF to tif (Images are getting distorted)

Post by fmw42 » 2019-10-24T09:16:14-07:00

There is no version 7.12 of Imagemagick? Current version is 7.0.8.68.

What did you upgrade? Is that a version of Magick.NET?

What do you get from

Code: Select all

magick -version
if on IM 7

or

Code: Select all

convert -version
if on IM 6

srace
Posts: 6
Joined: 2019-10-21T07:37:24-07:00
Authentication code: 1152

Re: Converting PDF to tif (Images are getting distorted)

Post by srace » 2019-10-24T10:58:17-07:00


User avatar
dlemstra
Posts: 1576
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting PDF to tif (Images are getting distorted)

Post by dlemstra » 2019-10-24T12:21:25-07:00

It appears that there is a typo in the built-in configuration that is used by Magick.NET on Linux. This will be fixed in the next release but it might be a while before that new release is available.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Post Reply