PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 9:22 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: PDF Size and Bookmarks
PostPosted: Wed Jun 19, 2019 8:15 am 
Offline

Joined: Wed Jun 19, 2019 7:26 am
Posts: 3
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 :)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 19, 2019 8:53 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!
chwe wrote:
my file size was 3,5mb and after saving its about 8mb.
Without seeing those two files I can only speculate what might cause the increase in size.
Would you share them?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 19, 2019 9:18 am 
Offline

Joined: Wed Jun 19, 2019 7:26 am
Posts: 3
Thomas Hoevel wrote:
Hi!
chwe wrote:
my file size was 3,5mb and after saving its about 8mb.
Without seeing those two files I can only speculate what might cause the increase in size.
Would you share them?


please look at your pm


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 01, 2019 5:57 am 
Offline

Joined: Wed Jun 19, 2019 7:26 am
Posts: 3
Hello Thomas,

did you forget me?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 121 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group