Use html2canvas to capture screen and print the image using weappbridge - html2canvas

I am using the web hardware bridge by imTigger. My goal is to do as silent printing directly from a webpage without invoking the system dialog.
Here is the web hardware bridge project:
https://github.com/imTigger/webapp-hardware-bridge
and I am able to map my printers and select and print directly to them pdfs and raw pdf using javascript like in many examples
I am also able to use html2canvas and capture the screen and append the image to the html and show it in the browser console.
Now I am trying to send the image to the printer using both codes and I get an ampty image.
The printer lights up but no image is printed. So I print to pdf using cutepdf so I can see what is printed and I get a blank pdf page.
Here is my code:
<script>
html2canvas(document.querySelector("#capture")).then(
canvas => {
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
console.log(image);
printService.submit({
'type': 'INVOICE',
'raw_content': image
});
});
</script>
I also tried this with no success
var image = canvas.toDataURL("image/png");
thanks!

I found the solution,
needed to remove data:image/png;base64 from the data and send the data as a file with the the png type 'url': 'file.png'.
This code works:
<script>
html2canvas(document.querySelector("#capture")).then(
canvas => {
var image = canvas.toDataURL("image/png").replace("data:image/png;base64,", "");
console.log(image);
printService.submit({
'type': 'INVOICE',
'url': 'file.png',
'file_content': image
});
});
</script>

Related

How to use Ordance Survey vector tiles with React-Leaflet?

I'm unsure of the correct syntax to add Ordnance Survey vector tiles to a React-Leaflet application.
The example code at https://labs.os.uk/public/os-data-hub-examples/os-vector-tile-api/vts-3857-basic-map loads some vector tile libraries from Mapbox:
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.13.1/mapbox-gl.js"></script>
<script src="https://unpkg.com/mapbox-gl-leaflet/leaflet-mapbox-gl.js"></script>
then uses this JavaScript syntax to load the OS vector tiles:
// Load and display vector tile layer on the map.
var gl = L.mapboxGL({
style: 'https://api.os.uk/maps/vector/v1/vts/resources/styles?key=' + apiKey,
transformRequest: url => {
return {
url: url += '&srs=3857'
}
}
});
(I've verified that my OS api key works in the stand-alone demo.)
How can accomplish the equivalent using React and Leaflet?
I'm using React-Leaflet to add Leaflet functionality to my React app, and I've tried adding react-leaflet-vector-tile-layer - I've verified that this works for vector tile layers supplied by Mapbox Studio:
<VectorTileLayer
styleUrl="mapbox://styles/my-org/my-style"
accessToken="my-key"
/>
I'm trying to use this approach for the Ordnance Survey vector tile layer too but it's not working as I probably have the syntax wrong:
<VectorTileLayer
styleUrl="https://api.os.uk/maps/vector/v1/vts/resources/styles?key=my-key"
/>
No error message is shown but the OS vector tile layer does not appear on the map. In the developer console I can see a PBF file has been downloaded but it doesn't draw on the map. Could this be because I'm missing the transformRequest function in their example? Assuming it's required, how can I add this transformation request when using react-leaflet-vector-tile-layer?
The answer came from Ted Piotrowski, the developer of the react-leaflet-vector-tile-layer library. I needed to add the transformRequest parameter using this syntax:
<VectorTileLayer
styleUrl="https://api.os.uk/maps/vector/v1/vts/resources/styles?key=my-key"
transformRequest={url => { return { url: url += '&srs=3857' }}}
/>

Display custom Image in jsTree - Build Tree from HTM Code behind

I amtry to display a costum Image in jsTree. I build the tree from a database via AJAX-Call. To build it up I use c# eg:
var s = "<li data-jstree='{'icon':'fa fa-check'}'> Konfiguration"
then I send "s" as JsonFile to on the Ajax call.
Can some on explain to me how I must format the string that I can display the image. Also I would pref to display an image out of my image-folder.
Thanks a lot for any suggest.

How to upload a "Image only from client side to SharePoint Custom List" using Rest Api ? not in Document Library and not in picture Library

I'm new to SharePoint & REST API. So kindly help me with Step by Step Instructions.
I have one custom list called "Attachment" within this custom list I have one Attachment column named as "Attach" which is created with the data type "Hyperlink or Picture".
Using Rest API I want to add the Image which is selected by the end user in client side (browser) to SharePoint Custom list named as "Attachment" under the column "Attach".
Help me with the working Code Samples.
Note: I'm trying this in visual studio 2017 as a SharePoint Hosted App.
This is my Default.aspx page code.
<div class="form-group">
<label>Attachments</label>
<input type="file" class="form-control" id="attch"/>
</div>
"I expect when the user selected any image using this control, I need to upload and store that image to custom List" not in document library , not in picture gallery. Only in Custom List.
Kindly Give me a Visual Studio Solution File (or) Give me a Clear Working code For Default.aspx and App.js with the Script.
Thanks in Advance!!!
The "Hyperlink or Picture" field only store the link of the image.
If you only want to store the image in custom list, we need store the images as attachments. I suggest you store the images into a document library or picture library, then use a "Hyperlink or Picture" to store the link of the images.
To upload image as attachment in list items using REST API, the following articles for your reference.
Working with files attached to list items by using REST
Uploading Attachments to SharePoint Lists Using REST
you need to create a document library instead and upload the image to it,
you can try this js to upload the image,
function _arrayBufferToBase64(buffer) {
var binary = ''
var bytes = new Uint8Array(buffer)
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i])
}
return binary;
}
function uploadfile(name, content) {
var createitem = new SP.RequestExecutor(appweburl);
createitem.executeAsync({
url: appweburl + "/_api/web/GetFolderByServerRelativeUrl('/sites/Tile of web/app title/Lists/list name/foldername')/Files/Add(url='" + name + "',overwrite=true)",
method: "POST",
binaryStringRequestBody: true,
body: content,
success: function (e) {
alert('done');
},
error: function () { alert("Error"); },
state: "Update"
});
}

