3D 모델을 보편적으로 볼 수 있는 문서로 변환하는 것은 엔지니어링 및 시각화 도구에서 자주 요구되는 작업입니다. Conholdate.Total for Java은 Java에서 STL을 PDF로 변환하는 강력한 SDK를 제공하여 간단하게 수행할 수 있게 합니다. 이 튜토리얼에서는 라이브러리를 설정하고, 전체 코드 예제를 살펴보며, PDF 옵션을 조정하고, 신뢰할 수 있는 결과를 위한 모범 사례를 배웁니다.
Java에서 STL을 PDF로 변환하는 단계
- STL 입력 파일 확인: 원본 STL 파일이 존재하고 읽을 수 있는지 확인합니다.
String inputPath = "sample.stl";
if (!Files.isReadable(Paths.get(inputPath))) {
System.err.println("Input STL file not found or not readable: " + inputPath);
return;
}
- 컨버터 초기화: STL 파일 경로를 사용하여
Converter인스턴스를 생성합니다.
try (Converter converter = new Converter(inputPath)) {
// conversion logic follows
}
- (선택 사항) STL 로드 옵션 적용: 사용자 지정 로드 동작이 필요하면 로드 옵션 라인의 주석을 해제하십시오.
// LoadOptions loadOptions = new StlLoadOptions();
// converter.setLoadOptions(loadOptions);
- PDF 변환 옵션 구성: 페이지 크기, 방향, 품질 및 기타 PDF 설정을 지정합니다.
PdfConvertOptions pdfOptions = new PdfConvertOptions();
pdfOptions.setPageSize(PdfPageSize.A4);
pdfOptions.setPageOrientation(PdfPageOrientation.PORTRAIT);
pdfOptions.setQuality(100);
pdfOptions.setEmbedFonts(true);
pdfOptions.setOptimizeForPrint(true);
pdfOptions.setCompressImages(true);
- 변환 실행 및 검증:
convert를 호출한 다음 생성된 PDF가 비어 있지 않은지 확인합니다.
converter.convert("sample.pdf", pdfOptions);
File pdfFile = new File("sample.pdf");
if (pdfFile.exists() && pdfFile.length() > 0) {
System.out.println("Generated PDF is valid. Size: " + pdfFile.length() + " bytes.");
}
STL to PDF Java - 전체 코드 예제
다음 예제는 Conholdate.Total for Java를 사용한 STL을 PDF로 변환하는 전체 워크플로를 보여줍니다.
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.enums.PdfPageOrientation;
import com.groupdocs.conversion.enums.PdfPageSize;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.LoadOptions;
import com.groupdocs.conversion.options.load.StlLoadOptions;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class StlToPdfDemo {
public static void main(String[] args) {
// Input STL file and desired PDF output file
String inputPath = "sample.stl";
String outputPath = "sample.pdf";
// Verify that the input file exists and is readable
if (!Files.isReadable(Paths.get(inputPath))) {
System.err.println("Input STL file not found or not readable: " + inputPath);
return;
}
// Perform conversion inside a try‑with‑resources block to guarantee cleanup
try (Converter converter = new Converter(inputPath)) {
// If STL‑specific loading options are required, uncomment the following lines:
// LoadOptions loadOptions = new StlLoadOptions();
// converter.setLoadOptions(loadOptions);
// Configure PDF conversion options
PdfConvertOptions pdfOptions = new PdfConvertOptions();
pdfOptions.setPageSize(PdfPageSize.A4);
pdfOptions.setPageOrientation(PdfPageOrientation.PORTRAIT);
pdfOptions.setQuality(100); // Highest visual quality
pdfOptions.setEmbedFonts(true); // Ensure fonts are embedded
pdfOptions.setOptimizeForPrint(true); // Optimize PDF for printing
pdfOptions.setCompressImages(true); // Reduce PDF size without quality loss
// Execute the conversion
converter.convert(outputPath, pdfOptions);
System.out.println("STL to PDF conversion completed successfully: " + outputPath);
} catch (Exception ex) {
System.err.println("An error occurred during conversion:");
ex.printStackTrace();
return;
}
// Simple validation of the generated PDF
File pdfFile = new File(outputPath);
if (pdfFile.exists() && pdfFile.length() > 0) {
System.out.println("Generated PDF is valid. Size: " + pdfFile.length() + " bytes.");
} else {
System.err.println("PDF generation failed or resulted an empty file.");
}
}
}
Note: 이 코드 예제는 핵심 기능을 보여줍니다. 프로젝트에서 사용하기 전에 파일 경로와 구성 값을 실제 환경에 맞게 업데이트하고, 모든 필수 종속성이 올바르게 설치되었는지 확인하며, 개발 환경에서 충분히 테스트하십시오. 문제가 발생하면 공식 문서를 참조하거나 지원 팀에 문의하십시오.
사전 요구 사항 및 설정
Conholdate Maven 저장소와 SDK 종속성을 pom.xml에 추가하십시오:
<repositories>
<repository>
<id>conholdate-repo</id>
<name>Conholdate Maven Repository</name>
<url>https://repository.conholdate.com/repo/</url>
</repository>
</repositories>
<dependency>
<groupId>com.conholdate</groupId>
<artifactId>conholdate-total</artifactId>
<version>24.9</version>
<type>pom</type>
</dependency>
최신 SDK 패키지를 다운로드 페이지에서 다운로드하십시오. 이 라이브러리는 Java 8 이상이 필요합니다.
PDF 출력 옵션 구성
Conholdate.Total for Java은 조정할 수 있는 여러 PDF 설정을 제공합니다:
- 페이지 크기 -
PdfPageSize.A4또는PdfPageSize.LETTER와 같은 표준 크기 중에서 선택합니다. - 페이지 방향 -
PdfPageOrientation.PORTRAIT또는PdfPageOrientation.LANDSCAPE로 설정합니다. - 품질 -
setQuality(int)메서드는 0부터 100까지의 값을 허용하며, 100은 가장 높은 시각적 정확도를 제공합니다. - 폰트 포함 -
setEmbedFonts(true)를 활성화하면 모든 폰트가 출력 PDF에 보존됩니다. - 인쇄용 최적화 -
setOptimizeForPrint(true)는 인쇄 워크플로에 맞게 PDF를 조정합니다. - 이미지 압축 -
setCompressImages(true)는 눈에 띄는 품질 손실 없이 파일 크기를 줄입니다.
위 코드 스니펫에서 이러한 옵션을 시연했으며, 특정 프로젝트 요구 사항을 충족하도록 결합할 수 있습니다.
결론
Conholdate.Total for Java은 Java에서 STL을 PDF로 변환하는 작업을 간단하면서도 강력하게 만들어 줍니다. 단계별로 따라가고 제공된 코드 예제를 사용하며 PDF 옵션을 조정하면 데스크톱 또는 서버 애플리케이션용 3D STL 모델에서 고품질 PDF를 생성할 수 있습니다. 프로덕션 사용을 위해 적절한 라이선스를 획득하는 것을 기억하세요; 가격 페이지에서 가격을 확인하거나 임시 라이선스 페이지에서 임시 라이선스를 얻을 수 있습니다. 이 SDK가 있으면 Java 프로젝트에 3D 모델 변환을 통합하는 것이 매우 쉽습니다.
FAQ
Java와 Conholdate.Total을 사용하여 STL을 PDF로 변환하려면 어떻게 해야 하나요?
전체 코드 예제에 표시된 대로Converter클래스를 사용하고,PdfConvertOptions를 구성한 뒤convert()를 호출하십시오. SDK가 3D 모델을 PDF로 렌더링하는 복잡한 작업을 처리합니다.STL에서 PDF 변환 중 지원되는 PDF 페이지 형식은 무엇입니까?
SDK는PdfPageSize에 정의된 모든 표준 PDF 페이지 크기와PdfPageOrientation을 통해 세로 및 가로 방향을 모두 지원합니다.생성된 PDF에 사용자 정의 글꼴을 포함시킬 수 있나요?
예.pdfOptions.setEmbedFonts(true)를 설정하면 STL 렌더링에 사용된 모든 글꼴을 포함시켜 PDF가 어떤 뷰어에서도 동일하게 표시됩니다.라이선스 및 지원에 대한 자세한 정보를 어디서 찾을 수 있나요?
라이선스 세부 정보는 가격 페이지에서 확인할 수 있으며, 임시 라이선스는 임시 라이선스 페이지에서 요청할 수 있습니다. 기술 지원이 필요하면 지원 포럼을 방문하세요.
