pdfMake pageBreakBefore feature is not working - javascript

I am trying to concatenate multiple pdf files to a content variable. However I want each pdf content to be on a new page, but pdfmake.js just concatenate each content right after the other. I have added 'pageBreakBefore' function right after my content but it still doesn't work. Is there a way to make each content to be on separate page. (I am using jpdmake.js 1.60). Thanks!
Below is my code:
let content = [];
content = this.getContent(checkedOrders, selectedLabOrders);
this.docDefinition = {
info: {
title: 'Title',
subject: 'labOrder-'
},
pageSize: 'LETTER',
pageOrientation: 'landscape',
pageMargins: [40, 30, 40, 30],
content: content,
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
return currentNode.headlineLevel === 1 && followingNodesOnPage.length === 0;
},
unbreakable: true,
styles: {
titleHeader: {
fontSize: 16,
bold: true,
margin: [0, 10, 0, 0],
},
tableHeader: {
bold: true,
fontSize: 13,
color: 'black'
}
},
defaultStyle: {
fontSize: 9,
lineHeight: .9
}
};

Related

PhotoSphereViewer: <a href="…"> not working on touchscreen

I made a simple page with the "PhotoSphereViewer" library and i want to add a couple of links, with the "Markers Plugin".
http://klappfon.info/xxxemanuel/2/
It works like a charm on firefox and safari, but unfortunately not at all on touch screens / phone browsers...
The links seems "clickable" (turning to active state, red) but does not open...
My theory is that it has something to do with the navigation of the sphere since link does open when "PhotoSphereViewer" is set to "TwoFingerMode"...
Any ideas how to work around that?
THANKS!!!
plugins: [PhotoSphereViewer.GyroscopePlugin,
[PhotoSphereViewer.MarkersPlugin,{markers:[{
id: '1',
className: 'link',
longitude: 0.7,
latitude: 0,
html: '1234',
anchor: 'bottom right',
scale: [0.5, 1.5],
style: {
maxWidth: '200px',
color: 'white',
fontSize: '30px',
fontFamily: 'Helvetica, sans-serif',
textAlign: 'center',
},
},
]
}]
]
You cannot add links to html markers because the click is intercepted. Instead you should attach custom datato the marker and use the select-marker event.
https://photo-sphere-viewer.js.org/plugins/plugin-markers.html#select-marker-marker-data
const viewer = new PhotoSphereViewer({
plugins: [PhotoSphereViewer.GyroscopePlugin,
[PhotoSphereViewer.MarkersPlugin,{markers:[{
id: '1',
className: 'link',
longitude: 0.7,
latitude: 0,
html: '1234',
anchor: 'bottom right',
scale: [0.5, 1.5],
style: {
maxWidth: '200px',
color: 'white',
fontSize: '30px',
fontFamily: 'Helvetica, sans-serif',
textAlign: 'center',
},
},
data: { href: 'http://google.com' },
]
}]
]
});
const markersPlugin = viewer.getPlugin(PhotoSphereViewer.MarkersPlugin);
markersPlugin.on('select-marker', (e, marker) => {
window.location.href = marker.data.href;
});

Text height of specific character in Fabric.js

