2017-12-19 6 views
0

xsltを使用してdocxファイルの/ doc.xmlファイルに置き換わるxmlに書き出します。docxファイルの破損画像

一度生成されると、docxファイルが作成されますが、オープンすると「ファイルが壊れていて開くことができません」というエラーが表示されます。 [OK]をクリックして「読み取り不可能なコンテンツ」エラーが表示され、適切なすべてのデータがドキュメントに表示されます。

完成したdocxをバリデーター(http://ucd.eeonline.org/validator/index.php)で実行したところ、 「すべてのイメージに代替テキストが定義されている必要があります。

イメージがドキュメントに入っていて、生成されたXMLにaltタグを使用しています。それは、画像に関連するとして、ここでは

は私のXSLTファイルからコードです:私の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"/> 

<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です。

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

はい、あります。ヌル値を ""に置き換えるスクリプトを設定しました – Michael

関連する問題