2014-10-14 5 views
0

내 HTML (그래프가 표시됨)에 SVG 파일이 있고 PDF로 변환해야하지만 나머지 HTML은 성공적으로 변환되지만 SVG는 그렇지 않습니다. JS 나 다른 프로그램으로 어떻게 할 수 있습니까? 앞서 응답SVG 요소를 PDF로 변환하는 방법

+0

https://github.com/CBiX /svgToPdf.js/tree/master –

답변

0

확인 감사합니다 이 링크 d3js/SVG Export demo

그들이 그것을 달성하는 방법이 적절한 대답하지 않을 수 있지만, 당신이 볼 수

/* 
    Utility function: populates the <FORM> with the SVG data 
    and the requested output format, and submits the form. 
*/ 
function submit_download_form(output_format) 
{ 
    // Get the d3js SVG element 
    var tmp = document.getElementById("ex1"); 
    var svg = tmp.getElementsByTagName("svg")[0]; 
    // Extract the data as SVG text string 
    var svg_xml = (new XMLSerializer).serializeToString(svg); 

    // Submit the <FORM> to the server. 
    // The result will be an attachment file to download. 
    var form = document.getElementById("svgform"); 
    form['output_format'].value = output_format; 
    form['data'].value = svg_xml ; 
    form.submit(); 
} 

/* 
d3js Example code, based on the "Three Little Circles" tutorial: 
http://mbostock.github.com/d3/tutorial/circle.html 
*/ 
function create_d3js_drawing() 
{ 
    var data = [32, 57, 112], 
     dataEnter = data.concat(293), 
     dataExit = data.slice(0, 2), 
     w = 360, 
     h = 180, 
     x = d3.scale.ordinal().domain([57, 32, 112]).rangePoints([0, w], 1), 
     y = d3.scale.ordinal().domain(data).rangePoints([0, h], 2); 

    var svg = d3.select("#ex1").append("svg") 
     .attr("width", w) 
     .attr("height", h); 

    svg.selectAll(".little") 
     .data(data) 
     .enter().append("circle") 
     .attr("class", "little") 
     .attr("cx", x) 
     .attr("cy", y) 
     .attr("r", 12); 

    d3.select("#randomize").on("click", function() { 
     svg.selectAll(".little") 
      .transition() 
      .duration(750) 
      .attr("cx", function() { return Math.random() * w; }) 
      .attr("cy", function() { return Math.random() * h; }) 
      .attr("fill", function() { return '#'+Math.floor(Math.random()*16777215).toString(16); }); 
     /* Random Hex Color in Javascript, from: http://paulirish.com/2009/random-hex-color-code-snippets/ */ 

     // Show the new SVG code 
     show_svg_code(); 
     }); 
} 

function show_svg_code() 
{ 
    // Get the d3js SVG element 
    var tmp = document.getElementById("ex1"); 
    var svg = tmp.getElementsByTagName("svg")[0]; 

    // Extract the data as SVG text string 
    var svg_xml = (new XMLSerializer).serializeToString(svg); 

    //Optional: prettify the XML with proper indentations 
    svg_xml = vkbeautify.xml(svg_xml); 

    // Set the content of the <pre> element with the XML 
    $("#svg_code").text(svg_xml); 

    //Optional: Use Google-Code-Prettifier to add colors. 
    prettyPrint(); 
} 
+0

답변을 주셔서 감사합니다. 사용자가 표시된 항목을 인쇄 할 수있게 해주는 window.print()를 사용하는 방법을 발견했습니다. – user3631872

관련 문제