Community

Multi Page object Replace Error Answered

Hello!

When setting a layout object as a page object, an error occurs if there are multiple pages.
Please tell me the workaround.

Error: System.AccessViolationException
Detail: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Code:


int iTargetPage = 1;
FRPage page = document.Pages.Item(iTargetPage - 1);
page.Layout = layout;
List<FRPage> lPage = new List<FRPage>(); for (int iIndex = document.Pages.Count - 1; iIndex >= 0; iIndex--) { lPage.Add(document.Pages.Item(iIndex)); document.Pages.DeleteAt(iIndex); }
// Ascending Order lPage.Reverse();
// Exec Replace for (int iIndex = 0; iIndex < lPage.Count; iIndex++) { if (iIndex + 1 == iTargetPage) { // Replace document.AddPage(page); } else { // Not Replace document.AddPage(lPage[iIndex]); // Error!! } }

Was this article helpful?

0 out of 0 found this helpful

Comments

4 comments

  • Avatar
    Nadezhda A. Solovyeva

    Hello,

    When you assign a Layout object to FREngine.Layout property (for example, when transferring data from one page to another), the logical structure of the corresponding document becomes invalid. It is necessary to restore the document structure by calling one of the synthesis methods. However, you do not need to perform synthesis for the whole document, it is only necessary to synthesize changed pages, e.g. using the Synthesize method.

    0
  • Avatar
    OHTSUKA Takeshi

    Hello!

    Thank you for your reply.
    I corrected the points pointed out and confirmed that no error occurred.
    I will post the corrected source, so please let me know if it is wrong.
    I appreciate it very much.

    Code:

    
    int iTargetPage = 1;
    FRPage page = document.Pages.Item(iTargetPage - 1);
    page.Layout = layout;
    page.Synthesize();    // Add Code
    List<FRPage> lPage = new List<FRPage>(); for (int iIndex = document.Pages.Count - 1; iIndex >= 0; iIndex--) { document.Pages.Item(iIndex).Synthesize(); // Add Code lPage.Add(document.Pages.Item(iIndex)); document.Pages.DeleteAt(iIndex); }
    // Ascending Order lPage.Reverse();
    // Exec Replace for (int iIndex = 0; iIndex < lPage.Count; iIndex++) { if (iIndex + 1 == iTargetPage) { // Replace document.AddPage(page); } else { // Not Replace document.AddPage(lPage[iIndex]); } }
    0
  • Avatar
    Nadezhda A. Solovyeva

    The code you posted is OK, but it might not work for some OCR scenarios different from yours. In this case, we would recommend calling Document.Synthesize() at the end.

    1
  • Avatar
    OHTSUKA Takeshi

    I understood.
    Thank you for the advice.

    0

Please sign in to leave a comment.