You are viewing limited content. For full access, please sign in.

Question

Question

How to clear document text using SDK

asked on June 14 Show version history

I am trying to clear all the document text from a document using the SDK.  Here is my code...

for (int pageNumber = 1; pageNumber <= document.PageCount; pageNumber++)
{
    var page = document.GetPageInfo(pageNumber);
    if (page.HasText)
     page.ClearPagePart(PagePart.Text);
}

I get no errors when i run this code and all the document text is empty but the "Text Pages" field still has a value of "Some".  I would expect it to have a value of "None".

What am I doing wrong?

0 0

Answer

SELECTED ANSWER
replied on September 1

This is a bug in the LF server, we will look into fixing it (bug#42872). The workaround is to create and delete a dummy page, which triggers LFS to update the column:

PageInfo dummyPage = document.AppendPage();
document.DeletePage(dummyPage.PageNumber, PageDeletionOptions.ForcePurge);

 

1 0

Replies

replied on June 14

Do you have a document.Save() call after the loop?

replied on June 14

Initially, I thought it was because you were not removing the location data as well, but I tested and found the same behavior.

        private void ClearText(int iDocID)
        {
            try
            {
                using (DocumentInfo CurrentDoc = Document.GetDocumentInfo(iDocID, LFSession))
                {
                    CurrentDoc.Lock(LockType.Exclusive);
                    for (int pageNumber = 1; pageNumber <= CurrentDoc.PageCount; pageNumber++)
                    {
                        PageInfo page = CurrentDoc.GetPageInfo(pageNumber);
                        if (page.HasText)
                        {
                            page.ClearPagePart(PagePart.Locations);
                            page.ClearPagePart(PagePart.Text);
                            page.Save();
                        }
                    }
                    CurrentDoc.Unlock();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

0 0
replied on June 19

I did a bit more research and discovered it is setting the value to "Some".  I have some documents that have a value of "All" and after I run the ClearPagePart method on all pages the value is changed to "Some".  Is there something I can do to force the value to be "None".

0 0
replied on September 1

Follow-up.....still do not have an answer to us.  Could someone from Laserfiche please let me know if...

1) Is there a solution to this problem?

2) Is this by design (I hope this is not the answer!)

3) Is this a bug that will be fixed in a future version.  If so, any idea what version?

0 0
SELECTED ANSWER
replied on September 1

This is a bug in the LF server, we will look into fixing it (bug#42872). The workaround is to create and delete a dummy page, which triggers LFS to update the column:

PageInfo dummyPage = document.AppendPage();
document.DeletePage(dummyPage.PageNumber, PageDeletionOptions.ForcePurge);

 

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.