Skip to content
Loading
  • +2
    Hi, @Rajanikant
     
    I'm getting the error on your code:
    'xl2PDF.MainForm.VerifyRenderingInServerForm(System.Windows.Forms.Control)': no suitable method found to override (CS0115) 
    +2
  • Sachin Singh
    +2
    @jaynta there are many free libraries with which you can convert excel to pdf as
    step 1. install 
     
    1. Install-Package SautinSoft.ExcelToPdf -Version 5.4.1.20 
     step 2.  code
    1. public static void ConvertExcelAsMemoryStream()  
    2. {  
    3.     // Convert Excel to PDF in memory  
    4.     ExcelToPdf x = new ExcelToPdf();  
    5.   
    6.     // Set PDF as output format.  
    7.     x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf;  
    8.   
    9.     string excelFile = @"d:\MyWorkBook.xls";  
    10.     string pdfFile = Path.ChangeExtension(excelFile, ".pdf");  
    11.     byte[] pdfBytes = null;  
    12.   
    13.     try  
    14.     {  
    15.         // Let us say, we have a memory stream with Excel data.  
    16.         using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(excelFile)))  
    17.         {  
    18.             pdfBytes = x.ConvertBytes(ms.ToArray());  
    19.         }  
    20.         // Save pdfBytes to a file for demonstration purposes.  
    21.         File.WriteAllBytes(pdfFile, pdfBytes);  
    22.         System.Diagnostics.Process.Start(pdfFile);  
    23.     }  
    24.     catch (Exception ex)  
    25.     {  
    26.         Console.WriteLine(ex.Message);  
    27.         Console.ReadLine();  
    28.     }  
    29. } 
     
    +2
  • +2
    Hi, @Sachin.
     
    But it has the trial notice "Created by unlicensed version of Excel to PDF .Net" and the random addition of the word "TRIAL".
     
    I don't want that or is there a workaround to not show that apart from purchasing it.
     
    I'm looking for a completely free with no watermark or any trial/free version printed on the PDF.
     
    Are there any other options? 
    +2
  • +2
    You could also try Spire.XLS. 
     
    1. using Spire.Xls;  
    2.   
    3. namespace Excel_Worksheet_to_PDF  
    4. {  
    5.     class Program  
    6.     {  
    7.         static void Main(string[] args)  
    8.         {  
    9.             Workbook workbook = new Workbook();  
    10.             workbook.LoadFromFile("Sample.xlsx");  
    11.             Worksheet sheet = workbook.Worksheets[0];  
    12.             sheet.SaveToPdf("toPDF.pdf");  
    13.         }  
    14.     }  
    15. }  
     
    +2
  • +2
    You can use LEADTOOLS Document SDK technology in your application.
    https://www.leadtools.com/sdk/products/document
    You can leverage the DocumentConverter class, which does not require the Microsoft Office interop assemblies, to convert any LEADTOOLS supported file format to any other LEADTOOLS supported file format (i.e. XLS/XLSX to PDF).
    Here is some sample code:
    1. using (DocumentConverter _converter = new DocumentConverter())  
    2. {  
    3.     string inputXLSX = @"FILE PATH TO INPUT XLS/XLSX";  
    4.     string outputPDF = @"FILE PATH TO OUTPUT PDF";  
    5.   
    6.     DocumentFormat format = DocumentFormat.Pdf;  
    7.     var jobData = DocumentConverterJobs.CreateJobData(inputXLSX, outputPDF, format);  
    8.   
    9.     var job = _converter.Jobs.CreateJob(jobData);  
    10.     _converter.Jobs.RunJob(job);  
    11.   
    12.     if (job.Status == DocumentConverterJobStatus.Success)  
    13.     {  
    14.         Console.WriteLine("Success");  
    15.     }  
    16.     else  
    17.     {  
    18.         Console.WriteLine("{0} Errors", job.Status);  
    19.         foreach (var error in job.Errors)  
    20.         {  
    21.             Console.WriteLine("  {0} at {1}: {2}", error.Operation, error.InputDocumentPageNumber, error.Error.Message);  
    22.         }  
    23.     }  
    24. }  
    +2