We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Two column text alignment issue

I am writing content in two column using Aspose pdf FloatingBox.

The text is moving to next column only when page is ended and page space is wasted.
I want the text to be moved to next column so that we can use remaining page for other content.

Sample code:Aspose Output.png (73.3 KB)
Expected Output.png (126.7 KB)

        string dataDir = @"C:\Users\sray18\PDF Creator\Temp\";
        Document pdfDocument = new Document();

        var page = pdfDocument.Pages.Add();
        var colummWidth = (page.PageInfo.Width - (page.PageInfo.Margin.Left + page.PageInfo.Margin.Right + 80)) / 2;

        FloatingBox box = new FloatingBox
        {
            ColumnInfo =
            {
                ColumnCount = 2,
                ColumnSpacing = "80",
                ColumnWidths = string.Join(" ", new double[2]{colummWidth, colummWidth})
            },
        }; 

         TextFragment text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin=new MarginInfo(0,20,0,0);
        box.Paragraphs.Add(text);
        text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin = new MarginInfo(0, 20, 0, 0);
        box.Paragraphs.Add(text);
        text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin = new MarginInfo(0, 20, 0, 0);
        box.Paragraphs.Add(text);
        text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin = new MarginInfo(0, 20, 0, 0);
        box.Paragraphs.Add(text);
        text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin = new MarginInfo(0, 20, 0, 0);
        box.Paragraphs.Add(text);
        text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin = new MarginInfo(0, 20, 0, 0);
        box.Paragraphs.Add(text);
        text = new TextFragment("On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.");
        text.Margin = new MarginInfo(0, 20, 0, 0);
        box.Paragraphs.Add(text);
        

        page.Paragraphs.Add(box);
       
        pdfDocument.Save(dataDir + "Test.pdf");<a class="attachment" href="/uploads/discourse_instance3/6255">Expected Output.png</a> (126.7 KB)

@sumitray1982,
You can set height of the floating box to save space in the bottom area of the page.

e.g.
box.Height = page.PageInfo.Height/2;

If this does not help, then kindly share the complete details of the scenario, including source PDF (if any) and code. We will investigate and share our findings with you.

Thanks for the reply.
I am using following sample code which is generating attached PDF.
My requirement is to generate pdf dynamically and content is not fixed hence I can not fix the height of the floating box.
Sample text is covering entire first column and part of second column of the page. in this case I am loosing some page space which can be used for rendering next content.
Is it possible to set some property or any other way to render the content equally on the both columns and rest of the page should be empty.Test.pdf (46.0 KB)

        string dataDir = @"C:\Users\sray18\PDF Creator\Temp\";
        Document pdfDocument = new Document();
        string content = "On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.";
        var page = pdfDocument.Pages.Add();
        var colummWidth = (page.PageInfo.Width - (page.PageInfo.Margin.Left + page.PageInfo.Margin.Right)) / 2;

        FloatingBox box = new FloatingBox
        {
            ColumnInfo =
            {
                ColumnCount = 2,
                ColumnSpacing = "40",
                ColumnWidths = string.Join(" ", new double[2]{colummWidth, colummWidth})
            },
        };

        for (int i = 0; i < 7; i++)
        {
            TextFragment fragment = new TextFragment(content);
            fragment.Margin = new MarginInfo(0, 20, 0, 0);
            fragment.TextState.HorizontalAlignment = HorizontalAlignment.Justify;
            box.Paragraphs.Add(fragment);
        }

        page.Paragraphs.Add(box);
        pdfDocument.Save(dataDir + "Test.pdf");

@sumitray1982,
There is no way to control the writing flow in the multi-column floating box. By default, the flow of adding elements in the floating box is from top left corner to the bottom right corner. You can control the vertical position of a floating box with Top, Bottom and Height properties and you can use page height for this purpose. We have just changed the height of floating box and now you can add other elements in the rest empty space. Please try the following code:

[C#]

string dataDir = @"C:\Pdf\test294\";
Document pdfDocument = new Document();
string content = "On the options front, maximum Put open interest stood at strike prices 9,700 and 9,800 while maximum Call OI was at 10,000 followed by 10,100. There was fresh Put writing at strike prices 9,000, 9,800 and 9,700 while fresh Call writing was seen at 9,900, 10,050 and 10,100. A shift in Put writing to higher levels suggests shifting of support while Call writing remained intact, which could restrict its immediate upside to 9,980-10,020 levels.";
var page = pdfDocument.Pages.Add();
var colummWidth = (page.PageInfo.Width - (page.PageInfo.Margin.Left + page.PageInfo.Margin.Right)) / 2;

FloatingBox box = new FloatingBox
{
    ColumnInfo =
    {
        ColumnCount = 2,
        ColumnSpacing = "40",
        ColumnWidths = string.Join(" ", new double[2]{colummWidth, colummWidth})
    },
Height = page.PageInfo.Height/2,
};

for (int i = 0; i < 7; i++)
{
    TextFragment fragment = new TextFragment(content);
    fragment.Margin = new MarginInfo(0, 20, 0, 0);
    fragment.TextState.HorizontalAlignment = HorizontalAlignment.Justify;
    box.Paragraphs.Add(fragment);
}
page.Paragraphs.Add(box);
pdfDocument.Save(dataDir + "Test_Out.pdf");

This is the output PDF: Test_Out.pdf (9.7 KB)