DOCX to PDF conversion issue with Header Footer and Section break rendering using .NET

You just need to install fonts that are used in your document. Please note that Aspose.Words requires TrueType fonts when rendering document to fixed-page formats (JPEG, PNG, PDF or XPS).

Please remove all old DLLs from your project and disk and add reference to latest DLL.

Please share the PDF files requested in my previous post. Please also execute the code shared in my previous post at Web Server and let us know if you face any missing font notification.

Please share step by step information that you are using to reproduce this issue at our end. Please also share the complete detail of Web Server and operating system detail. We will investigate the issue and provide you more information on it.

Hi Tahir,

Thanks a lot Tahir. Our problem is shorted out.There are some true type fonts are not installed in Web Server. Now we installed those and it is working fine.

We are facing one more problem.

Could you please help how to set “Font Text effects to none” to a word document using Aspose.Words dll.

Please help us.

Thanks,
Santosh Kumar Panigrahi

Hi Tahir,

One more think the above problem is happening while find and replace a word in a document.

We have already set font family, font size, bold, italic and set text effects to none. But it is not effecting while replacing.

Thanks,
Santosh Kumar Panigrahi

Please use ParagraphFormat.ClearFormatting method to reset the text formatting to default paragraph formatting.

Please ZIP and attach your input, problematic output and expected output documents along with code example to reproduce your issue at our end. We will investigate the issue and provide you more information on it.

Hi Tahir,

Thank you for your response. We have used ParagraphFormat.ClearFormatting method to reset the text formatting to default paragraph formatting but it is not working.

So, I have given the code in a console application in a zip file with Input, expected output and wrongoutput file.

In console application code the input file path(D:\input.docx) is hard codded in code level. You can change it to your local path.

Please find the below zip files where you can find FontPOC.zip for console application and Files.zip for Input, expected and wrong output files.

FontPOC.zip (4.9 MB)
Files.zip (135.2 KB)

We are unable to find any solution for this.

Could you please help us on this.

Thanks,
Santosh Kumar Panigrahi

@santoshp1989

In your case, we suggest you please implement IReplacingCallback interface to clear the font formatting of matched node. Please check the following code example. Hope this helps you.

Document document = new Document(MyDir + "input.docx");
var findReplaceOptions = new FindReplaceOptions();
findReplaceOptions.Direction = FindReplaceDirection.Forward;
findReplaceOptions.FindWholeWordsOnly = true;
findReplaceOptions.MatchCase = false;
findReplaceOptions.ApplyFont.Color = System.Drawing.Color.Black;
findReplaceOptions.ApplyFont.Underline = Underline.None;
findReplaceOptions.ApplyFont.TextEffect = TextEffect.None; // we set text effect to none but template applied text effects
findReplaceOptions.ApplyFont.UnderlineColor = System.Drawing.Color.Black;
findReplaceOptions.ApplyFont.StrikeThrough = false;
findReplaceOptions.ApplyFont.DoubleStrikeThrough = false;
findReplaceOptions.ApplyFont.Name = "Times New Roman";
findReplaceOptions.ApplyFont.Size = 14;
findReplaceOptions.ReplacingCallback = new FindAndClearFormatting();
document.Range.Replace("<<MBRNAME>>", "AARON", findReplaceOptions);
document.Save(MyDir + "20.4.docx");

private class FindAndClearFormatting : IReplacingCallback
{
    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = e.MatchNode;

        // The first (and may be the only) run can contain text before the match, 
        // In this case it is necessary to split the run.
        if (e.MatchOffset > 0)
            currentNode = SplitRun((Run)currentNode, e.MatchOffset);

        ArrayList runs = new ArrayList();

        // Find all runs that contain parts of the match string.
        int remainingLength = e.Match.Value.Length;
        while (
            (remainingLength > 0) &&
            (currentNode != null) &&
            (currentNode.GetText().Length <= remainingLength))
        {
            runs.Add(currentNode);
            remainingLength = remainingLength - currentNode.GetText().Length;

            // Select the next Run node. 
            // Have to loop because there could be other nodes such as BookmarkStart etc.
            do
            {
                currentNode = currentNode.NextSibling;
            }
            while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));
        }

        // Split the last run that contains the match if there is any text left.
        if ((currentNode != null) && (remainingLength > 0))
        {
            SplitRun((Run)currentNode, remainingLength);
            runs.Add(currentNode);
        }

        foreach (Run run in runs)
            run.Font.ClearFormatting();

        return ReplaceAction.Replace;
    }
}

Hi Tahir,

I am really very sorry but the above code is not working. Existing code also broken.

We are getting the below error while Find and Replace:-

Error: Cannot remove because there is parent.

Please find the below is for error image:-
image.jpg (136.1 KB)

Please find the attachment for the document file what we tried:-
COMBOFONTCHNAGED-new.zip (64.2 KB)

Could you please help us on this.

Thanks,
Santosh Kumar Panigrahi

@santoshp1989

Please use the latest version of Aspose.Words for .NET 20.4 to avoid this exception.

Hi Tahir,

We are facing one of the big problem with one of the word file.
The word file is having 4 images and out of that 3 are visible and one of them is invisible.

Problem:- The invisible image is with 0, 0 dimension.
Solution:- We need to remove that invisible or 0,0 dimension image from the word file.

Question:- Is it possible to remove the invisible image from the word file using Aspose.Words 18.5 dll for.NET? If yes, could please share the piece of code with us.

Note:- Please help us ASAP, our code is there in Production.

Please find the attached zip file, where you can file one word file. In the header section, you can find three images visible and one image invisible. You can find invisible image by pressing shift + right arrow in front of first image.

05212020_BHTRENDAV2FO18Q1_BHTRENDAV2FO19Q1_IA_MCD - Copy.zip (193.3 KB)

We are waiting for your response.

Thanks,
Santosh Kumar Panigrahi

@santoshp1989

Please use the following code example to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "05212020_BHTRENDAV2FO18Q1_BHTRENDAV2FO19Q1_IA_MCD - Copy.docx");
NodeCollection shapes = doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderFirst].GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
{
    if (shape.Width == 0)
        shape.Remove();
}
doc.Save(MyDir + "20.5.docx");

A post was merged into an existing topic: How to find and replace a word with Font Properties in a word document