Incremental save seems to break forms

Help
2010-10-26
2013-01-26
  • Diego de Felice

    Diego de Felice - 2010-10-26

    Hi to all, I'm having some troubles with PDF files saved with the Incremental SerializationModeEnum on .net version 0.0.8

    Step 1.
    I've a PDF file without a form, I add a new form and a field inside, I save the PDF document in Standard way and everything is ok. I've one field in the form.

    Step 2.
    I open the file again, I made some changes to it, I add a new field to the form and I save the PDF document again but in Incremental way this time.

    Now, if I open the PDF file, the form seems broken because I can see only the first field inside it and not the second field added in the second step. Am I missing something ? Or I've discovered a bug ? It seems the second field is inside the PDF but not linked to the form.

     
  • Stefano Chizzolini

    That's probably due to missing calls to the update() method on modified preexisting objects: see, for example, the ActionSample included in the distribution.

    I've planned to introduce a mechanism for automatic update in the 0.1.1 version (that is after the 0.1.0 currently under development).

     
  • Diego de Felice

    Diego de Felice - 2010-10-28

    Thanks for the reply, I made some tests updating with the Update() method in the various objects, but without success. Maybe I'm not calling the right Update() methods. Here you can see some very simple examples that shows this: button11_Click is the first method that open a one page document (word.pdf) and it adds a form button inside it, it saves in standard mode at the end. button12_Click instead is the method that take the previous PDF and tries to add a new form button inside it, but it saves it in incremental mode. If you open the final PDF, you can see that the second button do not appear in the document. If you save in standard mode instead, all works fine.

            
            private void button11_Click(object sender, EventArgs e)
            {
                try
                {
                    File file = new File(@"C:\temp\word.pdf");
                    Document document = file.Document;
                    document.Form = new it.stefanochizzolini.clown.documents.interaction.forms.Form(document);
                    DefaultStyle fieldStyle = new DefaultStyle();
                    fieldStyle.FontSize = 12;
                    Widget fieldWidget = new Widget( document.Pages[0], new RectangleF(150, 150, 136, 36) );
                    PushButton field = new PushButton( "okButton", fieldWidget, "Push 1" ); 
                    document.Form.Fields.Add(field); 
                    fieldStyle.Apply(field);
                    document.Form.Fields.Update();
                    document.Form.Update();
                    document.Update();
                    file.WriteTo(@"C:\temp\word.pdf_test.pdf", SerializationModeEnum.Standard);
                    file.Dispose();
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message + "\r\n\r\n" + exc.StackTrace);
                }
            }
            private void button12_Click(object sender, EventArgs e)
            {
                try
                {
                    System.IO.File.Copy(@"C:\temp\word.pdf_test.pdf", @"C:\temp\word.pdf_test_2.pdf", true);
                    File file = new File(@"C:\temp\word.pdf_test_2.pdf");
                    Document document = file.Document;
                    DefaultStyle fieldStyle = new DefaultStyle();
                    fieldStyle.FontSize = 12;
                    Widget fieldWidget = new Widget(document.Pages[0], new RectangleF(50, 50, 136, 36));
                    PushButton field = new PushButton("okButton2", fieldWidget, "Push 2");
                    document.Form.Fields.Add(field);
                    fieldStyle.Apply(field);
                    document.Form.Fields.Update();
                    document.Form.Update();
                    document.Update();
                    file.Save( SerializationModeEnum.Incremental );
                    file.Dispose();
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message + "\r\n\r\n" + exc.StackTrace);
                }
            }
    

    Using the code of an example, the second method saving in standard mode produces this output that seems ok:

    Iterating through the fields collection...
    * Field 'okButton' (18 0 R)
        Type: PushButton
        Page: 1 (3 0 R)
        Coordinates:
         x: 150
         y: 150
         width: 136
         height: 36
        Data: << Type Annot Subtype Widget P 3 0 R Border [ 0 0 0 ] Rect [ 150 655,919982910156 286 691,919982910156 ] F 4 FT Btn T okButton Ff 65536 V Push 1 AP 19 0 R >>
    * Field 'okButton2' (24 0 R)
        Type: PushButton
        Page: 1 (3 0 R)
        Coordinates:
         x: 50
         y: 50
         width: 136
         height: 36
        Data: << Type Annot Subtype Widget P 3 0 R Border [ 0 0 0 ] Rect [ 50 755,919982910156 186 791,919982910156 ] F 4 FT Btn T okButton2 Ff 65536 V Push 2 AP 25 0 R >>
    Fields partial counts (grouped by type):
     PushButton: 2
    Fields total count: 2
    

    Thanks for the help, bye

     
  • Diego de Felice

    Diego de Felice - 2010-10-28

    Sorry, I've solved changing the update section with this:

                    document.Pages.Update();
                    document.Form.Fields.Update();
                    document.Form.Update();
                    document.Update();

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks