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-7.0.0.0022-Q8-x64\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));
//images.Add(file);
}
using (FileStream fs = new FileStream(rep + @"\_Result.pdf", FileMode.Create)) {
images.Write(fs, MagickFormat.Pdfa);
fs.Flush();
fs.Close();
}
}
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, ... ?