Hello,
i've written a little program which opens an existing PDF, looks for three bookmarks i wish to remove an, removes it and saves the file.
It works, but i have two problems.
my file size was 3,5mb and after saving its about 8mb.
it only removes 2 of 3 bookmarks.
That was one of my debugging codes, it works but may you have to change some things
Code:
#region Member Variablen
string path = @args[0];
//string path = @"C:\Users\chwe\Desktop\test.pdf";
PdfDocument pdfDocument = PdfReader.Open(path, PdfDocumentOpenMode.Modify);
List<PdfOutline> unpleasantBookmarks = new List<PdfOutline>();
#endregion
#region Debug 1
Console.WriteLine("Steht in der Quell-Datei:");
Console.WriteLine(pdfDocument.Outlines.Count);
for (int i = 0; i < pdfDocument.Outlines.Count; i++)
{
Console.WriteLine(pdfDocument.Outlines[i].Title.ToString());
}
#endregion
#region Programm
foreach (PdfOutline item in pdfDocument.Outlines)
{
if (item.Title.Contains("Seitenbaum"))
{
unpleasantBookmarks.Add(item);
}
}
var outlines = pdfDocument.Outlines.ToList();
outlines.ForEach(x => pdfDocument.Outlines.Remove(x));
pdfDocument.Outlines.Clear();
pdfDocument.Outlines.Add(unpleasantBookmarks.First());
PdfDocument test = (PdfDocument)pdfDocument.Clone();
test.Outlines.Add(unpleasantBookmarks.First());
test.Save(path);
#endregion
#region Debug2
Console.WriteLine("Steht in der neuen Datei:");
Console.WriteLine(pdfDocument.Outlines.Count);
for (int i = 0; i < pdfDocument.Outlines.Count; i++)
{
Console.WriteLine(pdfDocument.Outlines[i].Title.ToString());
}
#endregion
//pdfDocument.Save(path);
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
could you please help me?
thanks