How to remove extra space next to number and starting text

Hi Team,

I am attaching file using builder.insertdocument() function in dot net using aspose words, when pdf file get generated, it shows space between number and starting text. How can we remove that extra space.

It displayed in generated pdf like below

  1.         Fill the packaging system to its nominal capacity with purified water and close it, if
    

possible,
but it should be like

  1. Fill the packaging system to its nominal capacity with purified water and close it, if
    possible,
    I am attaching dummy project and files.Dummy Project 17122020.zip (7.4 MB)

Can you please help on this on urgent basis.

Thank you for all your support.

Hi

Can anyone please help on this?

Thanks

@Pranita.Kasale,

The problem does not occur when you comment/remove the following lines:

paragraph.ParagraphFormat.LeftIndent = 0;
paragraph.ParagraphFormat.FirstLineIndent = 0;
paragraph.ParagraphFormat.RightIndent = 0; 

Please try the following simplified code:

Aspose.Words.Document wordDoc = null;
Aspose.Words.DocumentBuilder builder = null;
string genPath = "C:\\Temp\\Dummy Project 17122020\\PHYSICOCHEMICAL TESTS.docx";

if (System.IO.File.Exists(genPath))
{
    Aspose.Words.Document secDoc = new Aspose.Words.Document(genPath);

    wordDoc = (Aspose.Words.Document)secDoc.Clone(false);
    wordDoc.EnsureMinimum();

    builder = new Aspose.Words.DocumentBuilder(wordDoc);
    builder.MoveToDocumentEnd();

    wordDoc.CompatibilityOptions.GrowAutofit = false;
    Aspose.Words.PageSetup pageSet = builder.PageSetup;
    pageSet.PaperSize = Aspose.Words.PaperSize.A4;
    pageSet.LeftMargin = Aspose.Words.ConvertUtil.InchToPoint(0.5);
    pageSet.RightMargin = Aspose.Words.ConvertUtil.InchToPoint(0.5);
    pageSet.TopMargin = Aspose.Words.ConvertUtil.InchToPoint(2.5);
    pageSet.BottomMargin = Aspose.Words.ConvertUtil.InchToPoint(1);
    pageSet.Orientation = Aspose.Words.Orientation.Portrait;

    secDoc.FirstSection.PageSetup.SectionStart = Aspose.Words.SectionStart.Continuous;
    secDoc.FirstSection.HeadersFooters.LinkToPrevious(true);
    RemoveSectionBreaks(secDoc);
    //modified code start
    foreach (Aspose.Words.Paragraph paragraph in secDoc.GetChildNodes(NodeType.Paragraph, true))
    {
        //paragraph.ParagraphFormat.LeftIndent = 0;
        //paragraph.ParagraphFormat.FirstLineIndent = 0;
        //paragraph.ParagraphFormat.RightIndent = 0;
    }
    //modified code end
    Aspose.Words.ImportFormatOptions formatOpt = new Aspose.Words.ImportFormatOptions();
    formatOpt.KeepSourceNumbering = true;
    builder.InsertDocument(secDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting, formatOpt);

    wordDoc.UpdatePageLayout();

    byte[] pdfBytes = null;
    using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
    {
        wordDoc.Save("C:\\Temp\\Dummy Project 17122020\\text alignment issue.pdf", Aspose.Words.SaveFormat.Pdf);
        pdfBytes = stream.ToArray();
    }
}

@awais.hafeez Thank your for your reply.

Actually I am using leftindent / rightindent for another issue I had faced. That issue has been described in below link.

For above solution, I am attaching my document in between my contents. In attached project don’t have that scenario. But in my actual file it will be like some content then attached word file and again some content.
Like worddoc will be my main document where I have some table and other info to get display. Then using secdoc I read the attached word file and again that attachment inserted into main worddoc.

My actual problem is that in main word doc I had set up a page with margin like left and right margin as 0.5.
So if any word document which I need to attached using builder.insertdocument() function, if that word file having margin less than 0.5 or less than 0 then in generated pdf file, text getting cutt off from left or right side. To fix this issue using leftindent and rightindent property as per the solution given in issue which I linked here for reference. But while testing with this solution found that when having data with numbers it was displayed some extra space.

As per your solution if I clone the secdoc into main worddoc then other contents of worddoc will get overlapped with secdoc content.

Can you please on this? My main aim is whatever file user attached it should display proper in generated PDF file with other contents as well.

@Pranita.Kasale,

You can avoid applying Left, Right and First Line Indentations to list item Paragraphs by using the following code:

