How do I align an image with pdfmake? - pdfmake

I'm using pdfmake to create a PDF and have successfully used a data URI to embed an image. It is a small image, about 200px across, and I would like to have it right-aligned. Is there any way to push an image to the right side of the PDF?

You can right align your image using a pre-defined style in your document definition. The pdfmake playground has a good example of images, which I edited to add the 'right aligned' style (called 'rightme') below. I tried just adding 'alignment: right' to the document definition directly, but this does not work.
I removed the image data due to length - visit the pdfmake playground images to see this working:
var dd = {
content: [
'pdfmake (since it\'s based on pdfkit) supports JPEG and PNG format',
'If no width/height/fit is provided, image original size will be used',
{
image: 'sampleImage.jpg',
},
'If you specify width, image will scale proportionally',
{
image: 'sampleImage.jpg',
width: 150
},
'If you specify both width and height - image will be stretched',
{
image: 'sampleImage.jpg',
width: 150,
height: 150,
},
'You can also fit the image inside a rectangle',
{
image: 'sampleImage.jpg',
fit: [100, 100],
pageBreak: 'after'
},
// Warning! Make sure to copy this definition and paste it to an
// external text editor, as the online AceEditor has some troubles
// with long dataUrl lines and the following image values look like
// they're empty.
'Images can be also provided in dataURL format...',
{
image: **'IMAGE TRUNCATED FOR BREVITY'**,
width: 200,
style: 'rightme'
},
'or be declared in an "images" dictionary and referenced by name',
{
image: 'building',
width: 200
},
],
images: {
building: **'IMAGE DATA TRUNCATED FOR BREVITY'**
},
styles:{
rightme:
{
alignment: 'right'
}
}
}

Code below demonstrates left (default), center and right justifying an image.
Paste following code into http://pdfmake.org/playground.html for live view.
Playground requires you to assign document definition to a variable called dd
var dd = {
content: [
'left align image', ' ',
{
image: 'sampleImage.jpg',
width: 100,
height: 100,
alignment: 'left' // Default... not actually required.
},
' ', ' ', 'center align image', ' ',
{
image: 'sampleImage.jpg',
width: 100,
height: 100,
alignment: 'center'
},
' ', ' ', 'right align image', ' ',
{
image: 'sampleImage.jpg',
width: 100,
height: 100,
alignment: 'right'
}
]
}

