Как преобразовать DOCX, RTF, HTML в PDF под .NET Core на C# и .NET


Полный код

using System.IO;

namespace Sample
{
    internal class Test
    {

        private static void Main(string[] args)
        {
			// Activate your license here
			// SautinSoft.PdfMetamorphosis.SetLicense("1234567890");

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            //Prepare variables with path.
            string docxFile = Path.GetFullPath(@"..\..\..\example.docx");
            string pdfFileFromDocx = Path.GetFullPath(@"..\..\..\exampleResultDocx.pdf");
            string rtfFile = Path.GetFullPath(@"..\..\..\example.rtf");
            string pdfFileFromRtf = Path.GetFullPath(@"..\..\..\exampleResultRtf.pdf");
            string htmlFile = Path.GetFullPath(@"..\..\..\example.htm");
            string pdfFileFromHtml = Path.GetFullPath(@"..\..\..\exampleResultHtml.pdf");
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(Path.GetFullPath(@"..\..\..\")) { UseShellExecute = true });

            // Convert DOCX file to PDF file
            p.DocxToPdfConvertFile(docxFile, pdfFileFromDocx);
            // Convert RTF file to PDF file
            p.RtfToPdfConvertFile(rtfFile, pdfFileFromRtf);
            // Convert HTML file to PDF file
            p.HtmlToPdfConvertFile(htmlFile, pdfFileFromHtml);
        }
    }
}

Download

Imports System.IO

Namespace Sample
    Friend Class Test

        Shared Sub Main(ByVal args() As String)
            ' Activate your license here
			' SautinSoft.PdfMetamorphosis.SetLicense("1234567890")

			Dim p As New SautinSoft.PdfMetamorphosis()

            ' Prepare variables with path.
            Dim docxFile As String = Path.GetFullPath("..\..\..\example.docx")
            Dim pdfFileFromDocx As String = Path.GetFullPath("..\..\..\exampleFromDocx.pdf")
            Dim rtfFile As String = Path.GetFullPath("..\..\..\example.rtf")
            Dim pdfFileFromRtf As String = Path.GetFullPath("..\..\..\exampleFromRtf.pdf")
            Dim htmlFile As String = Path.GetFullPath("..\..\..\example.htm")
            Dim pdfFileFromHtml As String = Path.GetFullPath("..\..\..\exampleFromHtml.pdf")
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(Path.GetFullPath("..\..\..\")) With {.UseShellExecute = True})

            ' Convert DOCX file to PDF file
            p.DocxToPdfConvertFile(docxFile, pdfFileFromDocx)
			' Convert RTF file to PDF file
            p.RtfToPdfConvertFile(rtfFile, pdfFileFromRtf)
			' Convert HTML file to PDF file
            p.HtmlToPdfConvertFile(htmlFile, pdfFileFromHtml)
        End Sub
    End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.