Free Support Forum - groupdocs.com

Is it possible to define page size when rendering TXT to HTML?

Is it possible to define some page size for rendering text-based files to HTML?
We are just doing a basic conversion to HTML like that:

        using (var viewer = new Viewer(documentPath))
        {                
            var options = HtmlViewOptions.ForEmbeddedResources(@"D:\output\output_viewer{0}.html");
            viewer.View(options);
        }

The resulting HTML has some width boundary, so the text gets wrapped properly and there also seems to be some mechanism that determines how many lines to take on a single page, depending on the line size, as each page has a different line count.
So the result is not bad, but it just does not really fit on a A4 page.
Is there maybe some option to achieve that?

For emails we are using this line, but I did not find anything similar for text-based files yet.
options.EmailOptions.PageSize = PageSize.A4;
Text Page Size.zip (9.1 KB)

@Clemens_Pestuka

Right, at the moment we have the following predefined values that are used to determine how many chars will be taken for each page.

private const int MaxCharsInRow = 85;
private const int MaxRowsInPage = 57;

We’ve created the issue in our bug tracker. The issue ID is VIEWERNET-3323. We’ll investigate how this can be improved and let you know.

1 Like

@vladimir.litvinchik

Thank you for the detailed information and for logging this bug/feature request :slight_smile:
I think if those values would be modifiable, we could find an approximation for A4 size.

Hi @Clemens_Pestuka

Is this the problem? Some splitted pages do not fit on one A4 page?

@mikhail.evgrafov.aspose

That’s more or less the problem, yes.
But it is a bit different on our side, as we don’t print it, but display the html pages in our viewer, that has white pages for the content and gray background.
So in our case the text overflows the (hardcoded) A4 page size:

image.png (14.8 KB)

To some extent this is also our problem, but it would still be great, to have the text fit the A4 page.

@Clemens_Pestuka

Thanks for the details, this issue is in progress. We’ll notify you when it will be resolved.

1 Like

@Clemens_Pestuka

The fields MaxCharsPerRow and MaxRowsPerPage will be available as public properties starting from v21.6. We’ll notify you when the new version will be published.

1 Like

@vladimir.litvinchik

Oh that’s great news :+1:
Thanks a lot for adding this feature so quickly, that’s definitely going to help us :slight_smile:

1 Like

@Clemens_Pestuka

You’re welcome!

@Clemens_Pestuka

GroupDocs.Viewer for .NET v21.6 that includes new properties to configure page size has been published. You can find the new version at

Sample code

using (Viewer viewer = new Viewer("logfile.log"))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewOptions.TextOptions.MaxCharsPerRow = 85; 
    viewOptions.TextOptions.MaxRowsPerPage = 55;

    viewer.View(viewOptions);
}

Have a nice day!