--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/fc768134-c453-4b94-838b-f4ee96d932bc%40googlegroups.com.
<script src="{{=URL('static','js/jspdf.debug.js')}}"></script>
<script src="{{=URL('static','js/jspdf.min.js')}}"></script>
<script src="{{=URL('static','js/html2canvas.js')}}"></script>
<script type="text/javascript">
function genPDF()
{
let pdfName = "licencia";
var doc = new jsPDF({
format: "a4"
});
html2canvas(document.getElementById("IDName"), {
scale: "5"
}).then(canvas => {
console.log("Capturando");
this.imgFile = canvas;
doc.addImage(this.imgFile, "JPEG", 5, 5, 200, 250);
doc.save('filename.pdf');
});
}
</script>
<div id="pdf"><a href="javascript:genPDF()">Click to Download as PDF</a></div>
I have no issue styling the vouchers in HTML (this is already done in a view) my issue is how to capture that view and send it via email either as message or attachment.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/020c2eb9-f2b9-494e-901d-8990853b79d7%40googlegroups.com.
Hey thanks a lot will try it out!!
From: web...@googlegroups.com [mailto:web...@googlegroups.com] On Behalf Of mostwanted
Sent: 27 January 2020 15:47
To: web2py-users
Subject: [web2py] Re: Saving a view as an file/image
Hey John, I dont know if this will help you but there was a time when i needed to convert a view to PDF & I used 2 l js libraries, html2canvas & jsPDF, they enabled me to achieve my goal that time, you can find the jsPDF package here: https://github.com/MrRio/jsPDF
and the html2canvas package here: https://github.com/niklasvh/html2canvas/releases
After extracting all the files from the compressed folders look for these 2 js files in jsPDF; jspdf.debug.js, jspdf.min.js, and the html2canvas.js in the html2pdf folder, upload them into your application's static/js directory, from there call them in your application's layout page like this:
<script src="{{=URL('static','js/jspdf.debug.js')}}"></script>
<script src="{{=URL('static','js/jspdf.min.js')}}"></script>
<script src="{{=URL('static','js/html2canvas.js')}}"></script>
<script src="{{=URL('static', 'js/moments.js')}}"></script>
In the view that you want to convert to PDF have this javascript code:
<script type="text/javascript">
function genPDF()
{
let pdfName = "licencia";
var doc = new jsPDF({
format: "a4"
});
html2canvas(document.getElementById("invoicing"), {
scale: "5"
}).then(canvas => {
console.log("Capturando");
this.imgFile = canvas;
doc.addImage(this.imgFile, "JPEG", 5, 5, 200, 250);
doc.save('filename.pdf');
});
}
</script>
In the same view have a link that when clicked calls the above js function like this:
<div id="pdf"><a href="javascript:genPDF()">Click to Download as PDF</a></div>
This should convert you view into PDF or Image as per the usage of both liraries.
I hope the maintainers of the jsPDF & html2pdf libraries have not made adjustmets that may cause this not to work;
Regards
Mostwanted
On Sunday, January 26, 2020 at 4:25:47 PM UTC+2, John Bannister wrote:
Hi All,
I have hit a bit of a stumbling block and would like to know if anyone else has come across this and how to resolve it.
Situation is as follows:-
I am generating tickets/coupons for users once they have entered all the appropriate info which I am doing via normal controller/view using html for styling. Coupon consists of 2 images plus some text (nothing really fancy at all).
Everything looks okay and as it should in the view with all the correct information etc.
I now what to email the coupon to the user. This is where I am a bit stumped.
I am assuming that I will need to save the rendered view as an image/file/.pdf if I want the styling, logos, qrcodes etc to be in the email that I will send as well as for all the formatting to be as per the view.
Is there any easy way or any way at all to do this?
In the controller I can use the response.render(view, args) but still cant see how to create a pdf file from the actual view before sending the email.
Hopefilly I ma missing something simple
Thanks in advance
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/7643b84a-9fa5-490a-9a47-d5775f859b27%40googlegroups.com.
The FPDF module has an HTML Renderer which you might find useful.- Scott