두 가지 간단한 단계를 사용하여 CGM을 FLATOPC으로 변환할 수 있습니다. 먼저 Aspose.PDF for Java 를 사용하여 CGM 파일을 DOC로 렌더링해야 합니다. 그런 다음 강력한 문서 처리 API Aspose.Words for Java 를 사용하여 DOC를 FLATOPC으로 변환할 수 있습니다. 두 API 모두 Java용 Aspose.Total 패키지에 있습니다.
CGM을 FLATOPC으로 변환하는 Java API
변환 요구 사항
Maven 기반 프로젝트에서 직접 Java용 Aspose.Total을 쉽게 사용할 수 있습니다. Java용 Aspose.PDF 및 Aspose.Words for Java pom.xml에 있습니다.
또는 다운로드 에서 ZIP 파일을 받을 수 있습니다.
Document document = new Document("template.cgm"); | |
document.save("DocOutput.doc", SaveFormat.DOC); | |
Document outputDocument = new com.aspose.words.Document("DocOutput.doc"); | |
//save into related format | |
outputDocument.save("output.docm", SaveFormat.DOCM); |
변환 요구 사항
CGM을 FLATOPC으로 변환하는 동안 문서가 암호로 보호되어 있더라도 PDF 조작 API Java용 Aspose.PDF 를 사용하여 문서를 열 수 있습니다. 암호화된 파일을 열기 위해서는 문서 객체를 생성하고 소유자의 비밀번호로 CGM을 열어야 합니다.
Document document = new Document("input.cgm", "password"); | |
document.save("Output.doc", SaveFormat.DOC); |
Java를 통해 암호로 보호된 CGM 문서 열기
입력 문서를 FLATOPC 파일 형식으로 저장하는 동안 문서를 파일 시스템 대신 데이터베이스에 저장할 수도 있습니다. 데이터베이스에서 Document 객체를 저장하고 검색하는 것을 구현해야 할 수도 있습니다. 이는 모든 유형의 콘텐츠 관리 시스템을 구현하는 경우에 필요합니다. FLATOPC을 데이터베이스에 저장하려면 바이트 배열을 얻기 위해 문서를 직렬화해야 하는 경우가 많습니다. 이는 Aspose.Words for Java API를 사용하여 수행할 수 있습니다. 바이트 배열을 가져온 후 SQL 문을 사용하여 데이터베이스에 저장할 수 있습니다.
public static void StoreToDatabase(Document doc, Connection mConnection) throws Exception { | |
// create an output stream which uses byte array to save data | |
ByteArrayOutputStream aout = new ByteArrayOutputStream(); | |
// save the document to byte array | |
doc.save(aout, SaveFormat.DOCM); | |
// get the byte array from output steam | |
// the byte array now contains the document | |
byte[] buffer = aout.toByteArray(); | |
// get the filename from the document. | |
String fileName = doc.getOriginalFileName(); | |
String filePath = fileName.replace("\\", "\\\\"); | |
// create the SQL command. | |
String commandString = "INSERT INTO Documents (FileName, FileContent) VALUES('" + filePath + "', '" + buffer + "')"; | |
Statement statement = mConnection.createStatement(); | |
statement.executeUpdate(commandString); | |
} |