Converting PDF documents to HTML format is quite essential, especially when we need to display the content online, improving accessibility, and enabling easy content reuse in web applications. In this article, you will learn how to convert PDF to HTML using GroupDocs.Conversion Cloud SDK for .NET, preserving document layout, images, and formatting.

이 기사는 다음 주제를 다룹니다:

  • PDF to HTML 변환 API
  • [C#에서 PDF를 HTML로 변환하기 위한 방법은 여러 가지가 있습니다. 일반적으로 사용되는 라이브러리 중 하나는 iTextSharp입니다. 다음은 iTextSharp를 사용하여 PDF를 HTML로 변환하는 간단한 단계입니다.
  1. iTextSharp 라이브러리 설치: NuGet 패키지 관리자를 사용하여 iTextSharp를 프로젝트에 추가합니다.

    Install-Package itext7.pdfhtml
    
  2. PDF 파일을 HTML로 변환하는 코드 작성:

    using System;
    using System.IO;
    using iText.Html2pdf;
    
    class Program
    {
        static void Main(string[] args)
        {
            string pdfFilePath = "path/to/your/file.pdf"; // PDF 파일 경로
            string outputFilePath = "path/to/your/output.html"; // 출력 HTML 파일 경로
    

]6

PDF to HTML 변환 API

GroupDocs.Conversion Cloud SDK for .NET는 PDF 문서를 높은 정확도로 HTML로 변환하는 강력한 API를 제공합니다. 이는 출력 HTML을 사용자 정의하고, 페이지 범위를 정의하며, 이미지 품질을 제어할 수 있어 .NET 애플리케이션에서 문서-웹 워크플로우를 통합하는 데 이상적입니다.

설치

SDK를 NuGet 패키지 관리자 를 통해 설치하세요:

Install-Package GroupDocs.Conversion-Cloud -Version 24.2.0

또는 .NET CLI를 사용하여:

dotnet add package GroupDocs.Conversion-Cloud --version 24.2.0

이제 API 요청을 인증하기 위해 Aspose Cloud Dashboard에서 개인화된 클라이언트 ID와 클라이언트 비밀을 얻어야 합니다.

PDF를 C# (.NET)에서 HTML로 변환하십시오.

다음은 PDF를 HTML로 변환하는 단계별 C# 예제입니다:

  1. API 자격 증명 구성:
var config = new Configuration
{
    ClientId = "YOUR_CLIENT_ID",
    ClientSecret = "YOUR_CLIENT_SECRET"
};

var convertApi = new ConvertApi(config);
var fileApi = new FileApi(config);
  1. Cloud Storage에 PDF 파일을 업로드하세요:
using (var fileStream = File.OpenRead("sample.pdf"))
{
    var uploadRequest = new UploadFileRequest("sample.pdf", fileStream);
    fileApi.UploadFile(uploadRequest);
}
  1. 변환 설정 설정:
var settings = new ConvertSettings
{
    FilePath = "sample.pdf",
    Format = "html",
    OutputPath = "converted/resultant.html"
};
  1. PDF를 HTML로 변환 수행:
var request = new ConvertDocumentRequest(settings);
convertApi.ConvertDocument(request);
using System;
using GroupDocs.Conversion.Cloud.Sdk.Api;
using GroupDocs.Conversion.Cloud.Sdk.Client;
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests;
using System.IO;
using GroupDocs.Conversion.Cloud.Sdk.Model;

namespace GroupDocs.Conversion.CSharp
{
    // PDF를 HTML로 변환하십시오.
    class PDFConversion

    {
        static void Main(string[] args)
        {

            try
            {
                // API 자격 증명을 받으세요. 
                string clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
                string clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
                string myStorage = "test";

                // Configuration 클래스의 인스턴스를 클라이언트 비밀(Client Secret) 및 클라이언트 ID(Client ID)로 인스턴스화하십시오. 
                var configuration = new Configuration(clientId, clientSecret);
                // ApiBaseUrl의 값을 정의하여 API의 기본 URL을 설정합니다.
                configuration.ApiBaseUrl = "https://api.groupdocs.cloud";

                // ConvertApi 클래스의 객체를 Configuration 클래스의 객체로 초기화합니다.
                var apiInstance = new ConvertApi(configuration);
                // ConvertSettings 클래스의 인스턴스를 만드세요.
                var settings = new ConvertSettings
                {
                    FilePath = "sample.pdf",
                    Format = "html",
                    OutputPath = "converted/resultant.html"
                };

                // API를 호출하여 PDF를 웹 페이지로 변환합니다.
                var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
                Console.WriteLine("Successfully converted the PDF file to HTML format in C#: " + response[0].Url);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling GroupDocs Api: " + e.Message);
            }

        }
    }
}
free pdf to html online

Image:- PDF에서 HTML로 변환 미리보기.

  • 위 예제에서 사용된 샘플 PDF는 input.pdf에서 다운로드할 수 있습니다.

PDF를 웹 페이지로 변환하기 위해 cURL 사용하기

You can also use the GroupDocs.Conversion Cloud REST API with cURL for quick command-line conversion.

  • 귀하의 자격 증명으로 JWT 액세스 토큰을 생성하세요.
  • Run the following cURL command:
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"default\",  \"FilePath\": \"{sourcePDF}\",  \"Format\": \"html\",  \"OutputPath\": \"{resultantFile}\"}"
  • 다음 명령을 실행하여 HTML을 로컬 드라이브에 저장하십시오:
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"default\",  \"FilePath\": \"{sourceFile}\",  \"Format\": \"html\"}" \
-o "{resultantFile}"
  • sourceFile, resultantFile, and accessToken를 실제 값으로 교체하십시오.

무료 PDF to HTML 변환기를 사용해 보세요.

Try our free PDF to HTML Converter App to see the conversion quality before integrating it into your application.

무료 PDF에서 HTML 변환기 온라인

유용한 링크

결론

GroupDocs.Conversion Cloud SDK for .NET를 사용하면 PDF를 HTML로 변환하는 기능을 .NET 프로젝트에 쉽게 통합할 수 있으며, 포맷을 유지하면서 고품질의 웹 호환 출력을 가능하게 합니다. C#에서 SDK를 사용하든 cURL을 통해 직접 REST API를 호출하든, 과정은 간단하고 매우 사용자 정의가 가능합니다.

추천 기사

다음 기사를 탐색하는 것을 강력히 권장합니다: