Example #1
0
        public bool SaveTo(SaveDocumentToPdfRequest model)
        {
            try
            {
                return(RetryingPolicyAction <bool>(() =>
                {
                    _logger.WriteInfo(new LogMessage(string.Concat("SaveTo -> process item ", model.SourceFilePath, ". Document type: ", Path.GetExtension(model.SourceFilePath))), LogCategories);
                    OpenDocument(model.SourceFilePath);
                    if (HasShapesToRedirect(model.RedirectFilters))
                    {
                        return false;
                    }

                    if (_wordDocument.Sections != null && model.ForcePortrait)
                    {
                        ForcePortrait();
                    }

                    _wordDocument.ExportAsFixedFormat(model.DestinationFilePath, DocumentExportFormat.PDF, false, DocumentExportOptimizeFor.Print, DocumentExportRange.AllDocument, 1, 1, DocumentExportItem.DocumentContent, true,
                                                      true, DocumentExportCreateBookmarks.NoBookmarks, true, true, true);
                    _logger.WriteInfo(new LogMessage("SaveTo -> item saved to pdf correctly"), LogCategories);
                    return true;
                }, "WINWORD", _logger, LogCategories));
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage(string.Concat("SaveTo -> error on convert item ", model.SourceFilePath, " to pdf")), ex, LogCategories);
                throw;
            }
        }
Example #2
0
        public void TestMethod_ConvertDocxDocumentToPDF_Force_Portrait()
        {
            using (IWordToPdfService service = new WordToPdfService(_logger))
            {
                SaveDocumentToPdfRequest model = new SaveDocumentToPdfRequest()
                {
                    DestinationFilePath = Path.Combine(Directory.GetCurrentDirectory(), "VecompSoftwareTest.docx.pdf"),
                    SourceFilePath      = Path.Combine(Directory.GetCurrentDirectory(), @"TestFiles\VecompSoftwareTest.docx"),
                    ForcePortrait       = true,
                };

                Assert.IsTrue(service.SaveTo(model));
            }
        }
Example #3
0
 public bool Convert(string source, string destination, ConversionMode conversionMode = ConversionMode.Default)
 {
     using (_service = new WordToPdfService(_logger))
     {
         SaveDocumentToPdfRequest model = new SaveDocumentToPdfRequest()
         {
             DestinationFilePath = destination,
             ForcePortrait       = ForcePortrait,
             RedirectFilters     = RedirectFilters,
             SourceFilePath      = source
         };
         return(_service.SaveTo(model));
     }
 }