Java에서 GroupDocs Conversion Java를 사용하여 txt를 PDF로 변환
일반 텍스트 파일을 PDF로 변환하면서 모든 들여쓰기, 앞 공백 및 목록 번호를 그대로 유지하는 것은 까다로울 수 있습니다. 이 가이드에서는 groupdocs conversion java를 사용한 txt to pdf java 변환 방법을 배우고, 자동으로 서식을 보존하는 방법을 알아보며, 프로젝트에 바로 적용할 수 있는 실용적인 예제를 확인합니다.
빠른 답변
- txt to pdf java 변환을 처리하는 라이브러리는 무엇인가요? GroupDocs.Conversion Java.
- 들여쓰기를 유지할 수 있나요? 예 –
TxtLeadingSpacesOptions.ConvertToIndent를 설정합니다. - 번호 매기기 감지가 지원되나요?
setDetectNumberingWithWhitespaces(true)를 활성화합니다. - 라이선스가 필요합니까? 무료 체험으로 테스트가 가능하지만, 프로덕션에서는 정식 라이선스가 필요합니다.
- 필요한 Java 버전은 무엇인가요? JDK 11 이상.
txt to pdf java란?
txt to pdf java는 일반 텍스트(.txt) 문서를 Java 코드를 사용해 PDF 파일로 변환하는 과정입니다. GroupDocs.Conversion Java는 저수준 PDF 생성 세부 사항을 추상화하고 레이아웃, 들여쓰기 및 번호 매기기를 보존하기 위한 고수준 옵션을 제공합니다.
txt to pdf java에 GroupDocs Conversion Java를 사용하는 이유
GroupDocs Conversion Java는 일반적인 8코어 서버에서 초당 500페이지까지 처리하고, 50개 이상의 입력 및 출력 포맷을 지원하며, 수동 후처리 없이 복잡한 텍스트 서식을 유지할 수 있게 해줍니다. 이는 정확한 시각적 일관성이 중요한 법률 계약, 기술 매뉴얼 또는 코드 스니펫의 배치 처리에 이상적입니다.
사전 요구 사항
- GroupDocs.Conversion for Java 버전 25.2 이상.
- JDK 11 이상이 개발 머신에 설치되어 있어야 합니다.
- Maven 호환 IDE, 예: IntelliJ IDEA 또는 Eclipse.
- Java 프로젝트 구조와 Maven 의존성에 대한 기본적인 이해.
GroupDocs.Conversion for Java 설정
Maven 구성
Add the GroupDocs repository and dependency to your pom.xml:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/conversion/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-conversion</artifactId>
<version>25.2</version>
</dependency>
</dependencies>
라이선스 획득
GroupDocs.Conversion은 무료 체험, 확장 테스트를 위한 임시 라이선스, 정식 구매 옵션을 제공합니다. 옵션을 확인하려면 구매 페이지 를 방문하세요.
기본 초기화
After the Maven step, you can initialize the conversion engine:
import com.groupdocs.conversion.Converter;
public class InitializeConversion {
public static void main(String[] args) {
// Path to the input TXT document.
String inputFile = "SampleText.txt";
// Create a converter instance using the text file.
Converter converter = new Converter(inputFile);
System.out.println("Initialization complete!");
}
}
구현 가이드
각 기능을 단계별로 살펴보며, 코드가 나타나기 전에 각 옵션의 목적을 설명합니다.
기능 1: 고급 옵션으로 txt를 PDF로 변환
이 기능은 앞 공백 및 번호 매기기 감지와 같은 서식 동작을 제어하면서 텍스트 파일을 PDF로 변환하는 방법을 보여줍니다.
TXT 변환을 위한 로드 옵션 설정
TxtLoadOptions defines how the source text is interpreted before conversion.
The TxtLoadOptions class lets you specify whitespace handling, line‑break behavior, and numbering detection.
import com.groupdocs.conversion.options.load.TxtLoadOptions;
import com.groupdocs.conversion.options.load.TxtLeadingSpacesOptions;
// Create TxtLoadOptions instance.
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setLeadingSpacesOptions(TxtLeadingSpacesOptions.ConvertToIndent); // Convert leading spaces to indents.
loadOptions.setDetectNumberingWithWhitespaces(true); // Detect numbering with whitespaces.
변환기 초기화
The Converter class is the core engine that accepts a source document and a set of load options, then produces the desired output format.
import com.groupdocs.conversion.Converter;
// Create converter instance with specific options.
Converter converter = new Converter(inputFile, () -> loadOptions);
PDF 변환 옵션 구성
PdfConvertOptions controls PDF‑specific settings like page size, compression level, and font embedding.
The PdfConvertOptions class ensures the generated PDF matches your quality and size requirements.
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
// Prepare PDF conversion options.
PdfConvertOptions convertOptions = new PdfConvertOptions();
변환 수행
Calling convert on the Converter instance writes the PDF to the target path you specify.
// Convert TXT to PDF with advanced settings applied.
converter.convert(outputFile, convertOptions);
System.out.println("Conversion complete. Check YOUR_OUTPUT_DIRECTORY for the result.");
기능 2: 고급 텍스트 처리를 위한 로드 옵션 설정
이 기능은 정밀한 서식 제어가 필요한 텍스트 파일에 대한 로드 옵션을 미세 조정하는 방법을 보여줍니다.
TxtLoadOptions 구성
TxtLeadingSpacesOptions determines how leading spaces are treated during conversion.
Setting TxtLeadingSpacesOptions.ConvertToIndent tells the engine to transform leading spaces into visual indents in the PDF.
TxtLoadOptions txtLoadOptions = new TxtLoadOptions();
txtLoadOptions.setLeadingSpacesOptions(TxtLeadingSpacesOptions.ConvertToIndent);
txtLoadOptions.setDetectNumberingWithWhitespaces(true);
// These options ensure that the PDF conversion respects the original formatting nuances.
실용적인 적용 사례
- 법률 문서 – 조항 번호와 들여쓰기를 정확히 유지합니다.
- 기술 매뉴얼 – 다중 레벨 목록과 코드 블록을 수동 재포맷 없이 보존합니다.
- 소스 코드 문서화 – 원본 들여쓰기를 유지하여 검토자가 PDF를 읽기 쉽게 합니다.
이러한 시나리오는 groupdocs conversion java를 콘텐츠 관리 파이프라인, 자동 보고서 생성기 또는 문서 보관 서비스에 어떻게 삽입할 수 있는지를 보여줍니다.
성능 고려 사항
- 메모리 사용량: 200 MB보다 큰 파일의 경우,
OutOfMemoryError를 방지하기 위해 JVM 힙(-Xmx2g이상)을 늘립니다. - 배치 처리: 초기화 오버헤드를 줄이기 위해 여러 파일에 걸쳐 단일
Converter인스턴스를 재사용합니다. - 버전 업데이트: 최신 GroupDocs.Conversion 릴리스로 업그레이드하면 일반적으로 10‑15 % 속도 향상과 추가 포맷 지원을 얻을 수 있습니다.
일반적인 문제 및 해결책
| 문제 | 발생 원인 | 빠른 해결책 |
|---|---|---|
| 들여쓰기 손실 | TxtLeadingSpacesOptions가 설정되지 않음 | setLeadingSpacesOptions(TxtLeadingSpacesOptions.ConvertToIndent) 호출 |
| 번호 매기기 목록이 일반 텍스트로 표시 | setDetectNumberingWithWhitespaces가 false | true로 활성화 |
| 출력 PDF가 빈 페이지 | outputFile 경로가 잘못되었거나 쓰기 권한이 없음 | 경로를 확인하고 쓰기 권한을 확보 |
대용량 파일이 OutOfMemoryError 발생 | 기본 JVM 힙이 너무 작음 | 힙 크기 증가 (-Xmx2g 이상) |
자주 묻는 질문
Q: 한 번에 여러 TXT 파일을 변환할 수 있나요?
A: 예, GroupDocs.Conversion은 배치 처리를 지원하므로 텍스트 파일 컬렉션을 단일 루프에서 변환할 수 있습니다.
Q: 변환된 PDF가 예상과 다르게 보이면 어떻게 해야 하나요?
A: 앞 공백 및 번호 매기기 감지에 대한 로드 옵션을 다시 확인하십시오; 이러한 설정을 조정하면 대부분의 서식 차이를 해결할 수 있습니다.
Q: 변환할 수 있는 TXT 파일 크기에 제한이 있나요?
A: GroupDocs.Conversion은 매우 큰 파일도 처리할 수 있지만, 성능은 사용 가능한 메모리에 따라 달라집니다. 500 MB를 초과하는 파일은 분할하거나 JVM 힙을 늘리는 것을 고려하십시오.
리소스
- 문서: GroupDocs Conversion Java 문서
- API 참조: GroupDocs Conversion Java API 참조
- 다운로드: GroupDocs.Conversion for Java 다운로드
- 구매 및 라이선스: 라이선스 구매 또는 무료 체험
- 지원 포럼: GroupDocs 지원 포럼
이러한 리소스를 탐색하여 이해도를 높이고 프로젝트에서 groupdocs conversion java를 최대한 활용하십시오. 코딩 즐겁게!
마지막 업데이트: 2026-08-19
테스트 환경: GroupDocs.Conversion 25.2 for Java
작성자: GroupDocs