I have a text object in fabric.js that I am creating with:
fbText = new fabric.Textbox('#TEST', {
width: 700,
fill: '#303846',
top: 150,
left: 50,
fontSize: 150,
textAlign: 'left',
fixedWidth: 700,
// fontWeight: 'bold',
editable: false,
originY: 'center',
styles: {
// first word of text i.e Test
0: {
//first letter of first word i.e T
0: { fill: '#21bba6', fontSize: 130}
},
}
})
I would like to make the 1st letter higher than the rest of the word. Any thoughts on how that might be possible?
This is what I want to happen:
This is currently happening:
You can use deltaY negative value. There are more available style properties that can be used, have a look at [http://fabricjs.com/docs/fabric.Textbox.html#_styleProperties][1].
var fbText = new fabric.Textbox('#TEST', {
...,
styles: {
0: {
0: {
fill: '#21bba6',
fontSize: 130,
deltaY: -30
}
},
}
})

Plotly.js modebar, download as png, give png a name

I have a Plotly on my webpage and you can download it as a png by clicking the picture icon in the modebar. However when I click it, it downloads it as a png with the name new-plot, how can I give it a custom name?
My current code (var data is just data, so left it out) :
var layout = {
showlegend: true,
legend: {
x: 0,
y: 1
},
xaxis: {
title: 'Date',
titlefont: {
family: 'Courier New, monospace',
size: 18,
color: '#7f7f7f'
}
},
yaxis: {
title: 'Sales',
titlefont: {
family: 'Courier New, monospace',
size: 18,
color: '#7f7f7f'
}
}
};
var options = {
scrollZoom: true,
showLink: false,
modeBarButtonsToRemove: ['zoom2d', 'pan', 'pan2d', 'sendDataToCloud', 'hoverClosestCartesian', 'autoScale2d'],
displaylogo: false,
displayModeBar: true,
};
Plotly.newPlot('tester', data, layout, options);
Use Plotly.downloadImage
https://plot.ly/javascript/plotlyjs-function-reference/#plotlydownloadimage
Add this to your modebar setup for the button callback:
Plotly.downloadImage({
filename: 'customNamedImage',
format: 'png', //also can use 'jpeg', 'webp', 'svg'
height: 500,
width: 500
});
Edit:
I ran a custom example and I think you will want to custimze your own download button in the modebar, like so:
Plotly.newPlot(gd, [{
y: [1, 2, 1],
line: { shape: 'spline' }
}], {
title: 'custom modebar button',
width: 400,
height: 700
}, {
showTips: false,
displayModeBar: true,
modeBarButtons: [[{
name: 'custom download button',
icon: Plotly.Icons.camera,
click: function (gd) {
Plotly.downloadImage(gd, {
filename: 'your_custom_name',
format: 'jpeg',
width: gd._fullLayout.width,
height: gd._fullLayout.height
})
}
}, 'toImage'
], []]
})
There's an easier way to do this in newer versions of Plotly (v1.38+). Use the toImageButtonOptions parameter in the config like this:
Plotly.newPlot(graphDiv, data, layout, {
toImageButtonOptions: {
filename: 'image_filename',
width: 800,
height: 600,
format: 'png'
}
});
You can leave out options you don't need to use the defaults.

How to make table of PDF 100% width for datatables

I have a table that I'm saving as a pdfHtml5 in datatable. I'm trying to make the table full width but I have been unsuccessful. How can I make my table 100% width using styles for my pdfHtml5?
dom: 'Bfrtip',
buttons: [
{
extend: 'collection',
text: '<div class="image"><img src="/Asset/Image/Capture.jpg" alt="" /></div>',
autoClose: true,
buttons: [{
extend: 'pdfHtml5', text: 'Download PDF Document', className: 'pdfdoc', title: podTitle, message: pod.data.pod_description_text + "\n" + "\n" + printDate, customize: function (doc) {
doc.defaultStyle.alignment = 'left';
doc.styles.tableHeader.alignment = 'left';
doc.styles.message = {
alignment: 'center'
}
doc.styles.table = {
alignment: 'center',
width: '100%',
}
/*doc.content[1].table.widths = Array(doc.content[1].table.body[0].length + 1).join('*').split('');*/
doc.pageMargins = [ 80, 20, 80, 20 ];
}
}, { extend: 'excel', text: 'Download Excel Document', className: 'exceldoc' },
]
}
]
});
By further extending pdfHtml5, you can instruct the pdfmake library, used by the Buttons extension, to use 100% width. The DataTables forum has a post with the required code:
var tbl = $('.dTable');
var settings={};
settings.buttons = [
{
extend:'pdfHtml5',
text:'Export PDF',
orientation:'landscape',
customize : function(doc){
var colCount = new Array();
$(tbl).find('tbody tr:first-child td').each(function(){
if($(this).attr('colspan')){
for(var i=1;i<=$(this).attr('colspan');$i++){
colCount.push('*');
}
}else{ colCount.push('*'); }
});
doc.content[1].table.widths = colCount;
}
}
];
$('.dTable').dataTable(settings);
Note that if you just copy the customize portion of the code above, you must replace tbl by "#myTable" or something similar.
See also the related GitHub ticket, including another implementation (which may or may not be out-of-date).
I use this and works for me. Good luck.
{
extend: 'pdfHtml5',
charset: 'utf-8',
title:tableOptions.title.toUpperCase(),
orientation: 'landscape',
text: '<i class="fas fa-file-pdf"></i> PDF',
exportOptions: {
columns: [1,2,3,4]
},
customize: function(doc) {
doc.content.splice( 0, 0, {
margin: [ 7, 0, 0, -45 ],
width: 85,
height: 55,
alignment: 'right',
image: 'base64...'
});
let downloadDate=`${moment(new Date(), 'YYYY-MM-DD HH:mm:ss').format('DD-MM-YYYY')}`;
let downloadTime=`${moment(new Date(), 'YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss')}`.slice(11,16);
doc.content.splice( 2, 0, {
alignment: 'left',
fontSize:12,
margin: [ 0, 0, -10, 20 ],
color:"#003d66",
text:`${downloadDate} / ${downloadTime} Hrs`
});
doc.defaultStyle.alignment = 'center';
doc.defaultStyle.color = '#666';
doc.styles.title.color="#00c4cc";
doc.styles.title.alignment="left";
doc.styles.title.fontSize=14;
if(doc.content[3].table.body[0]){
let columns=doc.content[3].table.body[0].length;
let widths=[];
for (let i = 0; i < columns; i++) {
widths.push(`${99/columns}%`)
}
doc.content[3].table.widths = widths;
}
doc.styles.tableHeader.fontSize=12;
doc.styles.tableHeader.fillColor="#003d66";
doc.styles.tableBodyOdd.margin =[5, 5, 5, 5];
doc.styles.tableBodyEven.margin = [5, 5, 5, 5];
}
},

