2014-02-12 2 views
1

안녕하세요 모두, 나는 DOCX 문서 정션 2 다른 DOCX 발생하고있어, 내가 병합을하고 있어요.오류 변환 DOCX

public static void main(String[] args) throws Exception { 
    InputStream in1 = new FileInputStream(new File("C:\\Clientes\\Constremac\\Repositorio_DOCS\\UPLOAD\\LAYOUT_PAGINA_VERSAO_FINAL.docx")); 
    InputStream in2 = new FileInputStream(new File("C:\\Clientes\\Constremac\\Repositorio_DOCS\\UPLOAD\\modeloContratoSocial.docx")); 
    OutputStream out = new FileOutputStream(new File("C:\\Clientes\\Constremac\\Repositorio_DOCS\\UPLOAD\\modeloContratoSocialMerge.docx")); 
    mergeDocx(in1,in2,out); 
} 

public static void mergeDocx(InputStream s1, InputStream s2, OutputStream os) throws Exception { 
    WordprocessingMLPackage target = WordprocessingMLPackage.load(s1); 
    insertDocx(target.getMainDocumentPart(), IOUtils.toByteArray(s2)); 
    SaveToZipFile saver = new SaveToZipFile(target); 
    saver.save(os); 
} 
private static void insertDocx(MainDocumentPart main, byte[] bytes) throws Exception { 
     AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/part" + (chunk++) + ".docx")); 
     afiPart.setContentType(new ContentType(CONTENT_TYPE)); 
     afiPart.setBinaryData(bytes); 
     Relationship altChunkRel = main.addTargetPart(afiPart); 
     //convertAltChunks() 
     CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk(); 
     chunk.setId(altChunkRel.getId()); 

     main.addObject(chunk); 
} 

최종 문서 (docx)는 정상입니다. 정상적으로 열 수 있습니다. 이 생성 된 파일을 PDF로 변환 할 때 문제가 발생하면 다음 오류가 나타납니다. NOT IMPLEMENTED : w : altChunk -에 대한 지원.

public boolean createPDF(String nomeArquivo) { 
    try  { 
     long start = System.currentTimeMillis(); 
     Configuration confg = new Configuration(); 

     System.out.println(Configuration.repositorioUpload + nomeArquivo + ".docx"); 
     InputStream is = new FileInputStream(new File(Configuration.repositorioUpload + nomeArquivo + ".docx")); 
     WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is); 

     PdfSettings pdfSettings = new PdfSettings(); 

     OutputStream out = new FileOutputStream(new File(Configuration.repositorioUpload + nomeArquivo + ".pdf")); 
     PdfConversion converter = new Conversion(wordMLPackage); 
     converter.output(out, pdfSettings); 

     System.err.println("Generate " + Configuration.repositorioUpload + nomeArquivo + ".pdf" + " with " + (
       System.currentTimeMillis() - start) + "ms"); 
    } 
    catch (Throwable e) { 
     e.printStackTrace(); 
    } 
    return false; 
} 

나는 할 사람이 내가 감사 도와 있다면,이 PDF를 생성하기 위해 노력하고있어 잠시 동안, 내가 사용하는 자바 코드를 전송하고 있습니다.

감사합니다.

포옹!


나는 AltChunck를 사용하는 방법을 찾았지만도하지 넘어 제대로 실행 표시되지 않습니다 PDF로 내보낼 때 이미지 바닥 글 및 헤더를 병합합니다.

public static void main(String[] args) throws Exception { 

    boolean ADD_TO_HEADER = true; 
    HeaderPart hp = null; 

    String inputfilepath = "C:\\Clientes\\Constremac\\Repositorio_DOCS\\UPLOAD\\default_template.xml"; 

    String chunkPath = "C:\\Clientes\\Constremac\\Repositorio_DOCS\\UPLOAD\\sample.docx"; 

    boolean save = true; 
    String outputfilepath = "C:\\Clientes\\Constremac\\Repositorio_DOCS\\UPLOAD\\altChunk_out.docx"; 


    // Open a document from the file system 
    // 1. Load the Package 
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); 
    //proce 
    MainDocumentPart main = wordMLPackage.getMainDocumentPart(); 

    if (ADD_TO_HEADER) { 
     hp = wordMLPackage.getDocumentModel().getSections().get(0).getHeaderFooterPolicy().getDefaultHeader(); 
    } 

    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/chunk.docx")); 
    afiPart.setBinaryData(new FileInputStream(chunkPath)); 

    afiPart.setContentType(new ContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml")); //docx 
    //afiPart.setContentType(new ContentType("application/xhtml+xml")); //xhtml 

    Relationship altChunkRel = null; 
    if (ADD_TO_HEADER) { 
     altChunkRel = hp.addTargetPart(afiPart); 
    } else { 
     altChunkRel = main.addTargetPart(afiPart);   
    } 

    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk(); 
    ac.setId(altChunkRel.getId()); 

    if (ADD_TO_HEADER) { 
     hp.getJaxbElement().getEGBlockLevelElts().add(ac); 
    } else { 
     main.addObject(ac); 
    } 

    // Save it 

    if (save) {  
     SaveToZipFile saver = new SaveToZipFile(wordMLPackage); 
     saver.save(outputfilepath); 
     System.out.println("Saved " + outputfilepath); 
    } 
} 

내가 뭘 잘못하고 있니?

답변

2

altChunk는 "실제"docx 콘텐츠가 아닙니다. 이 PDF로 출력 할 수 전에

, 정상 WordML 단락 등 테이블

당신은 (내용이 어떤 관계를 포함하지 않는 경우 충분히 쉽게하는이 스스로 일을 시도 할 수 있습니다 이미지로 교체해야합니다 , 하이퍼 링크 등), 충돌하는 스타일 또는 번호 매기기. http://www.docx4java.org/blog/2010/11/merging-word-documents/ 더 참조하십시오 .. 또는이

altChunk를 해결할 수 있습니다 plutext.com

+0

안녕 JasonPlutext, 답장을 보내 주셔서 감사합니다, 나는 더 의심처럼, 나는이 줄 끝에서이 절차를 수행하고 있습니다 : 계산기.출력 (Oct, pdfSettings); 그리고이 공용 프로세스 WordprocessingMLPackage (WordprocessingMLPackage srcPackage)를 선언 했습니까? 예를 들어 주시겠습니까? 도움 주셔서 감사합니다. 포옹! –

0

내 회사의 웹 사이트입니다하지 "진짜"DOCX 내용. 우리는 원본 콘텐츠 단어 태그에 altchunk을 변환 할 수 있습니다

사용하여 자바,

은 DOCX

Docx4jProperties.setProperty(“docx4j.Convert.Out.HTML.OutputMethodXML”, 
true); 
Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL); 

열기 전체 코드에 대한 링크 내부의 document.xml을 변환합니다.

[원본 콘텐츠에 AltChunk 변환] [1]

https://kishankichi.wordpress.com/2016/05/26/convert-altchunk-to-original-content-or-convert-to-real-docx-format-using-java

https://kishankichi.wordpress.com/2016/05/26/convert-altchunk-to-original-content-or-convert-to-real-docx-format-using-java/

참고 :

는 친절하게 당신의 HTML 내용 & NBSP 및 기타 태그를 무시합니다. & nbsp에 대해서만 확인했습니다. 재생을위한

감사합니다 ...

+0

이 링크가 질문에 대답 할 수 있지만 여기에 답의 핵심 부분을 포함하고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. - [검토 중] (리뷰/저품절 게시물/12477815) –

+0

ok sir. 귀중한 재교육에 감사드립니다. –