Java에서 PDF를 EPUB, 텍스트, XPS 등으로 변환
Contents
[
Hide
]
Aspose.PDF for Java는 PDF 문서를 텍스트, 전자책, 인쇄 및 마크업 지향 출력 형식으로 내보낼 수 있습니다.
PDF를 EPUB로 변환
PDF 문서를 EPUB 전자책 형식으로 내보내야 하는 경우 이 예를 사용하세요.
Document인스턴스에서 소스 PDF를 여세요.EpubSaveOptions를 생성하고 인식 모드를Flow로 설정하세요.- PDF 콘텐츠를 리플로우 가능한 EPUB 마크업으로 내보내려면
document.save(outputFile.toString(), saveOptions)를 호출하세요. - 변환된 EPUB 파일을 저장하세요.
public static void convertPdfToEpub(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
EpubSaveOptions saveOptions = new EpubSaveOptions();
saveOptions.setContentRecognitionMode(EpubSaveOptions.RecognitionMode.Flow);
document.save(outputFile.toString(), saveOptions);
}
System.out.println(inputFile + " converted into " + outputFile);
}
PDF를 TeX로 변환
PDF 내용을 TeX 마크업으로 내보내야 하는 경우 이 예를 사용하세요.
Document인스턴스에서 소스 PDF를 여세요.- TeX 직렬화를 위해
TeXSaveOptions를 만드세요. document.save(outputFile.toString(), saveOptions)를 호출하세요. PDF 콘텐츠가 TeX 마크업으로 내보내집니다.- 결과 TeX 파일을 저장하세요.
public static void convertPdfToTex(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
document.save(outputFile.toString(), new TeXSaveOptions());
}
System.out.println(inputFile + " converted into " + outputFile);
}
PDF를 일반 텍스트로 변환
PDF 문서를 텍스트 파일로 내보내야 하는 경우 이 예를 사용하세요.
Document인스턴스에서 소스 PDF를 여세요.- PDF 페이지에서 텍스트 콘텐츠를 추출하려면
TextDevice를 만드세요. - 첫 번째 페이지를 일반 텍스트로 작성하려면
device.process(document.getPages().get_Item(1), outputFile.toString())를 호출하세요. - 텍스트 출력 파일을 저장하세요.
public static void convertPdfToTxt(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
TextDevice device = new TextDevice();
device.process(document.getPages().get_Item(1), outputFile.toString());
}
System.out.println(inputFile + " converted into " + outputFile);
}
PDF를 XPS로 변환
PDF 문서를 XPS 형식으로 변환해야 하는 경우 이 예를 사용하세요.
Document인스턴스에서 소스 PDF를 여세요.XpsSaveOptions를 만들고 내장된 트루타입 글꼴을 활성화하세요.document.save(outputFile.toString(), saveOptions)를 호출하세요. PDF가 포함된 글꼴 리소스가 있는 XPS로 직렬화됩니다.- 변환된 XPS 파일을 저장하세요.
public static void convertPdfToXps(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
XpsSaveOptions saveOptions = new XpsSaveOptions();
saveOptions.setUseEmbeddedTrueTypeFonts(true);
document.save(outputFile.toString(), saveOptions);
}
System.out.println(inputFile + " converted into " + outputFile);
}
PDF를 마크다운으로 변환
PDF 콘텐츠를 Markdown으로 내보내야 하는 경우 이 예를 사용하세요.
Document인스턴스에서 소스 PDF를 여세요.MarkdownSaveOptions를 만들고 이미지 리소스 디렉터리와 HTML 이미지 태그 출력을 구성하세요.document.save(outputFile.toString(), saveOptions)를 호출하세요. PDF 콘텐츠가 외부 이미지 리소스와 함께 Markdown으로 내보내집니다.- 생성된 Markdown 파일을 저장하세요.
public static void convertPdfToMd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
saveOptions.setResourcesDirectoryName("images");
saveOptions.setUseImageHtmlTag(true);
document.save(outputFile.toString(), saveOptions);
}
System.out.println(inputFile + " converted into " + outputFile);
}
PDF를 Mobi XML로 변환
PDF 콘텐츠를 Mobi 호환 XML로 내보내야 하는 경우 이 예를 사용하세요.
Document인스턴스에서 소스 PDF를 여세요.- 대상 직렬화 형식으로
SaveFormatMobiXml을 선택하세요. document.save(outputFile.toString(), SaveFormat.MobiXml)를 호출하세요. PDF가 Mobi 호환 XML로 내보내집니다.- 변환된 파일을 저장하세요.
public static void convertPdfToMobiXml(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
document.save(outputFile.toString(), SaveFormat.MobiXml);
}
System.out.println(inputFile + " converted into " + outputFile);
}