2017-12-19 6 views
0

docx 파일의/document.xml 파일을 xml로 바꾸기 위해 xslt를 사용하고 있습니다.이미지가있는 docx 파일 손상

일단 생성되면 docx 파일이 생성되지만 열면 "파일이 손상되어 열리지 않음"오류가 발생합니다. 확인을 클릭하고 "읽을 수없는 콘텐츠"오류가 발생하고 문서가 모든 적절한 데이터로 열립니다.

유효성 검사기 (http://ucd.eeonline.org/validator/index.php)를 통해 완료된 docx를 실행했으며 "모든 이미지에 대체 텍스트가 있어야합니다."라는 메시지가 표시됩니다.

내 이미지가 문서로 들어오고 생성 된 XML에 alt 태그를 사용하고 있습니다. 여기

는 이미지에 관한 나의 XSLT 파일의 코드입니다 :

<w:bookmarkStart w:id="0" w:name="_GoBack"/> 
      <w:r> 
      <w:rPr> 
       <w:rFonts w:ascii="Calibri" w:cs="Segoe UI" w:hAnsi="Calibri"/> 
       <w:noProof/> 
      </w:rPr> 
      <w:drawing> 
       <wp:inline distB="0" distL="0" distR="0" distT="0"> 
       <wp:extent cx="3093810" cy="2320356"/> 
       <wp:effectExtent b="3810" l="0" r="0" t="0"/> 
       <wp:docPr id="1" name="Picture 1"/> 
       <wp:cNvGraphicFramePr> 
        <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/> 
       </wp:cNvGraphicFramePr> 
       <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> 
        <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
        <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
         <pic:nvPicPr> 
         <pic:cNvPr id="1" name="Tulips.jpg"/> 
         <pic:cNvPicPr/> 
         </pic:nvPicPr> 
         <pic:blipFill> 
         <a:blip cstate="print" r:embed="rId5"> 
          <a:extLst> 
          <a:ext uri=""> 
           <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/> 
          </a:ext> 
          </a:extLst> 
         </a:blip> 
         <a:stretch> 
          <a:fillRect/> 
         </a:stretch> 
         </pic:blipFill> 
         <pic:spPr> 
         <a:xfrm> 
          <a:off x="0" y="0"/> 
          <a:ext cx="3105628" cy="2329220"/> 
         </a:xfrm> 
         <a:prstGeom prst="rect"> 
          <a:avLst/> 
         </a:prstGeom> 
         </pic:spPr> 
        </pic:pic> 
        </a:graphicData> 
       </a:graphic> 
       </wp:inline> 
      </w:drawing> 
      </w:r> 
      <w:bookmarkEnd w:id="0"/> 

이것은 생성 된 단어/document.xml :

<w:bookmarkStart w:id="0" w:name="_GoBack"/> 
     <w:r> 
      <w:rPr> 
      <w:rFonts w:ascii="Calibri" w:cs="Segoe UI" w:hAnsi="Calibri"/> 
      <w:noProof/> 
      </w:rPr> 
      <w:drawing> 
      <wp:inline distB="0" distL="0" distR="0" distT="0"> 
       <wp:extent cx="3093810" cy="2320356"/> 
       <wp:effectExtent b="3810" l="0" r="0" t="0"/> 
       <wp:docPr id="1" name="Picture 1"/> 
       <wp:cNvGraphicFramePr> 
       <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/> 
       </wp:cNvGraphicFramePr> 
       <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> 
       <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
        <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
        <pic:nvPicPr> 
         <pic:cNvPr id="0" name="11786.jpeg"/> 
         <pic:cNvPicPr/> 
        </pic:nvPicPr> 
        <pic:blipFill> 
         <a:blip cstate="print" r:embed="rId5"> 
         <a:extLst> 
          <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}"> 
          <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/> 
          </a:ext> 
         </a:extLst> 
         </a:blip> 
         <a:stretch> 
         <a:fillRect/> 
         </a:stretch> 
        </pic:blipFill> 
        <pic:spPr> 
         <a:xfrm> 
         <a:off x="0" y="0"/> 
         <a:ext cx="3105628" cy="2329220"/> 
         </a:xfrm> 
         <a:prstGeom prst="rect"> 
         <a:avLst/> 
         </a:prstGeom> 
        </pic:spPr> 
        </pic:pic> 
       </a:graphicData> 
       </a:graphic> 
      </wp:inline> 
      </w:drawing> 
     </w:r> 
     <w:bookmarkEnd w:id="0"/> 

내 XML을 모두 가지고와 속성.

protected function addImages() 
{ 
    // Check which image type(s) are registered in [Content_Types].xml 
    $this->checkDefaultContentTypes(); 
    // Prepare word/_rels/document.xml.rels to add details of the images 
    $this->initRelationships(); 
    // Get the merged text content ready for the image details 
    $doc = new \DOMDocument(); 
    $doc->loadXML($this->mergedContent); 
    $docPr = $doc->getElementsByTagNameNS(self::WP_NS, 'docPr'); 
    $cNvPr = $doc->getElementsByTagNameNS(self::PIC_NS, 'cNvPr'); 
    $blip = $doc->getElementsByTagNameNS(self::A_NS, 'blip'); 
    // Get the image filenames from the XML source 
    $images = $this->getImageFilenames(); 
    $i = 0; 
    $imgNum = 1; 
    // Add the details of each image to the merged content 
    foreach ($images as $image) { 
     $pr = $docPr->item($i); 
     $pr->setAttribute('id', $imgNum); 
     $pr->setAttribute('name', 'Picture ' . $imgNum); 
     $cNvPr->item($i)->setAttribute('id', 0); 
     $cNvPr->item($i)->setAttribute('name', $image); 
     $blip->item($i)->setAttributeNS(self::R_NS, 'r:embed', 'rId' . $this->imageStart); 
     $ext = $blip->item($i)->getElementsByTagNameNS(self::A_NS, 'ext'); 
     $ext->item(0)->setAttribute('uri', '{28A0092B-C50C-407E-A947-70E740481C1C}'); 
     $extension = $this->checkType($image); 
     $this->zip->addFile($this->imageSource . $image, 'word/media/image' . $i . ".$extension"); 
     $this->generateNewRelationship(self::IMAGE_NS, 'media/image' . $i . ".$extension"); 
     $i++; 
     $imgNum++; 
     $this->imageStart++; 
    } 
    // Add the Relationship elements that need to follow the images 
    foreach ($this->relsToAdd as $rel) { 
     $this->generateNewRelationship($rel['Type'], $rel['Target']); 
     $this->imageStart++; 
    } 
    // Save the updated version of document.xml.rels, and add to the download file 
    $relations = $this->docRels->saveXML(); 
    $this->zip->addFromString('word/_rels/document.xml.rels', $relations); 

    // Save the updated version of [Content_Types].xml and add it to the download file 
    $types = $this->types->saveXML(); 
    $this->zip->addFromString('[Content_Types].xml', $types); 

    // Save the updated merged content 
    $this->mergedContent = $doc->saveXML(); 

    // Add the header and footer Relationship IDs to the merged content if necessary 
    if ($this->header) { 
     $this->fixHeadersFooters($relations, 'header'); 
    } 
    if ($this->footer) { 
     $this->fixHeadersFooters($relations, 'footer'); 
    } 
} 

어떤 생각 방법이 문제를 해결하기 위해 다음과 같습니다

는 이미지를 추가하는 기능은?

답변

0

이것은 NULL 값의 결과입니다.

+0

문제가 해결되었다는 의미입니까? –

+1

예. null 값을 ""으로 대체하도록 스크립트를 설정했습니다. – Michael