Using Net MVC and Signaturepad, I´m taking a signature from users and generating a PNG by using this:
<canvas id="#("canvas" + flat.ID)" width="400" height="200" style="background-color: lightgrey;"></canvas>
<script type="text/javascript">
var canvas = document.querySelector("#("#canvas" + flat.ID)");
var signaturePad = new SignaturePad(canvas, {
backgroundColor: 'rgba(211,211,211, 1)',
penColor: 'rgb(0, 0, 0)'
});
</script>
I´m storing the signature in a database by using
<button class="btn btn-shadow btn-block btn-primary" onclick="saveSignature('#Url.Action("SaveSignature", "Home", new { Area = "AssemblyOrders" })', signaturePad.toDataURL(), '#flat.ID', '#ViewBag.AssemblyOrderID')">Speichern</button>
This does nothing but setting the value in database.
In database I find the generated string:
data:image/png;base64,iVBORw...
I´m loading the view and if the viewmodel has that string I´m displaying it as an image:
<img src="#flat.Signature" style="width: 100%; height: 200px;"/>
This is only showing the lightgrey background from signaturepad but not the handwritten signature.
Where is the problem?
edit: I also tried saving it to desktop, but this png is also only lightgrey without lines.
Problem were this lines of code:
var signaturePad = new SignaturePad(canvas, {
backgroundColor: 'rgba(211,211,211, 1)',
penColor: 'rgb(0, 0, 0)'
});
Because of multiple canvas, as you can see from <canvas id="#("canvas" + flat.ID)" ..., the var signaturePad existed multiple times. Thus always the last var was used.
I solved it like this:
var pads = {};
...
pads["#("#canvas" + flat.ID)"] = new SignaturePad(canvas, {
backgroundColor: 'rgba(211,211,211, 1)',
penColor: 'rgb(0, 0, 0)'
});
and
onclick="saveSignature('#Url.Action("SaveSignature", "Home", new { Area = "AssemblyOrders" })', pads['#("#canvas" + flat.ID)'].toDataURL(), '#flat.ID', '#ViewBag.AssemblyOrderID')"
Related
I have this button
<button
className="rounded border px-4 py-2"
onClick={() => {
const doc = new jsPDF();
doc.html(document.querySelector(".invoice-box"), {
callback: function (pdf) {
console.log("lol", pdf);
pdf.save("invoice.pdf");
},
margin: 0,
});
}}>
Print
</button>
when I log the pdf it's working well, but... nothing happens!
Does someone know in Tauri how to create a pdf from html then print it?
I would like to know how to add in image.src a upload image.
I know that with convas i do image.src = event.target.result but it don't work.
ts
onFileSelected(event){
var layer = new Konva.Layer();
var stage: Konva.Stage;
var box: Konva.Rect;
var image = new Image();
image.onload = function()
{
var img = new Konva.Image({ image: image });
stage = new Konva.Stage({
container: 'container',
width: image.width,
height: image.height
});
layer.add(img);
stage.add(layer);
}
image.src = '' /* Image to put event.target.result */;
}
html
<input type="file" (change)="onFileSelected($event)" accept="image/*"> <br><br>
<div id="container" style="border: 2px solid red;"></div>
Your sample code looks basically functional. Open your browser dev tools (F12) and see if here are any messages or errors. I suspect cross-origin issues - search SO or Google for cross-origin for resolutions.
I can't give you a working angular example, nor even a working plain JS example that uses a file select because my Chrome browser insists I cannot load local files to this website. Anyway, the snippet below uses the change event of a select box in the same way that you would for a file select. It is based around the intention of your code.
$('#daFile').on('change', function(e){
var layer = new Konva.Layer();
var stage = new Konva.Stage({container: 'container'})
var image = new Image();
var path = $(this).val(); // jquery way of retreiving new path
image.onload = function()
{
var img = new Konva.Image({ image: image });
stage.size({width: image.width, height: image.height});
layer.add(img);
stage.add(layer);
stage.draw();
}
image.src = path;
})
setTimeout( function(){$('#daFile')
.val('https://i.stack.imgur.com/kSo4z.jpg')
.trigger('change');
}, 500);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/konvajs/konva/1.6.5/konva.min.js"></script>
<div>
Select a file
<select id='daFile'>
<option value='https://i.stack.imgur.com/Awa0C.png'>Nosey dog</option>
<option value='https://i.stack.imgur.com/kSo4z.jpg'>Snow dog</option>
</select>
</div>
<div id='container' style="display: inline-block; width: 300px, height: 200px; background-color: silver; overflow: hidden; position: relative;"></div>
<div id='img'></div>
Im trying to print the current page numbers using this: https://github.com/MrRio/jsPDF/pull/260
But jsPDF renders a huge amount of blank pages and crashes :(
Without the footer, every thing works fine and I get a nice PDF with 27 pages, but without footers ofcause
Console errors:
my footer is:
<footer>
<div style='text-align:center;'>Page <span class="pageCounter"></span>/<span class="totalPages"></span></div>
</footer>
and heres my Jquery part:
var doc = new jsPDF();
var margins = {
top: 10,
left: 10,
right: 10,
bottom: 20,
width: 265
};
doc.setProperties({
title: 'Title',
subject: 'This is the subject',
author: 'Author Name',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'Creator Name'
});
length = doc.internal.getNumberOfPages()
doc.fromHTML(response, margins.left, margins.top,{
'width': margins.width // max width of content on PDF
},
function(){
doc.save('noter.pdf');
}, margins);
You can use this code :
var doc = jsPDF();
doc.addPage();
doc.addPage();
doc.addPage();
doc.addPage();
var pageCount = doc.internal.getNumberOfPages(); //Total Page Number
for(i = 0; i < pageCount; i++) {
doc.setPage(i);
let pageCurrent = doc.internal.getCurrentPageInfo().pageNumber; //Current Page
doc.setFontSize(12);
doc.text('page: ' + pageCurrent + '/' + pageCount, 10, doc.internal.pageSize.height - 10);
}
Very strange! but apparently, the footer needs to have a <p> tag to make it work, even though it isen´t like that in the example on the github page...
So I´ve changed
<footer>
<div style='text-align:center;'>Page <span class="pageCounter"></span>/<span class="totalPages"></span></div>
</footer>
to
<footer>
<div><p>Page <span class="pageCounter"></span>/<span class="totalPages"></span></p></div>
</footer>
and it works now
i am using jspdf to generate a pdf.Its working but the file is download to "Download" folder.but i want to download specific folder like this("localhost/ccs/ccs/invoice") folder path to save the generated pdf.how to solve to change in my code. my example code is
<div class="invoice" id="customers" ng-repeat="aim in input">
<div align="right"><h1 align="right"><b>INVOICE</b> </h1></div>
<table>
<tr>
<td>
Hello
</td>
<td>
Hi
</td>
</tr>
</table>
</div>
<button onclick="javascript:demoFromHTML();">PDF</button>
my scripting code is
<script>
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#customers')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, {// y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Invoice.pdf');
}, margins);
}
</script>
<script type="text/javascript" src="http://mrrio.github.io/jsPDF/dist/jspdf.debug.js"> </script>
Thank you.
You could use 'FileSaver.js' along with jspdf.js, it will help you to save pdf in specific folder whereever you like.
var pdf = new jsPDF();
// your code here to write something in to pdf.
pdf.save(fileName);
I have a cakephp view (index.ctp) where I have edit button. On button edit I want the jquery dialog box open with what i have in edit.ctp. (Currently if I go to edit.ctp, it works fine but I am trying to use model / dialog box so the user stays on same page)
This is what I have in my index.ctp
<td>
<?php echo $this->Html->link($team['Company']['name'], array('action' => 'edit_reload','team_id'=>$team['Team']['id']), array('id'=>"dialog_link", 'class'=>"ui-state-default ui-corner-all"));?>
</td>
<div id="dialog" title="Dialog Title">
</div>
Now when the link clicked I want to show the edit_reload.ctp contents here. I am totally exhausted so any help will be appreciated
thanks
In a separate JS file write the following code and add your values to the variables and include the JS file in your .ctp file.
$(document).ready(function() {
$myWindow = $('#dialog');
//instantiate the dialog
$myWindow.dialog({ height: 250,
width: 200,
modal: true,
position: 'center',
autoOpen:false,
title:'',
overlay: { opacity: 0.5, background: 'black'}
});
$J("#dialog_link").click( showDialog );
});// end (document).ready
var showDialog = function() {
var team_id = '';
var url = '/controller/action/' + team_id;//Apply path to controller, action
$.post(url, function(res) {
$myWindow.dialog({
title:'Give Title'
});
$('#dialog').html(res);
$myWindow.show();
});
}
In .ctp file use the link as follows-
echo $this->Html->link($team['Company']['name'],'#', array('id'=>"dialog_link", 'class'=>"ui-state-default ui-corner-all"));
I have show you an example.You can also write the js code in the .ctp file also.