Exemplo n.º 1
0
        public void TestMethod_ConvertXlsxDocumentToPDF_Force_Portrait()
        {
            using (IExcelToPdfService service = new ExcelToPdfService(_logger))
            {
                SaveWorkbookToPdfRequest model = new SaveWorkbookToPdfRequest()
                {
                    DestinationFilePath = Path.Combine(Directory.GetCurrentDirectory(), "VecompSoftwareTest.xlsx.pdf"),
                    SourceFilePath      = Path.Combine(Directory.GetCurrentDirectory(), @"TestFiles\VecompSoftwareTest.xlsx"),
                    ForcePortrait       = true,
                };

                Assert.IsTrue(service.SaveTo(model));
            }
        }
Exemplo n.º 2
0
 public bool Convert(string source, string destination, ConversionMode conversionMode = ConversionMode.Default)
 {
     using (_service = new ExcelToPdfService(_logger))
     {
         SaveWorkbookToPdfRequest model = new SaveWorkbookToPdfRequest()
         {
             DestinationFilePath = destination,
             ForcePortrait       = ForcePortrait,
             FitToPagesTall      = FitToPagesTall,
             FitToPagesWide      = FitToPagesWide,
             SourceFilePath      = source
         };
         return(_service.SaveTo(model));
     }
 }
Exemplo n.º 3
0
 private void ForcePortrait(dynamic sheet, SaveWorkbookToPdfRequest model)
 {
     if (model.FitToPagesTall.HasValue || model.FitToPagesWide.HasValue)
     {
         sheet.PageSetup.Zoom = false;
         if (model.FitToPagesTall.HasValue)
         {
             sheet.PageSetup.FitToPagesTall = model.FitToPagesTall.Value;
         }
         if (model.FitToPagesWide.HasValue)
         {
             sheet.PageSetup.FitToPagesWide = model.FitToPagesWide.Value;
         }
     }
     sheet.PageSetup.Orientation = WorkbookOrientation.Portrait;
 }
Exemplo n.º 4
0
        private void SetSheetsPaging(SaveWorkbookToPdfRequest model)
        {
            if (_excelWorkbook.Sheets == null)
            {
                return;
            }

            foreach (dynamic sheet in _excelWorkbook.Sheets)
            {
                if (model.ForcePortrait)
                {
                    ForcePortrait(sheet, model);
                }
                sheet.PageSetup.PaperSize = WorkbookPaperSize.A4;
            }
        }
Exemplo n.º 5
0
        public bool SaveTo(SaveWorkbookToPdfRequest model)
        {
            try
            {
                return(RetryingPolicyAction <bool>(() =>
                {
                    _logger.WriteInfo(new LogMessage(string.Concat("SaveTo -> process item ", model.SourceFilePath, ". Workbook type: ", Path.GetExtension(model.SourceFilePath))), LogCategories);
                    OpenWorkbook(model.SourceFilePath);

                    SetSheetsPaging(model);

                    _excelWorkbook.ExportAsFixedFormat(WorkbookExportFormat.PDF, model.DestinationFilePath);
                    _logger.WriteInfo(new LogMessage("SaveTo -> item saved to pdf correctly"), LogCategories);
                    return true;
                }, "EXCEL", _logger, LogCategories));
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage(string.Concat("SaveTo -> error on convert item ", model.SourceFilePath, " to pdf")), ex, LogCategories);
                throw;
            }
        }