0

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. 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. 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?

Aroueterra
  • 336
  • 3
  • 18

1 Answers1

5

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:

//printOptions.AutomaticPageBreakScalingFactor = 93;
printOptions.FitWorksheetWidthToPages = 1;
Mario Z
  • 4,328
  • 2
  • 24
  • 38
  • 1
    Oh, so these do exists. Working great so far. A few questions though. GemBox doesn't seem to be including text written in textboxes as opposed to the cell, is there any way for it to include these? This includes lines, white rectangles I made, all of which are excluded for some reason. – Aroueterra Feb 10 '17 at 09:32
  • Unfortunately no, shape elements (which includes TextBox, Line, Rectangle, etc.) are currently not supported through GemBox.Spreadsheet 4.1 API, they are supported only through a preservation (loading from and saving to same file format). There is a feature request for which you can add vote in order to increase its priority (but at the moment I cannot say when it will be available): http://support.gemboxsoftware.com/feedback/view/add-support-for-shapes-api – Mario Z Feb 10 '17 at 14:34
  • 1
    The latest versions of GemBox.Spreadsheet have support for `Shape` and `TexBox` elements, see [Excel Shapes](https://www.gemboxsoftware.com/spreadsheet/examples/excel-shapes/211) and [Excel TextBoxes](https://www.gemboxsoftware.com/spreadsheet/examples/excel-textboxes/212) examples. – Mario Z Mar 28 '20 at 12:15