1
I’m making a program to convert and concatenate files. I wanted, after converting the PDF files into TIFF, to combine them into a single multi-page TIFF file.
I’ve been looking for a long time and I still haven’t found any code that worked like I wanted.
Then I convert the PDF files to TIFF and store them in a temporary folder. Then I have an array of strings that will contain all these files from the temporary folder (through a function GetFiles()
).
I want you to combine the files from that array into a single multi-page TIFF. Someone has the solution or can direct me to it?
EDIT - My code:
Convert PDF to TIFF (with Imagemagick)
public void PDFToTIFF(string output)
{
MagickReadSettings settings = new MagickReadSettings();
settings.Density = new Density(500);
string[] ficheiros = GetFiles();
foreach (string fich in ficheiros)
{
string fichwithout = Path.GetFileNameWithoutExtension(fich);
string path = Path.Combine(output, fichwithout);
using (MagickImageCollection images = new MagickImageCollection())
{
images.Read(fich);
foreach (MagickImage image in images)
{
settings.Height = image.Height;
settings.Width = image.Width;
image.Format = MagickFormat.Tiff;
image.Write(path + ".tiff");
}
}
}
}
Function GetFiles()
:
public string[] GetFiles()
{
if (!Directory.Exists(@"C:\Users\srodrigues\Documents\ProjetoPAP-SofiaRodrigues\Main\temporario"))
{
Directory.CreateDirectory(@"C:\Users\srodrigues\Documents\ProjetoPAP-SofiaRodrigues\Main\temporario");
}
DirectoryInfo dirInfo = new DirectoryInfo(@"C:\Users\srodrigues\Documents\ProjetoPAP-SofiaRodrigues\Main\temporario");
FileInfo[] fileInfos = dirInfo.GetFiles("*.pdf");
ArrayList list = new ArrayList();
foreach (FileInfo info in fileInfos)
{
if(info.Name != caminho1)
{
// HACK: Just skip the protected samples file...
if (info.Name.IndexOf("protected") == -1)
list.Add(info.FullName);
}
}
return (string[])list.ToArray(typeof(string));
}
Thanks in advance.
Maybe it is easier to merge before the conversion, to convert only one file later not? Take a look at this topic: https://stackoverflow.com/questions/808670/combine-two-or-more-pdfs
– Victor Laio
I already have the code to merge PDF. I want to convert to TIFF and merge these files...
– Sofia Rodrigues
Good! It would be possible to provide your code or what you have already done to have a base and help you?
– Mikev
Hello, I’ve already included the code I’ve already done. There’s something else I can improve on my question since I have -2 negative votes @Mikev?
– Sofia Rodrigues
I think the question is a good one now. In the case of this issue I do not think that negative would be necessary, I think just asking the rest of the information that was 'missing' and waiting would be enough (+1). But do what, a lot of people on the site and many do not think so and are even a little boring.
– George Wurthmann
I think that instead of immediately denying, proposing amendments that will help to improve the issue, helps those who ask the question how to improve their issues, and helps those who want to help, to better understand the problem.
– Sofia Rodrigues