Can't remove Content

Help
Pedro Rosa
2012-06-16
2013-01-26
  • Pedro Rosa
    Pedro Rosa
    2012-06-16

    I'm tryig PDF Clown for the first time, so might be something I'm doing wrong.

    I've a PDF with 2 Contents, I'm trying to remove the first, but this is simply not working.

    string filePath = @"d:\teste2.pdf";
    files::File file = new files::File(filePath);
    Document document = file.Document;
    document.Pages[0].Contents.RemoveAt[0];
    document.Pages[0].Contents.Flush();
    file.Save(@"d:\Output file.pdf", SerializationModeEnum.Incremental );
    

    Can someone tell me want am I doing wrong.

     
  • In order to avoid making the application graph unnecessarily grow, references are loose - you have to retain them in order to alter their state:

    string filePath = @"d:\teste2.pdf";
    files::File file = new files::File(filePath);
    Document document = file.Document;
    Contents contents = document.Pages[0].Contents
    contents.RemoveAt(0);
    contents.Flush();
    file.Save(@"d:\Output file.pdf", SerializationModeEnum.Incremental );
    

    This should work.
    Stefano