2016-05-05 5 views
4

私はpdfへのHTML変換の状況になりました。ありがたいことに、フライングソーサーAPIを使ってこれを達成することができます。しかし、私のHTMLはsvgタグで構成されています。私はpdf形式でsvgを取得できません。 google私はそれが以下のリンクStackoverflow questionTutorialを使用して達成することができることがわかった後。 私はreplacedElementFactoryフライングソーサーを使ったpdfのSvg統合

ChainingReplacedElementFactory chainingReplacedElementFactory 
     = new ChainingReplacedElementFactory(); 
chainingReplacedElementFactory.addReplacedElementFactory(replacedElementFactory); 
chainingReplacedElementFactory.addReplacedElementFactory(new SVGReplacedElementFactory()); 
renderer.getSharedContext().setReplacedElementFactory(chainingReplacedElementFactory); 

による平均何であるか全くそれはチュートリアルでちょうどエラーです。この

答えて

2

の外に取り除くのに役立ちませんしてくださいん、replacedElementFactoryとラインは必要ありません。

ここに私の実例があります。

のJava:

import java.io.ByteArrayOutputStream; 
import java.io.FileOutputStream; 
import java.io.OutputStream; 

import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 

import org.w3c.dom.Document; 
import org.xhtmlrenderer.pdf.ITextRenderer; 

public class PdfSvg { 
    public static void main(String[] args) throws Exception { 
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     factory.setNamespaceAware(true); 
     DocumentBuilder builder = factory.newDocumentBuilder(); 
     Document inputDoc = builder.parse("svg.html"); 

     ByteArrayOutputStream output = new ByteArrayOutputStream(); 

     ITextRenderer renderer = new ITextRenderer(); 

     ChainingReplacedElementFactory chainingReplacedElementFactory = new ChainingReplacedElementFactory(); 
     chainingReplacedElementFactory.addReplacedElementFactory(new SVGReplacedElementFactory()); 
     renderer.getSharedContext().setReplacedElementFactory(chainingReplacedElementFactory); 

     renderer.setDocument(inputDoc, "");; 
     renderer.layout(); 
     renderer.createPDF(output); 

     OutputStream fos = new FileOutputStream("svg.pdf"); 
     output.writeTo(fos); 
    } 
} 

HTML:

<html> 
<head> 
<style type="text/css"> 
    svg {display: block;width:100mm;height:100mm} 
</style> 
</head> 
<body> 
    <div> 
     <svg xmlns="http://www.w3.org/2000/svg"> 
      <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" 
       fill="red" /> 
     </svg> 
    </div> 
</body> 
</html> 

ChainingReplacedElementFactorySVGReplacedElementSVGReplacedElementFactorytutorialから来ています。

+0

すばやい返信ありがとう...上記のhtml .. svgタグでうまく動作しますが、ハイチャートAPIによって生成されたsvgがあります。サンプル入力はこちら.... http://jsfiddle.net/gh/ハイチャートのJSコードからSVG(または画像)を生成することです。次のようにしてください://jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/line-basic/ –

+0

サーバー。残念ながら、私はそのための解決策はありませんが、ハイチャートのウェブサイトのこのページはあなたを助けるかもしれません:http://www.highcharts.com/news/52-serverside-generated-charts。 – obourgain

1

ページソリューションの場合は、リモート書式設定サービスである@cloudformatterを使用してください。私はあなたのハイブチャートといくつかのテキストと一緒にあなたのフィドルに彼らのJavascriptを追加しました。

http://jsfiddle.net/yk0Lxzg0/1/

var click="return xepOnline.Formatter.Format('printme', {render:'download'})"; 
jQuery('#buttons').append('<button onclick="'+ click +'">PDF</button>'); 

フィドルに配置された上記のコードは、ダウンロード用のPDFに 'ID' プリントミーでdiv要素をフォーマットします。そのdivにはあなたのチャートとテキストが含まれています。

http://www.cloudformatter.com/CSS2Pdf.APIDoc.Usageは、使用方法を示しています。SVG形式のチャートのサンプルは、それ自体で、またはテキスト、表などと組み合わされたPDFの形式で提供されています。

0

@Rajesh私はすでにあなたの問題の解決策を見つけたことを願っています。そうでない場合(または飛行皿、バティック、svgタグで問題を抱えている人)は、 をすべて削除してclip-path="url(#highcharts-xxxxxxx-xx)"<g>タグから削除してください。

関連する問題