$('#cmd').click(function () {
var img = document.getElementById('imgReq');
var empImage = img.getAttribute('src');
var docDefinition = {
pageMargins: [0, 0, 0, 0],
content: [
{
style: 'tableExample',
table: {
headerRows: 1,
body: [
[ {
image: 'building',
width: 195,
height: 185,
} ],
]
},
layout: {
hLineWidth: function(i, node) {
return (i === 0 || i === node.table.body.length) ? 0 : 0;
},
vLineWidth: function(i, node) {
return (i === 0 || i === node.table.widths.length) ? 0 : 0;
},
hLineColor: function(i, node) {
return (i === 0 || i === node.table.body.length) ? '#276fb8' : '#276fb8';
},
vLineColor: function(i, node) {
return (i === 0 || i === node.table.widths.length) ? '#276fb8' : '#276fb8';
},
paddingLeft: function(i, node) { return 0; },
paddingRight: function(i, node) { return 0; },
paddingTop: function(i, node) { return 0; },
paddingBottom: function(i, node) { return 0; }
}
}
],styles:{
tableExample: {
margin: [200, 74, 0, 0],
//alignment: 'center'
}
}, images: {
building: empImage
}
};

I used images "dictionary" in the browser (not in Nodejs) to locate an image from the server like this:
{
content: [
{
image: 'imageKey',
width: 20,
height: 20
}
],
images: {
imageKey: window.location.origin + "path/to/image" // via URL address, which can be referenced by this key
}
}
This allows you to (re-)use local images from the server with ease. I hope this will be helpful to someone in a similar situation.

just add alignment: "center" to the image, it works out for me)

Related

How to bind database in Syncfusion Bar Chart on Asp.net mvc

I tried to use the code on its documentation but it's still not running even if it's static data. Here is the code on the link that I've used but it is not connected to the database. Here are the pictures of the codes I've used:
//CS File(I JUST PUT HERE)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Charts;
namespace EJ2MVCSampleBrowser.Controllers.Chart
{
public partial class ChartController : Controller
{
// GET: RoundedColumn
public ActionResult RoundedColumn()
{
List<RoundedColumnChartData> chartData = new List<RoundedColumnChartData>
{
new RoundedColumnChartData { x= "BGD", y= 106, text= "Bangaladesh" },
new RoundedColumnChartData { x= "BTN", y= 103, text= "Bhutn" },
new RoundedColumnChartData { x= "NPL", y= 198, text= "Nepal" },
new RoundedColumnChartData { x= "THA", y= 189, text= "Thiland" },
new RoundedColumnChartData { x= "MYS", y= 250, text= "Malaysia" }
};
ViewBag.dataSource = chartData;
ViewBag.font = new { fontWeight = "600", color = "#ffffff" };
return View();
}
public class RoundedColumnChartData
{
public string x;
public double y;
public string text;
}
}
}
//CSHTML File (I JUST PUT HERE)
<script src="~/Scripts/theme-color.js"></script>
<div class="control-section">
<div style="text-align:center">
#Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column).XName("x").YName("y")
.CornerRadius(cr=>cr.BottomLeft(10).BottomRight(10).TopLeft(10).TopRight(10))
.Marker(mr => mr.DataLabel(dl => dl.Visible(true).Position(Syncfusion.EJ2.Charts.LabelPosition.Top).Font(ff => ff.FontWeight("600").Color("#ffffff"))))
.DataSource(ViewBag.dataSource).Name("Tiger").Add();
}).PrimaryXAxis(px => px.Interval(1).MajorGridLines(mg=>mg.Width(0))
.LabelStyle(ls=>ls.Color("#ffffff")).TickPosition(Syncfusion.EJ2.Charts.AxisPosition.Inside)
.LabelPosition(Syncfusion.EJ2.Charts.AxisPosition.Inside).ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py => py.Minimum(0).Maximum(300).Interval(50)
.MajorGridLines(mg => mg.Width(0)).LabelStyle(ls=>ls.Color("transparent"))
.MajorTickLines(mg => mg.Width(0)).LineStyle(mg => mg.Width(0))
).Title("Trade in Food Groups").ChartArea(area => area.Border(br=>br.Color("transparent"))
).Tooltip(tt => tt.Enable(false)).LegendSettings(lg => lg.Visible(false)
).Load("load").PointRender("pointRender").Loaded("loaded").Render()
</div>
<div style="float: right; margin-right: 10px;">
Source:
blogs.scientificamerican.com
</div>
</div>
<script>
var pointRender = function (args) {
var selectedTheme = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
if (selectedTheme && selectedTheme.indexOf('fabric') > -1) {
args.fill = fabricColors[args.point.index % 10];
}
else if (selectedTheme === 'material') {
args.fill = materialColors[args.point.index % 10];
}
else {
args.fill = bootstrapColors[args.point.index % 10];
}
};
var count = 0;
var loaded = function (args) {
args.chart.loaded = null;
setInterval(
function () {
if (count === 0) {
args.chart.series[0].dataSource = [
{ x: 'Tea', y: 206, text: 'Bangaladesh' },
{ x: 'Misc', y: 123, text: 'Bhutn' },
{ x: 'Fish', y: 48, text: 'Nepal' },
{ x: 'Egg', y: 240, text: 'Thiland' },
{ x: 'Fruits', y: 170, text: 'Malaysia' }
];
args.chart.animate();
count++;
}
else if (count === 1) {
args.chart.series[0].dataSource = [
{ x: 'Tea', y: 86, text: 'Bangaladesh' },
{ x: 'Misc', y: 173, text: 'Bhutn' },
{ x: 'Fish', y: 188, text: 'Nepal' },
{ x: 'Egg', y: 109, text: 'Thiland' },
{ x: 'Fruits', y: 100, text: 'Malaysia' }
];
args.chart.animate();
count++;
}
else if (count === 2) {
args.chart.series[0].dataSource = [
{ x: 'Tea', y: 156, text: 'Bangaladesh' },
{ x: 'Misc', y: 33, text: 'Bhutn' },
{ x: 'Fish', y: 260, text: 'Nepal' },
{ x: 'Egg', y: 200, text: 'Thiland' },
{ x: 'Fruits', y: 30, text: 'Malaysia' }
];
args.chart.animate();
count = 0;
}
}, 2000);
}
</script>
}

