P
The PdfDocument generated using the code below, send the last column of the Excel spreadsheet to another page in the PDF file
PdfDocument pdf = ExcelToPDF(fullPathName)
pdf.SaveToFile(newFullPathName, Spire.Pdf.FileFormat.PDF);
method:
public PdfDocument ExcelToPDF(string fullPathName)
{
if (String.IsNullOrWhiteSpace(fullPathName)) { throw new ArgumentException("No source file name provided"); }
string ext = Path.GetExtension(fullPathName).ToLower();
if (String.IsNullOrWhiteSpace(ext)) { throw new ArgumentException("Source file has no extension"); }
if (!File.Exists(fullPathName)) { throw new IOException("Source file does not exist"); }
if (!FileSystemHelper.ExcelExtensions.Contains(ext)) { throw new ArgumentException("No Excel file provided"); }
PdfDocument newPdf = new PdfDocument();
MemoryStream ms = new MemoryStream();
using (Spire.Xls.Workbook excelFile = new Workbook())
{
excelFile.LoadFromFile(fullPathName);
excelFile.SaveToStream(ms, Spire.Xls.FileFormat.PDF);
}
newPdf.LoadFromStream(ms);
return newPdf;
}
I had to add the following line to get it to work properly with the provided file adding the lines:
Spire.Xls.PageSetup pageSetup;
pageSetup=excelFile.Worjsheets[0].PageSetup;
pageSetup.FitToPageWide=1;
pageSetup.FitToPageTall=0;
INFO:
Spire.PDF for .NET version 11.6.14
Spire.XLS for .NET version 15.6.6
Winforms Application, net framework 4.8.1
Windows 11, 64 bit