Hello,
I have a template in excel whose print area I have set and size is Letter 8.511. It is dynamic excel template, based on user input the columns get hide or show. So, sometimes the output will be 40 columns , sometimes it will be less. At the end I am converting Excel to PDF but the paper size comes out to be very different, sometimes 19.520 etc.
My code to convert excel to pdf -
ConvertExcelToPDF(buffer, “Landscape”, “PaperLetter”, 1, 1, true, true);
public byte[] ConvertExcelToPDF(byte[] ExcelOutput, string PageOrientation, string PaperSize, int FitToPagesTall, int FitToPagesWide, bool CenterHorizontally, bool CenterVertically)
{
PageOrientationType PageOrientationType;
PaperSizeType PaperSizeType;
MemoryStream PDFStream = new MemoryStream();
MemoryStream ExcelStream = new MemoryStream(ExcelOutput);
Workbook wb = new Workbook(ExcelStream);
PageOrientationType = (PageOrientationType)Enum.Parse(typeof(PageOrientationType), PageOrientation);
PaperSizeType = (PaperSizeType)Enum.Parse(typeof(PaperSizeType), PaperSize);
foreach (Worksheet ws in wb.Worksheets)
{
ws.PageSetup.PaperSize = PaperSizeType;
ws.PageSetup.Orientation = PageOrientationType;
//ws.PageSetup.CenterHorizontally = CenterHorizontally;
//ws.PageSetup.CenterVertically = CenterVertically;
ws.PageSetup.FitToPagesTall = FitToPagesTall;
ws.PageSetup.FitToPagesWide = FitToPagesWide;
ws.PageSetup.RightMarginInch = 0.25;
ws.PageSetup.TopMarginInch = 0.25;
ws.PageSetup.LeftMarginInch = 0.25;
ws.PageSetup.BottomMarginInch = 0.25;
ws.PageSetup.HeaderMarginInch = 0.3;
ws.PageSetup.FooterMarginInch = 0.3;
ws.PageSetup.Zoom = 50;
//ws.PageSetup.PrintArea = "Print_Area";
}
ImageSaveOptions imgSaveOption = new ImageSaveOptions();
imgSaveOption.ImageOrPrintOptions.OnePagePerSheet = true;
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(SaveFormat.Pdf);
pdfSaveOptions.OnePagePerSheet = true;
pdfSaveOptions.DefaultFont = "Arial Narrow";
pdfSaveOptions.PrintingPageType = PrintingPageType.Default;
wb.CalculateFormula();
wb.Save(PDFStream, pdfSaveOptions);
return PDFStream.ToArray();
}
I have one more question, why after every time I convert excel to PDF, the font become bold for whole document. I have attached a message box once I generate PDF from Excel.
I would appreciate your help.
Thanks,
Sarthak
aspose convertion.jpg (28.5 KB)
pdf size.PNG (759 Bytes)