Aspose.Words.Document wordDoc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(wordDoc);
wordDoc.CompatibilityOptions.GrowAutofit = false;
Aspose.Words.PageSetup pageSet = builder.PageSetup;
pageSet.PaperSize = Aspose.Words.PaperSize.A4;
pageSet.LeftMargin = Aspose.Words.ConvertUtil.InchToPoint(0.5);
pageSet.RightMargin = Aspose.Words.ConvertUtil.InchToPoint(0.5);
pageSet.TopMargin = Aspose.Words.ConvertUtil.InchToPoint(2.5);
pageSet.BottomMargin = Aspose.Words.ConvertUtil.InchToPoint(1);
pageSet.Orientation = Aspose.Words.Orientation.Portrait;
builder.MoveToDocumentEnd();
string genPath = "C:\\Temp\\Dummy Project 17122020\\PHYSICOCHEMICAL TESTS.docx";

if (System.IO.File.Exists(genPath))
{
    Aspose.Words.Tables.Table table = builder.StartTable();
    builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.None;
    insertTableCell(builder, Aspose.Words.Tables.CellMerge.None, "Product General information", 0, 11, true);
    builder.EndRow();
    insertTableCell(builder, Aspose.Words.Tables.CellMerge.None, " ", 0, 11, true);
    builder.EndRow();


    if (System.IO.File.Exists(genPath))
    {
        Aspose.Words.Document secDoc = new Aspose.Words.Document(genPath);
        secDoc.FirstSection.PageSetup.SectionStart = Aspose.Words.SectionStart.Continuous;
        secDoc.FirstSection.HeadersFooters.LinkToPrevious(true);
        RemoveSectionBreaks(secDoc);
        //modified code start
        foreach (Aspose.Words.Paragraph paragraph in secDoc.GetChildNodes(NodeType.Paragraph, true))
        {
            if (!paragraph.IsListItem)
            {
                paragraph.ParagraphFormat.LeftIndent = 0;
                paragraph.ParagraphFormat.FirstLineIndent = 0;
                paragraph.ParagraphFormat.RightIndent = 0;
            }
        }
        //modified code end
        Aspose.Words.ImportFormatOptions formatOpt = new Aspose.Words.ImportFormatOptions();
        formatOpt.KeepSourceNumbering = true;
        builder.InsertDocument(secDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting, formatOpt);
    }

    builder.MoveToDocumentEnd();
    builder.EndTable();
    wordDoc.UpdatePageLayout();


    byte[] pdfBytes = null;
    using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
    {
        wordDoc.Save("C:\\Temp\\Dummy Project 17122020\\text alignment issue.pdf", Aspose.Words.SaveFormat.Pdf);
        pdfBytes = stream.ToArray();
    }
}

Hi @awais.hafeez

I have tried with above code. But its not working as expected.

I am attaching one demo project where I have two different types of attachments. In the same folder attached generated pdf files too.

I want whatever I have attached using builder.insertdocument() function, that should get formatted as per other content as per required data in pdf file. And all the data should be in same align without any formatting issue. Word attachment data should be display same as attached file. And it should be align with my main document content.

Can you please help on this? Your help is really appreciated.

Thanks
Pranita23122020.zip (7.4 MB)

@Pranita.Kasale,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-21585. We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for any inconvenience.

Hi @awais.hafeez

Any updates on this? Can you please provide any estimation for this?

Thanks
Pranita

@Pranita.Kasale,

Regarding WORDSNET-21585, we have completed the analysis of this issue. This issue can be simplified to the following:

Document dstDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(dstDoc);

Document srcDoc = new Document("SourceDocument.docx");

builder.InsertDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

dstDoc.Save("output.docx");

We get the following outputs (Left: Before, Right: After):

It looks like the styles were imported incorrectly. But this is not true. However, the whole reason is in the compatibility flag in source DOCX.

<w:compat>
        ...
        <w:doNotUseIndentAsNumberingTabStop />
        ...
</w:compat>

The code specified below fixes the issue. So, please set compatibility option explicitly:

Document dstDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(dstDoc);

Document srcDoc = new Document("SourceDocument.docx");

builder.InsertDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

dstDoc.CompatibilityOptions.DoNotUseIndentAsNumberingTabStop = false;

dstDoc.Save("output.docx");

@awais.hafeez

Thank you for your reply. I will implement this changes at my end.

Thank you!

@Pranita.Kasale,

Sure. In case you have further inquiries or may need any help in future, please let us know.