none
Using IPersistFile.Save on word doc doesn't copy lastRenderedPageBreaks? RRS feed

  • Question

  • Not sure if these goes here or in the Word for Developers, but I'll try here first.

    So I'm saving a temporary copy of a Word document using IPersistFile.Save() like so:

    var persistFile = (IPersistFile)_wordDocument;

    string fileName = Path.GetTempFileName();

    persistFile.Save(fileName, false);


    It produces different results when passed to my web server for text processing.  The document seemed identical to Word, but when you compare the two document.xml, the temporary copy has no lastRenderedPageBreaks anywhere for 6 page document.  The original document.xml has them.  Is this on purpose?

    My server uses these to determine pages to determine proper headers and footers.  I would rather not have to go back to requiring word docs be saved on disk before I can make a temp copy.

    Thanks.

    Tuesday, January 21, 2014 5:30 PM

Answers

  • Hi Steve Buberl,

    >> The original document.xml has them.  Is this on purpose? <<

    LastRenderedPageBreak specifies that this position delimited the end of a page when this document was last saved by an application which paginates its content. It will be calculated when saving the document by Word Application. It will changed with page layout, font and content accordingly. Since you are using IPersistFile interface to save a document, only the content will be saved, so there are no LastRenderedPageBreak elements in the new document.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Steve Buberl Thursday, January 23, 2014 7:25 PM
    Thursday, January 23, 2014 10:38 AM
    Moderator

All replies

  • Hi,

    What's the type of project are you developing? What's the _wordDocument object in your code?

    I try to reproduce your issue in my Word VSTO add-in with the code below and it works well.

    Word.Application App = Globals.ThisAddIn.Application;
    Word.Document doc = App.ActiveDocument;
    var persistFile = (IPersistFile)doc;
    string fileName = @"C:\Users\Documents\test.docx";
    
    persistFile.Save(fileName, false);

    Since I cannot repro your issue, I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 22, 2014 12:02 PM
    Moderator
  • Hi Steve Buberl,

    >> The original document.xml has them.  Is this on purpose? <<

    LastRenderedPageBreak specifies that this position delimited the end of a page when this document was last saved by an application which paginates its content. It will be calculated when saving the document by Word Application. It will changed with page layout, font and content accordingly. Since you are using IPersistFile interface to save a document, only the content will be saved, so there are no LastRenderedPageBreak elements in the new document.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Steve Buberl Thursday, January 23, 2014 7:25 PM
    Thursday, January 23, 2014 10:38 AM
    Moderator
  • Hi Steve Buberl,

    LastRenderedPageBreak specifies that this position delimited the end of a page when this document was last saved by an application which paginates its content. It will be calculated when saving the document by Word Application. It will changed with page layout, font and content accordingly. Since you are using IPersistFile interface to save a document, only the content will be saved, so there are no LastRenderedPageBreak elements in the new document.

    That's a shame.  I was hoping for a more exact copy.  Thanks for confirming it.  

    I'll switch back to requiring documents already being saved on disk and using File copy.

    Thursday, January 23, 2014 7:25 PM