簡體   English   中英

ASP.net中的Javascript畫布

[英]Javascript Canvas in ASP.net

我正在嘗試在Visual Studio應用程序的畫布上繪制圖像,然后在單擊按鈕后將該圖像顯示在PDF文件上。 我正在使用javascript和C#。 到目前為止,我創建了一個名為“ A”的網頁,並在.aspx頁面中創建了一個畫布和按鈕,但是我不確定如何在.aspx.cs頁面中獲得此圖像(在其中顯示“ Image Here ”)。 ),以便可以將其寫入PDF文件。 我很確定我的代碼當前將我的畫布圖像放在base 64中。我們將不勝感激。 謝謝!

//A.aspx:
//Create canvas and save as base 64
<head>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#saveButton').click(saveDrawing);
        });
    </script>  
</head>
<canvas id ="canvas1" class="pad" width="198" height="55"></canvas>
  <input type="button" name="saveButton" id="saveButton" value="Save Drawing">
  <script type="text/javascript">
      function saveDrawing() {
          var canvas = document.getElementById("canvas1");
          var context = canvas.getContext("2d");
          var imgData = canvas.toDataURL();
          //window.open(imgData);  //Not sure if I need this or not
      }      

//A.aspx.cs: Code Behind
public void Method(string A)
{
    PdfStamper pdfStamper = new PdfStamper(
        pdfReader, 
        new FileStream(newFile, FileMode.Create)
    );
    AcroFields pdfForm = pdfStamper.AcroFields;
    //This is where I need to get the image from A.aspx
    pdfForm.SetField("Picture is", (**Image Here**)); 
}

我做了一個jsFiddle ,其中包含您需要做的基本工作。 由於您使用的是Asp.Net,因此您的整個頁面都采用表格形式。 當您單擊提交按鈕時,它應該將畫布中的數據發布到隱藏字段中,並且您可以在頁面加載中從imageData中獲取數據。

我不確定在嘗試將數據保存到PDF之前是否必須進行數據轉換,但這應該為您提供一個良好的開端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM