How to convert and view HTML files with user defined margins
When you are converting HTML files, you can adjust top/bottom, left/right page margins in final document.
The units of margins are typography points.
Default values are:
Top/Bottom - 72
Left/Right - 5
Final margin value is calculated as:
Final margin value = [HTML page margin value] + [margin value in viewer ]
How to set margins values
Setting margins values when converting to PNG
To set margins values when converting HTML files to PNG with GroupDocs.Viewer for .NET use following code:
using (Viewer viewer = new Viewer("sample.htm"))
{
PngViewOptions options = new PngViewOptions("result_page_{0}.png");
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;
viewer.View(options);
}
The following screenshot shows the output PNG file opened in a Windows Photo Viewer application.
Setting margins values when converting to JPG
To set margins values when converting HTML files to PNG with GroupDocs.Viewer for .NET use following code:
using (Viewer viewer = new Viewer("sample.htm"))
{
JpgViewOptions options = new JpgViewOptions("result_page_{0}.jpg");
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;
viewer.View(options);
}
The following screenshot shows the output JPEG file opened in a Windows Photo Viewer application.
Setting margins values when converting to PDF
To set margins values when converting HTML files to PDF with GroupDocs.Viewer for .NET use following code:
using (Viewer viewer = new Viewer("sample.htm"))
{
PdfViewOptions options = new PdfViewOptions("result.pdf");
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;
viewer.View(options);
}
The following screenshot shows the output PDF file opened in an Acrobat Reader.
More resources
View WEB Files Online
Along with full-featured .NET library we provide simple but powerful free online Apps. View HTML and XML files online with GroupDocs Viewer App.
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for .NET examples, plugins, and showcase
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET MVC UI Example
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example