Tinymce wiris math editor

I am using Wiris Editor as a plugin in TinyMCE. When I insert equation from Wiris Editor it displays it as an image in TinyMCE - I found this is embedded image but when I click the source tag to save the content it is the mathml format. I am unable to save the equation and searched almost everywhere but could not find a solution and I don't know why this is happening.
well.. you can not convert mathxml to HTML DOM Elements in a smoothly way. but you can make a trick to trace the code from the inspect element by the help of console.
wiris plugin used to render a iframe so you have to dig into the iframe document first.
$(function(){
// here "task_case_in_ifr" is the id for editor iframe div.
var iframe = $("#task_case_in_ifr")[0];
var iframeDocument = iframe.contentDocument
var iframeContent;
if (iframeDocument) {
// "tinymce" is the id for parent div containing all equation in the div.
iframeContent = iframeDocument.querySelectorAll('#tinymce');
}
var content = iframeContent[0].innerHTML
// save to database content variable..
// then show this value from the database on load document in jquery
// at first load it to the hidden element containing id.
// eg. div id is "#t1"
// fetch from the DOM by
iframeContent[0].innerHTML = $("#t1").html();
});

Save Google apps script GUI form as an image

Im am working with google apps acript on Goolge spreadsheet to create a simple tree object as a GUI.
function doGet(e) {
var app = UiApp.createApplication().setTitle("A").setWidth('1000').setHeight('600');
var tree = app.createTree().setAnimationEnabled(true);
var item = app.createTreeItem("B");
tree.addItem(item);
var scrollPanel = app.createScrollPanel().setSize('980', '580').setStyleAttribute('border', '1px solid black');
scrollPanel.add(tree);
app.add(scrollPanel);
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}
I would like to save this GUI as an image (png, jpg, pdf...) so that I could be able to put it in a report.
I would also like to embed the GUI in the spreadsheet so that I could be able to print it.
Can anyone help me?
I know that this could appear as a strange request but what I am trying to do is to create a very special kind of graph using the GUI tree object, that has not a counterpart in the graph objects