How to turn off Blackscreen in IOS Web View

Using Quagga.js, we are working on barcode recognition in web view.
It works fine on the mobile web, but it happens on the APP.
The problem is two things below.
The target div provided by Quagga does not contain the camera, but switches to the full screen.
Problem 1 Image
After barcode recognition, the camera remains in the Blackscreen state, not off.
Problem 1 Image
Already unpacked permissions from info.plist.
Privacy - Camera Usage Description
Privacy - Photo Library Additions Usage Description
Below is my code.
openItem.addEventListener("click", () => {
document.querySelector(".barcode_Camera").style.bottom = "0px";
/* Barcode Scan Script */
Quagga.init({
inputStream: {
type : "LiveStream",
target: document.querySelector('#camera_Area'), // Or '#yourElement' (optional)
constraints: {
width: {min: 1280},
height: {min: 480},
facingMode: "environment",
aspectRatio: {min: 1, max: 2}
}
},
locator: {
patchSize: "small",
halfSample: true
},
numOfWorkers: 4,
frequency: 10,
decoder: {
readers : [{
format: "code_93_reader",
config: {}
}],
debug: {
drawBoundingBox: false,
showFrequency: false,
drawScanline: false,
showPattern: false
},
multiple: false
},
}, function (err) {
if (err) {
console.log(err);
return
}
console.log("Initialization finished. Ready to start");
Quagga.start();
});
}); /*Close*/
Quagga.onProcessed(function (result) {
let drawingCtx = Quagga.canvas.ctx.overlay,
drawingCanvas = Quagga.canvas.dom.overlay;
if (result) {
if (result.boxes) {
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")),
parseInt(drawingCanvas.getAttribute("height")));
result.boxes.filter(function (box) {
return box !== result.box;
}).forEach(function (box) {
Quagga.ImageDebug.drawPath(box, {x: 0, y: 1}, drawingCtx, {color: "#88d147", lineWidth: 2});
});
}
}
});
Quagga.onDetected(function (data) {
document.querySelector('#barcode').value = data.codeResult.code;
let closeTarget = closeItem.closest(".barcode_Camera");
document.querySelector(".barcode_Camera").style.bottom = "-100%";
Quagga.stop();
});
I would like to ask for your help if there is anything else I need to do in the info.plist or how I can solve the problem.

Highcharts Export Server: Polar Chart Ignoring Formatters in Callback

