Multi Page object Replace Error

  • 49 Views
  • Last Post 09 January 2019
  • Topic Is Solved
lx11020219 posted this 27 November 2018

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!! } }

Order By: Standard | Newest | Votes
Nadezhda A. Solovyeva posted this 01 January 2019

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.

lx11020219 posted this 09 January 2019

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]); } }

Nadezhda A. Solovyeva posted this 09 January 2019

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.

  • Liked by
  • lx11020219
lx11020219 posted this 09 January 2019

I understood.
Thank you for the advice.

Close