Hi,
I want to generate pdf/word with Gembox from HTML, the content is dynamic, how can i set a correct width?
for example, i generate a table,
<table style="width:1000px" >…</table>
then, I have to set page size on .cs code:
var document = DocumentModel.Load(htmlStream, htmlLoadOptions);
this almost works, but the empty space between the table is too much, also, the table is 1000px, i set pageWidth as 1000, but there are some more spaces, yes, the unit of pageWidth is point, I tried to set table width as 1000pt, the content is overflow, so how can I set exactly width of page based by the content?
I can use any unit for the html, for example cm, em, pt, just need to control the width of the page based on the content.
So if I understood you correctly, you want to export everything as a single page, is that correct?
In that case, I would actually suggest you use GemBox.Spreadsheet because it can specify ExcelWorksheet.PrintOptions.FitWorksheetWidthToPages and ExcelWorksheet.PrintOptions.FitWorksheetHeightToPages properties. Setting those to 1 will result in the sheet’s content being exported as a single page.
Thanks, problem solved, I have one more question, i also want to convert html to excel, my current code is:
using (var htmlStream = new MemoryStream(htmlLoadOptions.Encoding.GetBytes(html)))
{
ComponentInfo.SetLicense("abcd");
// Load input HTML text as stream.
var document = DocumentModel.Load(htmlStream, htmlLoadOptions);
//document.Sections[0].PageSetup = new PageSetup
//{
// PageWidth = _tableWidth,
// PageHeight = _tableWidth * 4 / 3
//};
// Save output PDF file.
var stream = new MemoryStream();
document.Save(stream, SaveOptions.PdfDefault);
return stream;
}
seems saveOptions don’t have option for excel, is excel can only generated by html with the code:
var htmlOptions = new HtmlLoadOptions();
var htmlStream = new MemoryStream(htmlOptions.Encoding.GetBytes(_stringBuilder.ToString()));
var workbook = ExcelFile.Load(htmlStream, htmlOptions);
workbook.Save("output.xlsx");
is there a way to generate excel but no need to save as a local file but get a stream?