Hide elements not working identical across file formats (Words .NET)

Hello aspose team!

I am using version 9.4.1 of Aspose.Words.dll.

My document has the following structure:

I try to hide these elements by setting Runs.Font.Hidden = true.

Afterwards I save the result as an ODT, DOCX and PDF file.

I would expect all elements to be hidden in the resulting documents but there are differences:

In the ODT file I can still see a thick line at the location of the table. The other elements are hidden as expected.

In the PDF file the text of the table cells are hidden, but the structure (borders and background-color) is still visible. Furthermore, i can see the list-item bullets (whereas the text is hidden). I have the same behaviour with the simple paragraph. The text is invisible, but the paragraph is still there.

The DOCX file looks exactly like the PDF file.

This is my code:

[Test]
public void HideTableTest()
{
    Document document = new Document("Resources/HiddenElementsTests.docx");
    Table table = (Table) document.FirstSection.Body.GetChild(NodeType.Table, 0, false);
    foreach(Row row in table.Rows)
    {
        foreach(Cell cell in row.Cells)
        {
            foreach(Paragraph cellParagraph in cell.Paragraphs)
            {
                Hide(cellParagraph);
            }
        }
    }

    foreach(Paragraph listParagraph in document.FirstSection.Body.Paragraphs)
    {
        if (listParagraph.IsListItem)
        {
            Hide(listParagraph);
        }
    }

    Paragraph paragraph = (Paragraph) document.FirstSection.Body.LastParagraph.PreviousSibling.PreviousSibling;
    Hide(paragraph);

    document.Save("HiddenElementsTests.odt");
    document.Save("HiddenElementsTests.docx");
    document.Save("HiddenElementsTests.pdf");
}

private static void Hide(Paragraph paragraph)
{
    foreach(Run run in paragraph.Runs)
    {
        run.Font.Hidden = true;
    }
}

I also tried to hide paragraphs by setting Paragraph.ParagraphFormat.Style.Font.Hidden = true.
But as this is modifying the whole style, all paragraphs using this style are hidden in the entire document. This is not what I want to achieve.

Am I doing something wrong? Please tell me, how I achieve to hide all of these elements as expected.

Regards

Hi

Thanks for your inquiry. The problem with visible paragraphs can be easily resolved by using the following code:

private static void Hide(Paragraph paragraph)
{
    paragraph.ParagraphBreakFont.Hidden = true;
    foreach(Run run in paragraph.Runs)
    run.Font.Hidden = true;
}

However, the problem with table still persists. I linked your request to the appropriate issue. You will be notified as soon as it is resolved. For now, if you need to make a table invisible, you can just remove it.
Best regards,

Hi Marty,
Thanks for your inquiry.
The code found on this API example here may be of help to you.
Thanks,

Hi

Thank you for your fast answer! With your hint I can hide paragraphs and lists now.

alexey.noskov:
For now, if you need to make a table invisible, you can just remove it.

Sorry, that is not possible. The table has to remain intact because it’s visibility-state is bound on a certain conditions. That condition result can change from time to time (the document is generated once, afterwards it will be processed multiple times after user interaction).

Regards

Hi Marty,
Thanks for the additional information.
In that case I think you could wrap your table in an IF field based off this condition which would hide the table in the output but not remove it. You could also look into storing two copies of the document, one with hidden content removed and the original… If these do not suffice then I don’t think there is any other work around to achieve this right now. We will keep you informed when this feature is avaliable.
Thanks,

aske012:
In that case I think you could wrap your table in an IF field based off this condition which would hide the table in the output but not remove it.

Storing two documents is not an option.
I tried to embedd the table in an if-field, but I did not succeed. I managed to show different text, based off the if-condition. But I need to show/hide a table with custom formatting.
This is what I got so far:
{IF {DOCPROPERTY showtable \* MERGEFORMAT } = "1" "Is 1" "Is not 1" \* MERGEFORMAT }
If I set the docproperty showtable to 1 I see “Is 1”, or else I see “Is not 1”. So far, so good. But how to show/hide complex elements, like a table?
I am not very familiar with fields in word documents. Also, I could not find a solution on the web. Maybe you know how to solve this?
Thank you in advance!

-----
Edit: I just noticed that it is important that the enclosing quotation marks are important. When I create a table in the field directly before Is 1" then I can delete Is 1 and from there on I can switch the visibility of the table.

Anyway, this is helpful for new documents. But this solution does not fit for documents that are already deployed to the customer. So it is really desirable to have the possibility to show/hide tables like normal runs and paragraphs.

Hi Marty,
Thanks for your inquiry.

  1. Simply toggle field codes (ALT+F9) so the way you are viewing your fields in the document is like your example above.
  2. Copy or cut your table to clipboard
  3. Place the cursor inbetween the appropriate part of the field, in this case where “Is 1” resides.
  4. Paste the table.

The content inside this type of field can span multiple paragraphs and include tables etc so you can simply work with them as if you are editing in the main document.
Thanks,

Thank you for your answer. I discovered this possibility right after submitting my last post (and already edited it with my way of solving it).

But as I already wrote in the “edit-part” this is only helpful for new documents. But this solution does not fit for documents that are already deployed to the customer. So it is really desirable to have the possibility to show/hide tables like normal runs and paragraphs.

However, thank you for your quick response!

Hi Marty,

Thank you for additional information. Unfortunately, this is the only workaround we can suggest you at the moment.
Strange thing is that if all paragraphs are hidden in table, the table is also hidden in DOC, but it is not hidden in DOCX. This is specific of file format. We will deeply investigate the problem and let you know once it is resolved.
Best regard.

Hi aspose team!

Unfortunately the IF field hides the table only in DOC, DOCX and PDF files. ODT shows the table without text (only the structure is visible). Does OpenOffice have problems with processing fields, in this case showing the IF-TRUE part of an IF field although the condition is false (IF “1”=“0”)?

Is there a way to format a section so that it is hidden or invisible? I know that Open Office supports hidden sections. I don’t know whether MS Word supports it too. Then, I could break the document into multiple sections and place this table in a dedicated section, which I could show or hide as needed.

Regards

Hi Marty,
Thanks for your inquiry.
Yes it appears OpenOffice does have some troubles with tables within fields, I think it is not properly supported in OpenOffice so that does not appear to be a viable solution in that case.
To my knowledge I have not heard of MS Word being able to hide sections. A quick search only provides samples references to VBA code which will hide the range of the section (the same thing hiding each individual peice of text in the section) which would of course result in the original issue still.
I’m afraid I can’t suggest any other work arounds for now.
Thanks,

The issues you have found earlier (filed as WORDSNET-2523) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(11)

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan