html2canvas and jspdf genereted blank pdf - jspdf

Hi i created invoice page and added to them jsPDF and html2canvas, but my solution generated blank pdf. How can I repair this? where is a bug ?
In my project used jspdf and html2canvas, can you help me with this?
Script:
$(document).ready(function() {
function generatePDF() {
window.scrollTo(0, 0);
var pdf = new jsPDF('p', 'pt', [1380, 2030]);
html2canvas($(".page-section")[0], {
onrendered: function(canvas) {
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');
var imgData = canvas.toDataURL("image/png", 1.0);
var width = canvas.width;
var height = canvas.clientHeight;
pdf.addImage(imgData, 'PNG', 20, 20, (width - 10), (height));
}
});
setTimeout(function() {
pdf.save('sample.pdf');
var blob = pdf.output("blob");
var blobURL = URL.createObjectURL(blob);
var iframe = document.getElementById('sample-pdf');
iframe.src = blobURL;
var downloadLink = document.getElementById('pdf-download-link');
downloadLink.href = blobURL;
}, 0);
};
generatePDF();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="https://instamarketing.pl/cennik/js/jspdf.min.js"></script>
<script type="text/javascript" src="https://instamarketing.pl/cennik/js/html2canvas.js"></script>
<div class="page-section">
test
</div>

Related

ThreeJS / GLTFLoader responded with 404 about my gltf object

I started an ASPNET MVC project and I tried to load a gltf object
GLTFLoader.js -> https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js
But my object isn't found... chrome console :
Project files:
I added something in web config:
<script src="~/Scripts/three.js"></script>
<script src="~/Scripts/OrbitControls.js"></script>
<script src="~/Scripts/GLTFLoader.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
test: 'xd'
}
});
</script>
<script>
var scene, renderer, camera;
var cube;
var controls;
function initialize() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0xdddddd);
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.lookAt(new THREE.Vector3(0, 0, 0));
camera.rotation.y = 45 / 180 * Math.PI;
camera.position.set(800, 100, 1000);
ambientLight = new THREE.AmbientLight(0x404040, 100);
scene.add(ambientLight)
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
$('#object').append(renderer.domElement);
let loader = new THREE.GLTFLoader();
loader.load('Cars/tutorial/scene.gltf', function (gltf) {
car = gltf.scene.children[0];
car.scale.set(0.5, 0.5, 0.5)
scene.add(gltf.scene);
renderer.render(scene, camera);
})
}
initialize();
</script>
Thanks!

How to create blob URL for large videos

I am using below javascript code to create blob URL. If video size is more like(500mb), then it is taking lot of time.
Please help me to create blob URL for large videos
if we can see Youtube the videos are playing very fast even though they are big in size with BLOB URL
<html>
<head>
<title>Blob URL</title>
</head>
<body>
<video controls="" preload="auto" id="_video"></video>
<script>
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
//console.log(atob(reader.result.slice(reader.result.indexOf(',') + 1)));
var byteCharacters = atob(reader.result.slice(reader.result.indexOf(',') + 1));
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
//console.log(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {type: 'video/mp4'});
var url = URL.createObjectURL(blob);
document.getElementById('_video').src = url;
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', 'domain.com/738-360p.mp4',true);
xhr.send();
</script>
</body>
</html>

Format content after table (jsPDF autotable)

i want to add content after a table in a pdf file that was created with jsPDF autotable.
My Code:
$('#printBtn').on('click', function() {
var pdf = new jsPDF('p', 'pt', 'a4');
var res = pdf.autoTableHtmlToJson(document.getElementById("tablePrint"));
var anfang = "Anfang";
pdf.text(anfang, 14, 30);
pdf.autoTable(res.columns, res.data, {
theme : 'plain',
styles: {
fontSize: 12
},
showHeader: 'never',
createdCell: function(cell, data) {
var tdElement = cell.raw;
if (tdElement.classList.contains('hrow')) {
cell.styles.fontStyle = 'bold';
}
}
});
var ende = $('#ende_text').text();
pdf.text(ende, 0, 12);
pdf.save("test.pdf");
});
My Problem is that the code isn't formatted. The tags and everything else was ignored by jsPDF.
How can i fix that or what can i do that the text has line breaks and not overflow?
Thanks for help!
margins={
top=50,
left=30,
bottom=50,
width=520
}
var pdf = new jsPDF("p", "pt","a4");
var res = pdf.autoTableHtmlToJson(document.getElementById("table2"));
pdf.autoTable(res.columns, res.data,{
margin: { left: 30,bottom:100},
startY: 30, pageBreak: 'always',
styles: {overflow: 'linebreak', columnWidth: 'wrap', font: 'arial',
cellPadding: 8, overflowColumns: 'linebreak'}
});
pdf.fromHTML($("#editor1").get(0), 30, pdf.autoTableEndPosY() + 20, {
'width': margins.width
},function(dispose)
{
var iframe = document.createElement('iframe');
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:40%; padding:20px;');
document.body.appendChild(iframe);
iframe.src = pdf.output('datauristring');
//pdf.save('name.pdf');
},
margins);
iam using the latest version of jspdf.min.js and jspdf.autotable.js
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.5/jspdf.plugin.autotable.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.4.1/jspdf.min.js"></script>

Handling EXCEPTION response from WMS Server

I tried to get a map image from a wms server using the following code.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Playing with fis broker berlin</title>
<link rel="stylesheet" href="../../libs/ol3/css/ol.css"/>
<link rel="stylesheet" href="../../css/samples.css"/>
</head>
<body>
<div id="map" class="map"></div>
<script src="../../libs/ol3/js/ol.js"></script>
<script>
var imageSource = new ol.source.ImageWMS({
url: 'http://fbinter.stadt-berlin.de/fb/wms/senstadt/k_dtk50',
params: {
'LAYERS': '0',
'REQUEST': 'GetMap',
'STYLES': ['default'],
'SRS': 'EPSG:4326',
'BBOX': [13.079, 52.3284, 13.7701, 52.6877],
'WIDTH': '256',
'HEIGT': '256',
'FORMAT': 'jpeg'
}
})
imageSource.on('imageloaderror', function (event) {
var imageState = event.target.getState()
var request = event.image.n
console.log('imageloaderror, state = ' + imageState)
console.log('request: ' + request)
})
var imageLayer = new ol.layer.Image({
opacity: 0,
source: imageSource
})
var view = new ol.View({
center: [13.4297269, 52.4594867],
zoom: 10
})
var map = new ol.Map({
target: 'map',
layers: [imageLayer],
view: view
})
</script>
</body>
</html>
ol3 fails to show the image, because the wms sends backs a xml exception report instead of jpeg data meaning
crs is not permitted: EPSG:3857.
On the java console we see the message
Resource interpreted as Image but transferred with MIME type text/xml ...
I understand, that the image source is not set up correctly. This needs further investigaton by me. But My question is:
How can I catch the message crs is not permitted: EPSG:3857 and any other error messages from the wms server by the ol script?
You will need to use XHR to load the image and get the exception text, see this thread for some inspiration:
https://groups.google.com/d/msg/ol3-dev/39tX1fSeSc0/KGURE6NrexIJ
imageLoadFunction: function(image, src) {
progress('start');
var img = image.getImage();
if (typeof window.btoa == 'function') {
var xhr = new XMLHttpRequest();
xhr.open('GET', src, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
if (this.status == 200) {
var uInt8Array = new Uint8Array(this.response);
var i = uInt8Array.length;
var binaryString = new Array(i);
while (i--) {
binaryString[i] = String.fromCharCode(uInt8Array[i]);
}
var data = binaryString.join('');
var type = xhr.getResponseHeader('content-type');
if (type.indexOf('image') === 0) {
img.src = 'data:' + type + ';base64,' + window.btoa(data);
} else {
error($.parseJSON(data));
}
} else {
error(this.statusText);
}
progress('end');
};
xhr.send();
} else {
img.onload = function() {
progress('end');
};
img.onerror = function() {
progress('end');
error();
};
img.src = src;
}
}
})

loading flickr photos by a set in div jquery mobile

i am creating a jquery mobile application;this is the script to load flickr photos thumbnail in a div it is loading but it is appearing in a group thumbnail not loading each images.can load each thumbnails by editing this.i just removed my api key and my ids.
$(function() {
var api_key = 'API KEY';
var user_id = 'ID';
var photoset_id = 'PHOTO SET ID';
var large_image_size = 'Medium';
var photoset_id,photo_id;
var current = -1;
var continueNavigation = false;
var photos_service = 'http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos' + '&api_key=' + api_key;
var photos_url = photos_service + '&photoset_id=' + photoset_id + '&media=photos&format=json&jsoncallback=?';
var large_photo_service = 'http://api.flickr.com/services/rest/?&method=flickr.photos.getSizes' + '&api_key=' + api_key;
var $photosContainer = $('#images').find('#ba');
var $photopreview = $('#flickr_photopreview');
var $flickrOverlay = $('#flickr_overlay');
var $loadingStatus = $('.loading_small');
$(function(){
$('#images').stop().animate(200,function(){
if($photosContainer.is(':empty')){
/*
if sets not loaded, load them
*/
LoadPhotos();
}
});
},function(){
});
function LoadPhotos(){
$photosContainer.empty();
$loadingStatus.css('visibility','visible');
$.getJSON(photos_url,function(data){
if(data.stat != 'fail') {
var photo_count = data.photoset.photo.length;
var photo_count_total = photo_count ;
for(var i = 0; i < photo_count; ++i){
var photo = data.photoset.photo[i];
var photoid = photo.id;
var secret = photo.secret;
var server = photo.server;
var farm = photo.farm;
var photoUrl = 'http://farm'+farm+'.static.flickr.com/'+server+'/'+photoid+'_'+secret+'_s.jpg';
var $elem = $('<div />');
var $link = $('<a class="toLoad" href="#" />');
$link.data({
'photoid' :photoid,
'secret' :secret,
'server' :server,
'farm' :farm,
'photoUrl' :photoUrl,
'photo_title' :photo.title
});
$photosContainer.append($elem.append($link));
$link.bind('click',function(e){
var $this = $(this);
current = $this.parent().index();
photo_id = $this.data('photoid');
LoadLargePhoto();
e.preventDefault();
});
}
LoadPhotosImages();
}
});
}
function LoadPhotosImages(){
var toLoad = $('.toLoad:in-viewport').size();
if(toLoad > 0)
$loadingStatus.css('visibility','visible');
var images_loaded = 0;
$('.toLoad:in-viewport').each(function(i){
var $space = $photosContainer.find('.toLoad:first');
var $img = $('<img style="display:none;" />').load(function(){
++images_loaded;
if(images_loaded == toLoad){
$loadingStatus.css('visibility','hidden');
$photosContainer.find('img').fadeIn();
}
}).error(function(){
//TODO
++images_loaded;
if(images_loaded == toLoad){
$loadingStatus.css('visibility','hidden');
$photosContainer.find('img').fadeIn();
}
}).attr('src',$space.data('photoUrl'))
.attr('alt',$space.data('photoid'));
var $photo_title = $('<span/>',{'html':$space.data('photo_title')});
$space.append($photo_title).append($img).removeClass('toLoad');
});
}
<!DOCTYPE html>
<html lang="en">
<head>
<script src="js/jquery-latest.js"></script>
<script type="text/javascript">
function downloadImg() {
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
{
ids : "78368944#N06",
tags: "",
tagmode: "any",
format: "json",
},
function(data) {
$('.img-1').attr('src', data.items[0].media.m);
$('.tit-1').text(data.items[0].title);
$('.img-2').attr('src', data.items[1].media.m);
$('.tit-2').text(data.items[1].title);
}
);
}
$(document).ready(function() {
downloadImg();
});
</script>
</head>
<body>
<div class="img-cont"><img class="img-1" /> </div>
<h3 class="tit-1"></h3>
<div class="img-cont"><img class="img-1" /> </div>
<h3 class="tit-1"></h3>
</body>
</html>

Resources