Pb converting TIFF to PDF

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
Posts: 1
Joined: 2016-02-05T03:42:31-07:00
Authentication code: 1151

Pb converting TIFF to PDF

Post by lguyot » 2016-02-05T04:08:02-07:00

Hi There,

I must convert a lot of TIFF (from 1 to 994) in the same directory into a unique PDF.
The PDF must be PDFA.
The TIFF are black and white with density 200x200, resolution 1650x2300 and the average size of the TIFF is 30ko.
When I convert them, I think all are loaded in memory and the memory usage is huge.
For 200 TIFF the memory usage is about 1GB.

I use 'Magick.NET-\net20'

Here is my code :

Code: Select all

                using (MagickImageCollection images = new MagickImageCollection()) {
                    MagickReadSettings settings = new MagickReadSettings();
                    settings.Density = new PointD(200);
                    settings.UseMonochrome = true;

                    foreach (string file in Directory.GetFiles(rep, "*.tiff")) {
                        images.Add(new MagickImage(file, settings));

                    using (FileStream fs = new FileStream(rep + @"\_Result.pdf", FileMode.Create)) {
                        images.Write(fs, MagickFormat.Pdfa);
How could I improved the memory usage ?

I try to define :
ResourceLimits.Memory = 512000000;
To limit to about 512MB but it not works (I try different values from 1 to 512000000 whithout any effect)

If there is no solution to improive memory usage, how can i load the first TIFF, create the PDF, then load the second add it to the PDF, ... ?

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

Re: Pb converting TIFF to PDF

Post by snibgo » 2016-02-05T04:29:55-07:00

IM is not the ideal tool for this. 1650*2300*994 = 4 giga-pixels. Using IM v6 at Q16, we need 8 bytes per pixel, so 32 GB of memory.

IM v7 at Q8 for grayscale may need only 1 byte/pixel (I haven't verified this), so that is more reasonable.

The common utility tiff2pdf apparently can't handle multiple input tiff files, but I expect that some simple utility can.

EDIT: tiffcp can take multiple tiff inputs, creating one tiff output file without massive memory use, so perhaps tiffcp followed by tiff2pdf is a solution.
snibgo's IM pages: im.snibgo.com

Post Reply