Deleting a view from a ScrollView

Developing in Titanium Mobile.
I need to remove a view from a scrollView when a delete button is clicked. I have a custom event firing when my button is clicked, which the scrollView listens for. My question is, how do I reference the view that needs to be deleted? These views are added to the scrollView dynamically, and there is no unique information about the view. I tried passing the view itself when firing the custom event, but this does not work. How do I tell the scrollView which view to delete?
When you have a delete button inside the view - that's a piece of cake :) Just get its' parent and delete it - scrollView.remove(e.source.parent);
Here I created a demo page:
var scrollView = Titanium.UI.createScrollView({
contentWidth: 'auto',
contentHeight: 'auto',
top: 0,
showVerticalScrollIndicator: true,
showHorizontalScrollIndicator: true,
layout: 'vertical'
});
var colors = ['red', 'green', 'blue', 'orange', 'purple', 'yellow'];
for (var i = 0; i < 6; i++) {
var view = Ti.UI.createView({
backgroundColor: colors[i],
borderRadius: 10,
width: 300,
height: 200,
top: 10,
id: i
});
scrollView.add(view);
var deleteButton = Ti.UI.createButton({
borderRadius: 3,
style: Ti.UI.iPhone.SystemButtonStyle.PLAIN,
backgroundGradient: {
type: 'linear',
colors: [ '#c7c7c7', '#686868' ],
startPoint: { x: 0, y: 0 },
endPoint: { x: 0, y: 30 },
backFillStart: false
},
title: 'Delete view ' + i,
font: { fontSize: 12, fontWeight: 'bold' },
color: '#fff',
width: 120,
height: 30
});
view.add(deleteButton);
deleteButton.addEventListener('click', function(e) {
Ti.API.info(e.source.id); // use this ID
scrollView.remove(e.source.parent);
});
}
Ti.UI.currentWindow.add(scrollView);

Categories