Using the Spire.XLS/Spire.PDF and C#, I am successfully creating a PDF file from an several Excel (2013) worksheets however, the resulting PDF file has extra white space to the right of the main visible cells of the worksheet. The worksheets contain several 'hidden' lookup cells, which sit to the right of the visible cells and it appears that the width of the PDF file is set by: 'the width of the visible cells' + 'width of the hidden cells'.
How can I produce a PDF file whose width is set only by the visible cells and not the hidden cells? I have tried copying the Cell Range to a new worksheet and converted that, but the layout is different and doesn't look like the original.
I am using streams (with no disk io) and the code is:
public byte[] ExtractWorksheetsAsPdf(byte[] excelFile, int[] worksheets)
{
using (var excelStream = new MemoryStream(excelFile))
{
var workbook = new Workbook();
workbook.LoadFromStream(excelStream, ExcelVersion.Version2013);
var pdfDocument = new PdfDocument();
foreach (Spire.Xls.Worksheet worksheet in workbook.Worksheets.Where(x => worksheets.Contains(x.Index + 1)))
{
var pdfConverter = new PdfConverter(worksheet);
var settings = new PdfConverterSettings
{
TemplateDocument = pdfDocument,
FitSheetToOnePage = FitToPageType.NoScale,
};
pdfDocument = pdfConverter.Convert(settings);
}
using (var ms = new MemoryStream())
{
pdfDocument.SaveToStream(ms);
return ms.ToArray();
}
}
}