<script>
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
</script>
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>a pararaph</p>
<img src="4.jpg" />
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
I am exporting html to pdf. Without image in html content PDF exporting properly,But if I add image to HTML content it creates blank pdf.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js"></script>
<script>
function toPdf() {
var doc = new jsPDF();
// We'll make our own renderer to skip this editor
var specialElementHandlers = {
'#editor' : function(element, renderer) {
return true;
}
};
// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('#render_me').get(0), 30, 50, {
'width' : 170,
'elementHandlers' : specialElementHandlers
});
doc.save('sample-file.pdf');
}
Give id="render_me" to div what you want to render. for example
<table id="render_me"></table>
When using the fromHTML() it's important to save the pdf in the callback, because else it won't be done rendering by the time it saves the doc.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js"></script>
<script>
$(document).ready(function() {
var doc = new jsPDF();
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
}, function () {
doc.save('sample-file.pdf')
});
});
});
</script>
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>a pararaph</p>
<img src="//i.imgur.com/7NtRajR.jpg" />
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
Demo: https://jsfiddle.net/qcyspvy7/
Related
I'm not familiar with js. I'd like to get the result of "file_get_contents" function and put it on the "source" (I have marked both with .................).
Thank you in advance.
<script>
var myInit = {
referrer: '',
};
function file_get_contents(filename) {
fetch(filename, myInit).then((resp) => resp.text()).then(function(data) {
content = JSON.parse(data)
fetch(content['some']['media']['content'], myInit).then((resp) =>
resp.text()).then(function(data));});}
file_get_contents("https://.................");
</script>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/clappr#latest/dist/clappr.min.js">
</script>
</head>
<div id="player"></div>
<script>
window.onload = function() {
var player = new Clappr.Player({
source: '<?php echo $url...................?>',
parentId: "#player",
height: '100%',
width: '100%',
autoPlay: true,
});};
</script>
</body>
</html>
I think if you use the following code, you will get closer to your solution.
<script>
var myInit = {
referrer: '',
};
function file_get_contents(filename) {
fetch(filename, myInit).then((resp) => resp.text()).then(function(data) {
var content = JSON.parse(data);
console.dir(content);
var player = new Clappr.Player({
source: content['some']['media']['content'],
parentId: "#player",
height: '100%',
width: '100%',
autoPlay: true,
});
});
}
file_get_contents("https://.................");
</script>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/clappr#latest/dist/clappr.min.js">
</script>
</head>
<div id="player"></div>
<script>
window.onload = function() {
//Whatever
};
</script>
</body>
</html>
If you tell me what console.dir outputs, I might be able to offer more help.
BTW.: doesn't clapper have some documents showing how to use its API?
I've bought the "Sonorama" website template and there is ajax function for opening window with news.
But I need to take the news content dynamically from MySQL, so I have to open a .php file. But it works only for .html files.
Could someone please help me what should I edit to make this working?
Thanks!
HTML:
<li id="news?id=1" class="last-news"> <!-- Type One Thumb on Top, PHP, doesn't open -->
<div class="news-info">
<h1>ZIMNÍ KONCERTY SE ZNOUZECNOSTÍ</h1>
<p>Začátkem roku si po dlouhé době opět zahrajeme se Znouzecností.</p>
<div class="news-date">4.1.2016</div>
</div>
<div class="news-thumb">
<img src="img/img-news1.png" alt='img' />
</div>
</li><!-- end Type One -->
<li id="news-02.html" class="last-news"> <!-- Type Two Thumb on Bottom, HTML, works -->
<div class="news-thumb">
<img src="img/img-news2.png" alt='img' />
</div>
<div class="news-info">
<h1>NOVÉ PÍSNIČKY</h1>
<p>Připravujeme několik nových písniček, které již brzy můžete slyšet na dalších koncertech.</p>
<div class="news-date">3.12.2015</div>
</div>
</li><!-- end Type Two -->
AJAX FUNCTION:
/* Dynamic Window Ajax Content */
"use strict";
var $actual2= null;
var obert2=false;
$(".last-news").click(function() {
obre2($(this).attr('id'));
$actual2=$(this);
});
function obre2(quin2){
$.ajax({
url: quin2,
success: function(data) {
$('.news-content').html(data);
$(".news-content").hide(0)
$('.news-window').hide(0)
tanca2();
canvia2();
$("html, body").animate({ scrollTop: $('#news-show').offset().top - (200) }, 500, function(){
$('.news-window').show(0);
$('.news-window').css('height','0');
$('.news-window').animate({height:760}, 1000,function(){
$('.news-window').css('height','760');
$(".news-content").fadeIn("slow");
});
});
}
});
}
/**/
function canvi2(quin2){
var obert2=true;
$.ajax({
url: quin2,
success: function(data) {
$('.news-content').html(data);
tanca2();
canvia2();
$("html, body").animate({ scrollTop: $('#news-show').offset().top - (200) }, 500, function(){
$('.news-window').show(0);
$('.news-window').animate({height:760}, 1000,function(){
$('.news-window').css('height','760');
$(".news-content").fadeIn("slow");
});
});
}
});
}
/**/
function tanca2(){
$(".close2-btn").click(function() {
$(".news-window").slideUp("slow");
$(".news-content").fadeOut("slow");
$("html, body").animate({ scrollTop: $('#anchor01').offset().top }, 1000);
obert2=false;
});
}
function seguent(){
if($actual2.next().hasClass('end')){
$(".news-content").fadeOut("slow");
$actual2=$($('.start').next());
}else{
$(".news-content").fadeOut("slow");
$actual2=$($actual2.next());
}
if($actual2.hasClass('isotope-hidden')){
seguent();
}else{
$(".news-content").fadeOut("slow");
canvi2($actual2.attr('id'));
}
}
function enrera(){
if($actual2.prev().hasClass('start')){
$(".news-content").fadeOut("slow");
$actual2=$($('.end').prev());
}else{
$(".news-content").fadeOut("slow");
$actual2=$($actual2.prev());
}
if($actual2.hasClass('isotope-hidden')){
enrera();
}else{
$(".news-content").fadeOut("slow");
canvi2($actual2.attr('id'));
}
}
function canvia2(){
$('.news-next').click(function() {
seguent();
});
$('.news-prev').click(function() {
enrera();
});
}
I used bootstrap in my project. in each tab i show a chart my problem is the div display attribute is none and after user clicked on a tag the div display changes to the block. also i wrote a function to handle displaying the chart. but when user clicks on the tab chart not showing. but if i remove the display:none attribute its showing with no problem.
this is my div :
<div id="bar" style="display: none">
<?php echo chart($title,$data,'Bar');?>
</div>
and this is my chart function :
function chart($title,$data,$type){
ob_start();
?>
<script src="<?php echo url()?>/assets/chart/Chart.min.js" type="text/javascript"></script>
<script src="<?php echo url()?>/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<canvas style="display: block;margin: 0 auto;" id="myCanvas" width="600" height="300"></canvas>
<script>
$(function(){
var ctx = $('#myCanvas').get(0).getContext('2d');
var barChartData = {
labels : <?php echo json_encode($title) ?>,
datasets : [
{
fillColor : "rgba(10, 150, 100, 0.8)",
strokeColor : "rgba(24, 107, 2, 0.8)",
highlightFill: "rgba(4, 20, 60, 0.9)",
highlightStroke: "rgba(5, 35, 70, 1)",
data : <?php echo json_encode($data) ?>
}
]
};
var pieChart = new Chart(ctx).<?php echo $type?>(barChartData);
});
</script>
<?php
$view = ob_get_clean();
return $view;
}
and this is the script that shows the div when its clicked:
$('#aBar').on('click',function(){
$('#circle').css('display','none');
$('#line').css('display','none');
$('#bar').css('display','block');
});
Solved. I just have to set visibility to hidden and when user clicked on a tag set this to visible and everything is okay.
Using the code at the bottom, the a href part does show the relevant link where my mouse is at, but when I click it it just redirects to .../index.php#.
I need some coding help - so it redirects me to the actual url - which is held in var totalService3 = data.getValue(e.row, 4); and as I said, is being shown in the tooltip div.
regards
Peter
google.visualization.events.addListener(tree, 'onmouseover', function (e) {
var provider = data.getValue(e.row, 0);
var totalService = data.getValue(e.row, 2);
var totalService2 = data.getValue(e.row, 3);
var totalService3 = data.getValue(e.row, 4);
// populate the tooltip with data
$('#tooltipTopLine').html(provider);
$('#tooltipMiddleLine').html(totalService);
$('#tooltipBottomLine').html(totalService2);
$('#tooltipHyperlink').html(totalService3);
// show the tooltip
$('#tooltip').show();
});
google.setOnLoadCallback(drawVisualization);
// make the tooltip div follow the mouse
$(function () {
$('#visualization').mousemove(function (e) {
$('#tooltip').css({
left: e.pageX,
top: e.pageY - 40
});
});
});
}
<div id="container" style="width:400px; height: 1200px;padding-top: 20px;">
<div id="visualization" style="width: 400px; height: 400px;"></div>
<div id="tooltip" style="padding-bottom:10px;"> <span id="tooltipTopLine"></span>
<br />Price 1 <span id="tooltipMiddleLine"></span>
<br />Price 2 <span id="tooltipBottomLine"></span>
<br />Link
</div>
Not tested:
google.visualization.events.addListener(tree, 'onmouseover', function (e) {
// your code
$('#tooltip a').attr('href', totalService3);
// show the tooltip
$('#tooltip').show();
});
or
google.visualization.events.addListener(tree, 'onmouseover', function (e) {
//your code
$('#tooltipHyperlink').attr('href', totalService3);
// show the tooltip
$('#tooltip').show();
});
I am using a fullcalendar:-
http://arshaw.com/fullcalendar/
and I am using jquery .post to get a parameter back to the same page to generate some result, and this is working well.
At the same time, I wish to use jquery ui dialogue to hold the displayed contents. While pasting the sample codes from official site, the example works. However, when combining the .post output with dialogue, it was not successful.
I would like to seek help in combining the below 2 sets of scripts:-
//for generating .post output (working!)
<script>
function event_details(thevalue){
$.post('module/calendar/event_details.php',{
eid:thevalue},
function(output){
$('#theeventmsg').html(output);
});
}
</script>
<div id='theeventmsg'></div>
//jquery ui dialogue (working!)
<script>
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() {
$( "#dialog" ).dialog({
autoOpen: true,
show: "blind",
hide: "explode"
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});
</script>
<div class="demo">
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
</div><!-- End demo -->
Can help??? Thanks a lot!!
Try something like this:
<script>
$.fx.speeds._default = 1000;
$(document).ready(function() {
$( "#dialog" ).dialog({ autoOpen: false });
$('#button').click(function () {
var data = { ... };
$.post('module/calendar/event_details.php', data, function (output) {
$('#dialog p').html(output);
$( "#dialog" ).dialog("open");
});
});
});
</script>
<div id="dialog">
<p>content</p>
</div>
<button id="button">button</button>
Or:
<script>
$(document).ready(function () {
function eventdetail(thevalue) {
$.post('event_details.php', { eid: thevalue }, function (output) {
$('#dialog p').html(output);
$("#dialog").dialog({ autoOpen: true });
});
}
$('#button').click(function () { eventdetail('value'); });
});
</script>
<div id="dialog">
<p>content</p>
</div>
<button id="button">button</button>