2013-03-22 30 views
0

我正在尝试使用pdf.js将KineticJS形状添加到现有的 pdf文件中。我遇到的问题是KineticJS创建一个新的画布,不会使用由pdf.js.创建的画布。我已经尝试在KineticJS中引用pdf.js画布,但这不起作用。任何关于如何整合这两者的想法?主要目的是为pdf提供注释。将动力学JS添加到PDF文件

+1

好吧,这个想法是将Kinetic画布保存为图像,然后将该图像放置在pdf.js画布中。这可能会指向你在正确的方向:http://stackoverflow.com/questions/13164226/kineticjs-toimage-proper-method-for-creating-image-from-region-group – SoluableNonagon 2013-03-22 18:46:26

+0

我不知道这将是有益的。我需要能够稍后编辑形状。我还需要能够看到pdf,以便放置形状很有意义。 – user2200401 2013-03-22 19:45:45

+0

您可以发布引用pdf.js画布的代码 – SoluableNonagon 2013-03-22 20:20:58

回答

0

如果你不太深入这个过程,你可以尝试Bytescout生成.pdf,并且还包含一个钩子来将你的canvas图像加载到你的pdf中。

一切都在客户端完成,因此您可以查看/编辑/查看/编辑您心中的内容。

他们在这里:http://bytescout.com/products/developer/pdfgeneratorsdkjs/index.html(顺便说一句,没有推销这里 - 我没有连接以任何方式bytescout!)

下面是从他们的网站的例子显示了一个嵌入式的画布:

function CreatePDF() { 

    // create BytescoutPDF object instance 
    var pdf = new BytescoutPDF(); 

    // set document properties: Title, subject, keywords, author name and creator name 
    pdf.propertiesSet("Sample document title", "Sample subject", "keyword1, keyword 2, keyword3", "Document Author Name", "Document Creator Name"); 

    // set page size 
    pdf.pageSetSize(BytescoutPDF.A4); 

    // set page orientation (BytescoutPDF.PORTRAIT = portrait, BytescoutPDF.LANDSCAPE = landscape) 
    pdf.pageSetOrientation(BytescoutPDF.PORTRAIT); 

    // add new page 
    pdf.pageAdd(); 

    // create temporary canvas (you can also simply get existing canvas) 
    var canvas = document.createElement('canvas'); 
    // set width and height 
    canvas.width = 320; 
    canvas.height = 240; 

    // get context from canvas (to draw on) 
    var context = canvas.getContext("2d"); 

    // set white background color 
    context.fillStyle = "#FFFFFF"; 
    // and fill the background with white color 
    context.fillRect(0, 0, 320, 240); 

    // draw the yellow circle 
    context.strokeStyle = "#000000"; 
    context.fillStyle = "#FFFF00"; 
    context.beginPath(); 
    context.arc(100, 100, 50, 0, Math.PI * 2, true); 
    context.closePath(); 
    context.stroke(); 
    context.fill(); 

    // load image from canvas into BytescoutPDF 
    pdf.imageLoadFromCanvas(canvas); 

    // place this image at given X, Y coordinates on the page 
    pdf.imagePlace(20, 40); 


    // return BytescoutPDF object instance 
    return pdf; 
} 
+0

谢谢。我认为BytescoutPDF的工作原理与JSPDF相似,它根据画布内容创建一个pdf。我其实没有这个问题。问题在于查看现有PDF(使用pdf.js)并使用KineticJS向该PDF添加注释。 – user2200401 2013-03-22 21:00:17