简体   繁体   English

使用Gembox.Spreadsheets将.Xlsx转换为PDF

[英]Using Gembox.Spreadsheets to convert .Xlsx to PDF

I was looking for free alternatives to Spire.Xls that allow me to convert from .Xlsx format to .PDF, so far, Gembox is doing great work. 我一直在寻找Spire.Xls的免费替代品,这些替代品使我可以将.Xlsx格式转换为.PDF,到目前为止,Gembox做得很好。 However, I cant seem to get the scaling right, and as far as I've looked noone has had the same problem. 但是,我似乎无法正确进行缩放,就我看来,没有人遇到过相同的问题。 I'm trying to set the scaling to 93% of the original size with 0 margins all around. 我正在尝试将缩放比例设置为原始大小的93%,周围全部有0个边距。 However, I cant seem to find the documentation of code that mentions this. 但是,我似乎找不到提到此的代码文档。 It isn't in their sample files either. 它们的样本文件中也没有。

Does anyone with experience with this DLL know where I should be looking? 有这个DLL经验的人知道我应该去哪里吗?

Use the following: 使用以下内容:

var workbook = ExcelFile.Load("Sample.xlsx");

foreach (var worksheet in workbook.Worksheets)
{
    var printOptions = worksheet.PrintOptions;
    printOptions.LeftMargin =
    printOptions.RightMargin =
    printOptions.TopMargin =
    printOptions.BottomMargin = 0;

    printOptions.AutomaticPageBreakScalingFactor = 93;
}

var saveOptions = new PdfSaveOptions();
saveOptions.SelectionType = SelectionType.EntireFile;

workbook.Save("Sample Output.pdf", saveOptions);

Also, I'm not sure why exactly you want to use 93% scaling, but in case you want to achieve fitting of all worksheet's columns on a single page's width then you should use the following instead: 另外,我不确定为什么要精确地使用93%的缩放比例,但是如果要在单个页面的宽度上实现所有工作表的列的拟合,则应该使用以下内容:

//printOptions.AutomaticPageBreakScalingFactor = 93;
printOptions.FitWorksheetWidthToPages = 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM