C#에서 Microsoft DOCX를 PDF로 변환하는 방법
IronPDF는 C#에서 Word 문서를 PDF로 변환합니다. DocxToPdfRenderer 클래스: RenderDocxAsPdf는 파일 경로, 바이트 배열, 또는 스트림을 받아들이고, DocxPdfRenderOptions는 메일 병합 및 페이지 설정을 설정합니다. 모든 호출은 PdfDocument를 반환하므로, 동일한 객체는 이후에 헤더, 워터마크, 비밀번호 또는 아카이브 내보내기를 처리합니다.
Word는 문서가 작성되는 곳이고, PDF는 보내지는 곳입니다. 변환은 대부분의 문서 파이프라인의 끝에 있습니다: 서명이 필요한 계약서, 고객에게 발송할 송장, 아카이브에 넣을 보고서 등이 이에 포함됩니다. PDF는 모든 기기에서 레이아웃을 유지하지만, DOCX는 상대 기기의 폰트와 Word 버전에 의존합니다.
IronPDF Word 문서를 PDF 파일로 즉시 변환할 수 있을 뿐만 아니라, 개별 수신자에게 맞춤형 문서를 일괄적으로 생성할 수 있는 메일 병합 기능도 제공합니다. DOCX 파일을 PDF로 변환하면 범용 호환성이 보장되고 서식이 유지되며 보안이 강화됩니다. 이 기능은 HTML에서 PDF를 생성하거나 이미지를 PDF로 변환하는 것과 유사하게, 다른 기기와 운영 체제 간에 정확한 모양을 유지해야 하는 문서를 배포할 때 특히 유용합니다.
빠른 시작: IronPDF 사용하여 DOCX를 PDF로 변환하기하나의 클래스, 하나의 메서드, 하나의 줄. DocxToPdfRenderer는 파일을 읽고 RenderDocxAsPdf는 저장할 준비가 된 PdfDocument를 반환합니다.
-
1IronPDF를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
new IronPdf.DocxToPdfRenderer() .RenderDocxAsPdf("document.docx") .SaveAs("output.pdf");Dim renderer As New IronPdf.DocxToPdfRenderer() renderer.RenderDocxAsPdf("document.docx").SaveAs("output.pdf")Dim renderer As New IronPdf.DocxToPdfRenderer() renderer.RenderDocxAsPdf("document.docx").SaveAs("output.pdf") -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronPDF 사용을 시작해보세요 무료 체험
최소 워크플로우(5단계)
- DOCX를 PDF로 변환하는 C# 라이브러리 다운로드
- 변환할 DOCX 파일을 준비하세요.
- DocxToPdfRenderer 클래스를 인스턴스화하여 DOCX 파일에서 PDF로 렌더링합니다
RenderDocxAsPdf를 호출하고 DOCX 파일 경로를 제공합니다- 메일 병합 기능을 활용하여 여러 문서를 일괄 생성하세요.
DOCX 파일을 PDF로 변환하는 방법은 무엇인가요?
IronPDF는 개발자가 Word 문서를 PDF로 프로그래밍적으로 변환할 수 있도록 하여 효율성을 간단하게 하고, 기존 .NET 애플리케이션이나 그들이 보유한 모든 크로스 플랫폼 .NET Framework 애플리케이션에 통합할 수 있게 합니다. 라이브러리는 NuGet 패키지를 포함한 다양한 설치 방법을 지원하고, Windows, Linux, macOS를 포함한 여러 플랫폼에서 배포될 수 있습니다.
전제합니다 DocxToPdfRenderer를 인스턴스화한 다음, 파일의 경로와 함께 RenderDocxAsPdf를 호출합니다. 이 메서드는 PdfDocument 객체를 반환하여, 헤더 및 푸터 추가, 워터마크 적용, 보안 옵션 설정을 포함한 PDF를 추가적으로 커스터마이즈할 수 있게 합니다. 현대적인 연대순 이력서 DOCX 예제 파일를 다운로드할 수 있습니다.
입력

C# 코드는 어떻게 작성하나요?
using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");Imports IronPdf
' Instantiate Renderer
Dim renderer As New DocxToPdfRenderer()
' Render from DOCX file
Dim pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")
' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")Imports IronPdf
' Instantiate Renderer
Dim renderer As New DocxToPdfRenderer()
' Render from DOCX file
Dim pdf As PdfDocument = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx")
' Save the PDF
pdf.SaveAs("pdfFromDocx.pdf")산출
결과 PDF는 원본 서식(폰트, 색상, 레이아웃 및 포함된 이미지 포함)을 보존합니다.
스트림 또는 바이트 배열에서 DOCX를 변환하는 방법?
문서가 디스크에 있는 파일이 아닌 메모리 또는 데이터베이스에서 오는 경우, RenderDocxAsPdf는 바이트 배열이나 스트림도 수용합니다:
// Convert from byte array
byte[] docxBytes = File.ReadAllBytes("document.docx");
PdfDocument pdfFromBytes = renderer.RenderDocxAsPdf(docxBytes);
// Convert from stream
using (FileStream stream = new FileStream("document.docx", FileMode.Open))
{
PdfDocument pdfFromStream = renderer.RenderDocxAsPdf(stream);
}// Convert from byte array
byte[] docxBytes = File.ReadAllBytes("document.docx");
PdfDocument pdfFromBytes = renderer.RenderDocxAsPdf(docxBytes);
// Convert from stream
using (FileStream stream = new FileStream("document.docx", FileMode.Open))
{
PdfDocument pdfFromStream = renderer.RenderDocxAsPdf(stream);
}Imports System.IO
' Convert from byte array
Dim docxBytes As Byte() = File.ReadAllBytes("document.docx")
Dim pdfFromBytes As PdfDocument = renderer.RenderDocxAsPdf(docxBytes)
' Convert from stream
Using stream As New FileStream("document.docx", FileMode.Open)
Dim pdfFromStream As PdfDocument = renderer.RenderDocxAsPdf(stream)
End UsingImports System.IO
' Convert from byte array
Dim docxBytes As Byte() = File.ReadAllBytes("document.docx")
Dim pdfFromBytes As PdfDocument = renderer.RenderDocxAsPdf(docxBytes)
' Convert from stream
Using stream As New FileStream("document.docx", FileMode.Open)
Dim pdfFromStream As PdfDocument = renderer.RenderDocxAsPdf(stream)
End Using같은 파일을 바이트로 읽거나 스트림으로 읽으면 위의 PDF와 동일한 결과를 생성합니다; 단지 문서가 렌더러에 도달하는 방법만 다릅니다.
C# 비동기로 DOCX를 PDF로 변환하는 방법?
RenderDocxAsPdfAsync는 웹 요청이나 데스크톱 UI에서 중요한 호출 스레드를 차단하지 않고 파일 경로에서 렌더링합니다. 비동기 오버로드는 파일 경로만 수용합니다; 위의 바이트 배열 및 스트림 오버로드는 여전히 동기적입니다.
using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file without blocking the calling thread
PdfDocument pdf = await renderer.RenderDocxAsPdfAsync("document.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocxAsync.pdf");using IronPdf;
// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();
// Render from DOCX file without blocking the calling thread
PdfDocument pdf = await renderer.RenderDocxAsPdfAsync("document.docx");
// Save the PDF
pdf.SaveAs("pdfFromDocxAsync.pdf");Imports IronPdf
' Instantiate Renderer
Dim renderer As DocxToPdfRenderer = New DocxToPdfRenderer()
' Render from DOCX file without blocking the calling thread
Dim pdf As PdfDocument = Await renderer.RenderDocxAsPdfAsync("document.docx")
' Save the PDF
pdf.SaveAs("pdfFromDocxAsync.pdf")Imports IronPdf
' Instantiate Renderer
Dim renderer As DocxToPdfRenderer = New DocxToPdfRenderer()
' Render from DOCX file without blocking the calling thread
Dim pdf As PdfDocument = Await renderer.RenderDocxAsPdfAsync("document.docx")
' Save the PDF
pdf.SaveAs("pdfFromDocxAsync.pdf")출력은 동일한 문서가 동일한 방식으로 렌더링됩니다; 단지 실행 중에 호출 스레드만 유휴 상태로 유지됩니다.
메일 병합 기능을 사용하여 PDF 파일을 일괄 생성하는 방법은 무엇인가요?
Microsoft Word의 "메일링" 탭에 있는 "메일 병합" 기능을 사용하면 각 수신자 또는 데이터 항목에 맞게 개인화된 정보를 포함하는 문서를 일괄적으로 만들 수 있습니다. 이 기능은 초대장, 뉴스레터 또는 양식 편지와 같이 내용의 대부분은 동일하지만 수신자마다 특정 세부 사항이 다른 개인 맞춤형 편지, 봉투, 라벨 또는 이메일 메시지를 생성하는 데 자주 사용됩니다. 이 기능은 IronPDF의 여러 PDF를 병합하는 능력이나 커스텀 메타데이터로 문서를 생성하는 능력과 결합할 때 특히 강력합니다.
어떤 데이터 모델을 만들어야 할까요?
병합될 값을 보관할 모델을 생성하세요. 데이터 모델의 속성 이름은 Word 템플릿의 병합 필드 이름과 정확히 일치해야 합니다(대소문자 구분).
internal class RecipientsDataModel
{
public string Date { get; set; }
public string Location{ get; set; }
public string Recipients_Name { get; set; }
public string Contact_Us { get; set; }
}internal class RecipientsDataModel
{
public string Date { get; set; }
public string Location{ get; set; }
public string Recipients_Name { get; set; }
public string Contact_Us { get; set; }
}Friend Class RecipientsDataModel
Public Property [Date]() As String
Public Property Location() As String
Public Property Recipients_Name() As String
Public Property Contact_Us() As String
End ClassFriend Class RecipientsDataModel
Public Property [Date]() As String
Public Property Location() As String
Public Property Recipients_Name() As String
Public Property Contact_Us() As String
End Class아래 템플릿은 병합 필드가 추가된 Microsoft Word 샘플입니다. 파티 초대장 DOTX 예제 파일 다운로드. PDF를 하나의 PdfDocument 객체로 결합하려면 MailMergePrintAllInOnePdfDocument 속성을 true로 설정하세요. 여기 사용된 병합 필드는 Date, Location, Recipient's Name, 그리고 Contact Us 입니다.
입력

