Loading ...
Sorry, an error occurred while loading the content.
 

Dynamic load SVG from database

Expand Messages
  • danielhorng0001
    Dear all, I write a simple asp & script for dynamic load SVG from database. following is the asp & script. Everything is work fine. But when I try to load a
    Message 1 of 4 , May 1, 2005
      Dear all,
      I write a simple asp & script for dynamic load SVG from database.
      following is the asp & script.
      Everything is work fine. But when I try to load a lager size SVG
      (ex: 1400px*1600px), then some part of graphic will be cut.
      Did anyone can tell me what's going on?

      Daniel Horng

      ************************************************************
      ************************************************************
      filename: test.asp
      ************************************************************
      ************************************************************
      <%@Language=Vbscript codepage=65001%>
      <%
      Option Explicit
      Response.Buffer=true
      Response.Expires = -1
      Session.Codepage = 65001
      %>
      <html>
      <head>
      <script language='Jscript'>
      var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

      function GetSVG() {
      xmlHttp.open("GET","ws_GenSVGData.asp?Key=1", true);
      xmlHttp.send();
      xmlHttp.onreadystatechange = Function("GetSVGFinish()");
      }

      function GetSVGFinish() {
      if (xmlHttp.readyState != 4) {return;}
      var embSVG = document.embeds["objSVG"];
      var SVGDoc = embSVG.getSVGDocument();
      var objFrag = embSVG.window.parseXML(xmlHttp.responseText,SVGDoc);
      SVGDoc.rootElement.appendChild(objFrag.firstChild);
      }
      </script>
      </head>
      <body>
      <button onclick='jscript:GetSVG();'> Load SVG</button><p>
      <EMBED ID='objSVG' SRC="blank.svg" TYPE="image/svg-xml" WIDTH="100%"
      HEIGHT="100%" LUGINSPAGE="http://www.adobe.com/svg/viewer/install/">
      </body>
      </html>

      ************************************************************
      ************************************************************
      filename:ws_GenSVGData.asp
      ************************************************************
      ************************************************************
      <%@Language=Vbscript codepage=65001%>
      <%
      Option Explicit
      Response.Buffer=true
      Response.Expires = -1
      Session.Codepage = 65001

      dim strConn,cnnDB,strSQL,strKey,rst1

      strConn = "Provider=SQLOLEDB.1;User ID=sa;Password=;Persist Security
      Info=True;Initial Catalog=MyTestDB;Data Source=(local)"

      set cnnDB = Server.CreateObject("ADODB.Connection")
      cnnDB.Open strConn

      strKey = trim(Request("Key"))
      strSQL = "SELECT SVGData FROM MyTable WHERE KeyID = " & strKey
      set rst1 = cnnDB.Execute(strSQL)
      Response.Write rst1("SVG").value
      %>


      ************************************************************
      ************************************************************
      filename: Blank.svg
      ************************************************************
      ************************************************************
      <?xml version="1.0" standalone="no"?>
      <svg xmlns:xlink="http://www.w3.org/1999/xlink"></svg>
      ************************************************************
      ************************************************************
    • Richard Smith
      Does your dynamically loaded SVG include a viewBox attribute in its element? You need to specify the bounding-box of the area to render, otherwise SVG
      Message 2 of 4 , May 1, 2005
        Does your dynamically loaded SVG include a 'viewBox' attribute in its <svg> element? You need to specify the bounding-box of the area to render, otherwise SVG doesn't know how big the image is!

        Example:

        <svg viewBox="0 0 1600 1200">
        ...
        </svg>
      • danielhorng0001
        Dear Richard, Thank you for your remind. The dynamic SVG doesn t specify the viewBox attribute. Because it is generated by the other program and we don t know
        Message 3 of 4 , May 1, 2005
          Dear Richard,
          Thank you for your remind.
          The dynamic SVG doesn't specify the viewBox attribute.
          Because it is generated by the other program and we don't know "How
          big?" of this graphic.
          I resolve this problem by add overflow attribute to <svg> tag.
          Am I right?

          *******************************************************
          *******************************************************
          <svg xmlns:xlink="http://www.w3.org/1999/xlink"
          overflow="visible">
          .......
          </svg>
          *******************************************************
          *******************************************************
        • Richard Smith
          tag. Am I right? That may make the rest of your document appear, but you ll have to pan in the
          Message 4 of 4 , May 2, 2005
            <<I resolve this problem by add overflow attribute to <svg> tag. Am I right?>>

            That may make the rest of your document appear, but you'll have to pan in the viewer to see all of it. However, if you can't easily find out how 'big' the SVG is that's probably the best solution.
          Your message has been successfully submitted and would be delivered to recipients shortly.