We're currently generating a polar chart in HighCharts that renders correctly on the client-side (in the browser), and correctly applies formatters to the xAxis, yAxis, and plotOptions. Here is a jsFiddle that shows how it is rendering (correctly) in the browser: https://jsfiddle.net/cmodzelewski/38f03Lse/1/
On the server side, we are constructing a JSON payload and sending it to a node-export-server instance and returning a PNG. Based on our research, it is clear that formatters need to be included in the callback key of our JSON payload and passed to the server as a string, rather than in the infile key.
That's fine, and so we're converting our formatter functions into strings, composing them into the options object in our callback key, and then redrawing the chart at the end of our callback key.
This approach works great for non-polar charts, but if polar == true the export server returns a valid PNG from the export server, however that chart does not apply our formatter functions to the xAxis, yAxis, or plotOptions.series.
Here is the JSON payload that we are sending to a node-export-server instance:
{
"callback": "function (chart) {var options = chart.options;var xAxisFormatter = function () { var extra_hrs = 0; if (this.value == 0) { extra_hrs = 12; }; return ((this.value / 0.5)/60) + extra_hrs + ':00'; };if (\"labels\" in options[\"xAxis\"]) { options[\"xAxis\"][\"labels\"][\"formatter\"] = xAxisFormatter; } else { options[\"xAxis\"][\"labels\"] = { \"formatter\": xAxisFormatter, \"style\": { \"fontSize\": \"8px\" } }; };var yAxisFormatter = function () { return Highcharts.numberFormat(this.value, 2, '.', ',') + \"%\"; };if (\"labels\" in options[\"yAxis\"]) { options[\"yAxis\"][\"labels\"][\"formatter\"] = yAxisFormatter; } else { options[\"yAxis\"][\"labels\"] = { \"formatter\": yAxisFormatter, \"style\": { \"fontSize\": \"8px\" } };};var plotOptionsFormatter = function () { return Highcharts.numberFormat(this.value, 2, '.', ',') + \"%\"; };options[\"plotOptions\"][\"series\"][\"dataLabels\"][\"formatter\"] = plotOptionsFormatter;chart = new Highcharts.chart(chart.container, options);chart.redraw();}",
"infile": "{chart: {backgroundColor: \"white\", borderWidth: 0, height: 300, polar: true, width: 300}, colors: [\"#16C1F3\", \"#3C6E71\", \"#EAC435\", \"#E63946\", \"#33658A\", \"#DFD6A7\", \"#627264\", \"#86CCA5\", \"#6268B0\", \"#E8D33F\", \"#DA2C38\"], credits: {enabled: false, position: {align: \"right\", verticalAlign: \"bottom\"}, text: \"(c) Insight Industry Inc., 2017.\"}, exporting: {enabled: false}, legend: {enabled: false}, plotOptions: {column: {groupPadding: 0, pointPadding: 0}, series: {dataLabels: {}, pointInterval: 30, pointStart: 0}}, series: [{data: [{name: \"12:00am - 4:59am\", x: 0, y: 2.737994945240101}, {name: \"5:00am - 5:29am\", x: 150, y: 1.6287559674248806}, {name: \"5:30am - 5:59am\", x: 165, y: 1.6849199663016006}, {name: \"6:00am - 6:29am\", x: 180, y: 5.9112608817747825}, {name: \"6:30am - 6:59am\", x: 195, y: 11.513619769727605}, {name: \"7:00am - 7:29am\", x: 210, y: 17.98652064026959}, {name: \"7:30am - 7:59am\", x: 225, y: 17.733782645324347}, {name: \"8:00am - 8:29am\", x: 240, y: 20.190957596180848}, {name: \"8:30am - 8:59am\", x: 255, y: 7.848918843021623}, {name: \"9:00am - 9:59am\", x: 270, y: 8.438640831227183}, {name: \"10:00am - 10:59am\", x: 300, y: 3.1592249368155008}, {name: \"11:00am - 11:59am\", x: 330, y: 1.1654029766919405}], name: null, pointPlacement: \"on\", type: \"column\"}], title: {text: null}, tooltip: {style: {fontSize: \"10px\"}, valueDecimals: 1, valueSuffix: \"%\"}, xAxis: {labels: {style: {fontSize: \"10px\"}}, max: 360, min: 0, tickInterval: 30, title: {text: null}}, yAxis: {labels: {style: {fontSize: \"10px\"}}, max: 25.0, min: 0, showLastLabel: false, tickInterval: 5, title: {style: {color: \"#0A3B61\", fontSize: \"9px\", fontWeight: \"bold\"}, text: \"Workers, Aged 25+\"}}}",
"scale": 2,
"type": "png"
}
We have recreated what we (suspect) is the process that the node export server goes through, and have definitely recreated the (weird) behavior that we're seeing in this jsFiddle: https://jsfiddle.net/cmodzelewski/v4gm6t9a/2/
Are we missing something blatantly obvious (which is what we suspect)? Or is there a better way of doing this to get the behavior we're looking for?
Any help would be very much appreciated!
In your fiddle with the suspected process, and in your callback, you are setting the axis labels in the following way:
options["yAxis"]["labels"]
This will set an object labels on the yAxis element, however, since you can have several axis in highcharts, they are indexed, and stored as such. That means you have to edit the first axis like this:
options["yAxis"][0]["labels"]
Here is a picture of the yAxis object in the incorrect configuration:
Here is a picture of the yAxis object in the correct configuration:
Working example using your second fiddle: https://jsfiddle.net/ewolden/v4gm6t9a/4/

