1
I am converting PDF to TIFF and converting page by page to a temporary folder and at the end I will fetch those files to join them as in the original file. My code is as follows: (I used what is in my reply question):
string pastapdf = AppDomain.CurrentDomain.BaseDirectory + "temporario\\" + Path.GetFileNameWithoutExtension(e[i]);
Directory.CreateDirectory(pastapdf);
string pdfFile = Path.Combine(pastapdf, e[i]);
for (int h = 0; h <= (pdfReader.NumberOfPages - 1); h++)
{
using (var document = PdfiumViewer.PdfDocument.Load(pdfFile))
{
var image = document.Render(h, dpi, dpi, true);
image.Save(pastapdf + "\\" + Path.GetFileNameWithoutExtension(e[i]) + "_" + h.ToString() + ".tif", ImageFormat.Tiff);
image.Dispose();
}
}
string save = output + "\\" + Path.GetFileNameWithoutExtension(e[i]) + ".tif";
string[] tifffiles = GetFiles(pastapdf, "*.tif");
var finalfiles = tifffiles.OrderBy(f =>
new string(f.Where(char.IsLetter).ToArray())).ThenBy(f => {
int number; if (int.TryParse(new string(f.Where(char.IsDigit).ToArray()), out number))
return number; return -1; } ).ToList(); //código LINQ para ordenar
JoinTiffLZW(finalfiles.ToArray(), save);
Invoke(new Action(() => { pbar.PerformStep(); pdfReader.Dispose(); }));
You should do: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.... And it’s doing: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9....
My question is if anyone can tell me another way to sort the list or what’s wrong with my code?
TEST
I uploaded a 40-page PDF. I divided and converted them all, then I fetched the files:
And then I should order with LINQ, but the result is this:
And it should be in the right order, so when I get everybody together, it’s the wrong order.
First thing: The VS update itself might not have caused this, only if you installed some framework and/or something related together, but that shouldn’t change. Until pq you would need to change the target framework you are using in your project, so it doesn’t seem to make sense. Other than that, it is impossible to happen what you comment on the question because the ordering is numerical, or you are testing with the wrong code block, or missing information in the question.
– Jéf Bueno
My tip for you is: Isolate the code and test with a pre-defined data set. Also, always leave a test case ready in your question - especially one that is failing, because then whoever wants to help you has a starting point.
– Jéf Bueno
@LINQ I thought it might be the update because before it was working. I will add more code to the question and I will test as you said.
– Sofia Rodrigues
Yes, quiet. This is a very normal mess, especially since the problem started to appear after updating. But do it, add more details that is better to try to help you.
– Jéf Bueno
@LINQ already added a test and changed the question.
– Sofia Rodrigues
I’ll write you a reply. Look, I realized that you already have a certain site time. After answering I will edit your question and format it and you use this question as formatting basis for your next questions, it may be?
– Jéf Bueno
@LINQ right, but what’s wrong with my question?
– Sofia Rodrigues
Let’s go continue this discussion in chat.
– Sofia Rodrigues
is ordering strings instead of numbers... values to sort are always between characters
_
and.
?– vik
@All right, you stay " name _0"
– Sofia Rodrigues