메일 병합 코드를 어떻게 구현하나요?
IronPDF의 메일 병합 기능은 DocxPdfRenderOptions 클래스를 통해 구성할 수 있는 다양한 렌더링 옵션을 지원합니다. 이를 통해 페이지 방향, 여백, 병합된 모든 문서를 단일 PDF로 결합할지 또는 개별 파일로 생성할지 여부와 같은 여러 측면을 제어할 수 있습니다.
MailMergePrintAllInOnePdfDocument를 true로 설정하고, 수신자별로 개별 문서를 얻으려면 false로 두십시오.using IronPdf;
using System.Collections.Generic;
using System.Linq;
var recipients = new List<RecipientsDataModel>()
{
new RecipientsDataModel()
{
Date ="Saturday, October 15th, 2023",
Location="Iron Software Cafe, Chiang Mai",
Recipients_Name="Olivia Smith",
Contact_Us = "support@ironsoftware.com"
},
new RecipientsDataModel()
{
Date ="Saturday, October 15th, 2023",
Location="Iron Software Cafe, Chiang Mai",
Recipients_Name="Ethan Davis",
Contact_Us = "support@ironsoftware.com"
},
};
DocxToPdfRenderer docxToPdfRenderer = new DocxToPdfRenderer();
// Apply render options
DocxPdfRenderOptions options = new DocxPdfRenderOptions();
// Configure the output PDF to be combined into a single PDF document
options.MailMergePrintAllInOnePdfDocument = true;
// Convert DOTX to PDF
var pdfs = docxToPdfRenderer.RenderDocxMailMergeAsPdf<RecipientsDataModel>(
recipients,
"Party-invitation.dotx",
options);
pdfs.First().SaveAs("mailMerge.pdf");using IronPdf;
using System.Collections.Generic;
using System.Linq;
var recipients = new List<RecipientsDataModel>()
{
new RecipientsDataModel()
{
Date ="Saturday, October 15th, 2023",
Location="Iron Software Cafe, Chiang Mai",
Recipients_Name="Olivia Smith",
Contact_Us = "support@ironsoftware.com"
},
new RecipientsDataModel()
{
Date ="Saturday, October 15th, 2023",
Location="Iron Software Cafe, Chiang Mai",
Recipients_Name="Ethan Davis",
Contact_Us = "support@ironsoftware.com"
},
};
DocxToPdfRenderer docxToPdfRenderer = new DocxToPdfRenderer();
// Apply render options
DocxPdfRenderOptions options = new DocxPdfRenderOptions();
// Configure the output PDF to be combined into a single PDF document
options.MailMergePrintAllInOnePdfDocument = true;
// Convert DOTX to PDF
var pdfs = docxToPdfRenderer.RenderDocxMailMergeAsPdf<RecipientsDataModel>(
recipients,
"Party-invitation.dotx",
options);
pdfs.First().SaveAs("mailMerge.pdf");Imports IronPdf
Imports System.Collections.Generic
Imports System.Linq
Private recipients = New List(Of RecipientsDataModel)() From {
New RecipientsDataModel() With {
.Date ="Saturday, October 15th, 2023",
.Location="Iron Software Cafe, Chiang Mai",
.Recipients_Name="Olivia Smith",
.Contact_Us = "support@ironsoftware.com"
},
New RecipientsDataModel() With {
.Date ="Saturday, October 15th, 2023",
.Location="Iron Software Cafe, Chiang Mai",
.Recipients_Name="Ethan Davis",
.Contact_Us = "support@ironsoftware.com"
}
}
Private docxToPdfRenderer As New DocxToPdfRenderer()
' Apply render options
Private options As New DocxPdfRenderOptions()
' Configure the output PDF to be combined into a single PDF document
options.MailMergePrintAllInOnePdfDocument = True
' Convert DOTX to PDF
Dim pdfs = docxToPdfRenderer.RenderDocxMailMergeAsPdf(Of RecipientsDataModel)(recipients, "Party-invitation.dotx", options)
pdfs.First().SaveAs("mailMerge.pdf")Imports IronPdf
Imports System.Collections.Generic
Imports System.Linq
Private recipients = New List(Of RecipientsDataModel)() From {
New RecipientsDataModel() With {
.Date ="Saturday, October 15th, 2023",
.Location="Iron Software Cafe, Chiang Mai",
.Recipients_Name="Olivia Smith",
.Contact_Us = "support@ironsoftware.com"
},
New RecipientsDataModel() With {
.Date ="Saturday, October 15th, 2023",
.Location="Iron Software Cafe, Chiang Mai",
.Recipients_Name="Ethan Davis",
.Contact_Us = "support@ironsoftware.com"
}
}
Private docxToPdfRenderer As New DocxToPdfRenderer()
' Apply render options
Private options As New DocxPdfRenderOptions()
' Configure the output PDF to be combined into a single PDF document
options.MailMergePrintAllInOnePdfDocument = True
' Convert DOTX to PDF
Dim pdfs = docxToPdfRenderer.RenderDocxMailMergeAsPdf(Of RecipientsDataModel)(recipients, "Party-invitation.dotx", options)
pdfs.First().SaveAs("mailMerge.pdf")산출
결론
DocxToPdfRenderer는 한 번의 호출로 Word 파일, 바이트 배열 또는 스트림을 PdfDocument로 변환하며, DocxPdfRenderOptions는 동일한 호출을 전체 수신자 목록에 걸쳐 메일 병합 실행으로 전환합니다. 반환되는 것은 일반 IronPDF 문서이므로 라이브러리가 PDF에 대해 수행하는 모든 작업을 이 문서에도 수행합니다.
PdfDocument는 PDF/A 또는 PDF/UA 내보내기, 디지털 서명, 또는 권한과 비밀번호를 처리합니다.여기에서, 결과를 내보내기하여 디스크, 메모리, 또는 HTTP 응답으로 변환하거나, 다른 소스에서 Markdown을 PDF로 및 RTF를 PDF로 변환합니다.
문제 해결
- IronPDF에서 라이선스 키 적용하기: 변환된 PDF에 워터마크가 포함되어 있는 경우
- Windows와 Linux 간의 폰트 불일치: 변환된 문서의 폰트가 플랫폼 간에 다르게 보이는 경우
- IronPDF에서 RenderingOptions를 올바르게 초기화하기:
DocxPdfRenderOptions속성이 해결되지 않으면 예외를 발생시키는 경우
질문?
질문이 있으시면 support@ironsoftware.com으로 문의하세요.
자주 묻는 질문
IronPDF에서 DocxToPdfRenderer의 주요 기능은 무엇입니까?
IronPDF의 DocxToPdfRenderer 클래스는 Microsoft Word 문서(DOCX)를 PDF 형식으로 변환하는 데 사용됩니다. 이 변환은 문서의 레이아웃을 기기 간에 유지하여 글꼴, 색상 및 전체 구조를 보존합니다.
IronPDF가 메일 머지 작업에 어떻게 도움을 줄 수 있나요?
IronPDF는 DocxPdfRenderOptions 클래스를 통해 메일 머지를 지원하여 사용자들이 개인화된 문서의 배치를 생성할 수 있게 합니다. 이는 특히 개인화된 편지와 같이 각 문서에 고유한 수신자 데이터가 필요한 대량 커뮤니케이션을 생성하는데 유용합니다.
IronPDF가 파일 외의 다른 소스로부터 DOCX 입력을 처리할 수 있습니까?
네, IronPDF의 RenderDocxAsPdf 메소드는 또한 바이트 배열 또는 스트림으로부터 DOCX 내용을 처리할 수 있어, 메모리나 데이터베이스에 저장된 문서에 이상적입니다.
DOCX를 PDF로 비동기 변환하는 것이 성능에 어떻게 도움이 됩니까?
RenderDocxAsPdfAsync를 사용하면 DOCX를 PDF로 변환하면서 호출 스레드를 차단하지 않으므로, 응답성을 유지하는 것이 중요한 웹 서버 또는 데스크톱 응용 프로그램과 같은 환경에서 유익합니다.
DOCX를 PDF로 변환하는 것은 어떤 이점을 제공합니까?
DOCX를 PDF로 변환하면 다양한 기기 및 운영 시스템 간의 호환성을 보장하고, 문서 형식을 유지하며, 보안 층을 추가하여 PDFs는 최종 문서를 공유하기에 이상적입니다.
IronPDF는 변환 중 문서 레이아웃 보존을 어떻게 보장합니까?
IronPDF는 글꼴, 색상, 레이아웃 및 포함된 이미지들을 정확하게 보존하여 변환 중 문서의 원래 형식을 유지하여 원래 DOCX와 동일한 PDF를 생성합니다.
IronPDF를 사용하여 한 줄의 코드로 Microsoft Word 문서를 PDF로 렌더링할 수 있습니까?
네, IronPDF는 DocxToPdfRenderer 객체를 인스턴스화하고 원하는 DOCX 파일 경로와 함께 RenderDocxAsPdf 메소드를 호출하여 C# 코드 한 줄로 DOCX를 PDF로 변환할 수 있습니다.
IronPDF는 DOCX를 PDF로 변환하기에 어떤 플랫폼을 지원합니까?
IronPDF는 Windows, Linux 및 macOS를 포함한 여러 플랫폼에서 DOCX를 PDF로 변환할 수 있어 다양한 개발 환경에 유연하게 사용됩니다.
.NET 응용 프로그램에 IronPDF를 어떻게 통합할 수 있습니까?
개발자는 IronPDF 라이브러리를 NuGet 패키지를 통해 설치하여 그들의 .NET 응용 프로그램에 IronPDF를 통합할 수 있으며, 추가 기능인 메일 머지와 함께 DOCX를 PDF로 부드럽게 변환할 수 있습니다.
IronPDF는 변환된 PDF 문서의 보안을 어떻게 강화합니까?
IronPDF는 개발자가 PDF 문서 변환 후에 비밀번호를 추가하거나 특정 권한을 설정하는 기능을 구현할 수 있도록 하여 보안을 강화합니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.