Can't put row above tableheader

I made a custom row and want to put it above the table header. How can i do this? see custom row , I got this from the example, can anyone please help me? here my code :
doc.autoTable(columns, rows, {
theme : 'grid',
styles: {
halign: 'right'
},
headerStyles: {
fillColor: [33, 150, 243],
halign:'center'
},
margin : {
top : 100
},
columnStyles:{
0: {halign:'left'}
},
createdCell: function(cell, data) {
if (data.row.index === 0 || data.row.index === 3 ||data.row.index === 6 ||data.row.index === 9
|| data.row.index === 12 || data.row.index === 13 || data.row.index === 14) {
cell.styles.fontStyle = 'bold';
cell.styles.fillColor = [255,251,204];
}
},
drawRow: function (row, data) {
// Colspan
doc.setFontStyle('bold');
doc.setFontSize(20);
if (row.index === 0) {
doc.setTextColor(200, 0, 0);
doc.rect(data.settings.margin.left, row.y, data.table.width, 20, 'S');
doc.autoTableText("Raportage Handelsregister", data.settings.margin.left + data.table.width / 2, row.y + row.height / 2, {
halign: 'center',
valign: 'middle',
});
data.cursor.y += 20;
}
}
});

Angular UI-Grid changing columnDefs

I have a UI-Grid in my View and in some cases i have to show differents things and differents configuration (editable for example).
One of my column is a dropdownlist, but when I change grid columnDefs my dropdown column is alaways as a text and don't allow edit.
$scope.grdComposicaoQuimica =
{
showGridFooter: true,
enableSorting: true,
enableGridMenu: true,
exporterMenuCsv: false,
exporterMenuPdf: false,
enableRowHeaderSelection: false,
enableCellEditOnFocus: true,
data: [],
};
$scope.atualizarCondicao = function () {
if ($('#hdf-Operacao').val() == "I" || $('#hdf-Operacao').val() == "E") {
$scope.grdComposicaoQuimica.enableCellEdit = true;
$scope.grdComposicaoQuimica.columnDefs = [
{ displayName: 'Elemento', field: 'COD_ELEME_QUIMI', minWidth: 75, enableCellEdit: false },
{ name: 'COD_UNIDA_MEDIDA', displayName: 'Unid. Medida', minWidth: 80, editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownRowEntityOptionsArrayPath: 'UnidadesMedida', editDropdownIdLabel: 'COD_UNIDA_MEDID', editDropdownValueLabel: 'COD_UNIDA_MEDID'},
{ displayName: 'Mínimo', field: 'VLR_MINFA_ELEME', minWidth: 100, type: 'number' },
{ displayName: 'Máximo', field: 'VLR_MAXFA_ELEME', minWidth: 100, type: 'number' }
]
}
else {
$scope.grdComposicaoQuimica.enableCellEdit = false;
$scope.grdComposicaoQuimica.columnDefs = [
{ displayName: 'Elemento', field: 'COD_ELEME_QUIMI', minWidth: 75 },
{ displayName: 'Unid. Medida', field: 'COD_UNIDA_MEDIDA', minWidth: 75 },
{ displayName: 'Mínimo', field: 'VLR_MINFA_ELEME', minWidth: 100, type: 'number' },
{ displayName: 'Máximo', field: 'VLR_MAXFA_ELEME', minWidth: 100, type: 'number' }
]
}
};
The property "UnidadesMedida" was loaded when I filled out grid data. For each row this property is loaded.
All of others configuration works, just dorpdownlist column don't.

Resources