Setting PageSize of Google Slides with Javascript API - javascript

I am creating google slides with the help of javascript API. I need to set up the page size But its not working. Below is my code .
var size = {
width:{
magnitude: 612,
unit: "PT"
},
height: {
magnitude: 792,
unit: 'PT'
}};
gapi.client.slides.presentations.create({
title: "Some title",
pageSize: size
}).then((response) => {
var presentationId = response.result.presentationId;
})

Use this Method: presentations.create
Creates a new presentation using the title given in the request. Other
fields in the request are ignored. Returns the created presentation.
Here is the request body:
{
"presentationId": string,
"pageSize": {
object(Size)
},
"slides": [
{
object(Page)
}
],
"title": string,
"masters": [
{
object(Page)
}
],
"layouts": [
{
object(Page)
}
],
"locale": string,
"revisionId": string,
"notesMaster": {
object(Page)
},
}
To check the description of pageSize, you can refer to the fields table. It was specified as the size of pages in the presentation.
Also, you may want to check this javascript Browser Quickstart to help you further.

Related

How to make api function dynamically in Reactjs

I am working with Reactjs/Nextjs and i am fetching data from "comments.js"
in this file right now data is statically displaying,Here is my current data
export const books = [
{
id: 1,
title: "Things fall apart",
},
{
id: 2,
title: "Fairy tails",
},
...
]
I want to know that how can i convert this "static" data to "dynamic"(from server or database/mysql) ?

JSPDF-INVOICE-TEMPLATE Create a pdf with N pages fetching data to a internal orders route

Hi to every one reading this. I am struggling with a PDF.js problem. I am using this library: https://github.com/edisonneza/jspdf-invoice-template to render a PDF with data that I am getting from an internal axios route that returns orders. This orders are listed with a checkbox, for the orders checked I generate a new array with the objects of the different orders checked.
Up to this I was doing fine, but the next thing I need is to generate this PDFs. I got it to work rendering one single pdf with the data order, but i would like to generete a PDF with (N) numbers of pages, using the checked orders to print with a button.
Below are the blocks of the code that i wrote.
printAllbtn.addEventListener('click',function(){
try {
if(ordersSelectedToPrint.length \> 1){
console.log(ordersSelectedToPrint);
for (let orderPrint of ordersSelectedToPrint) {
let pdfObject = jsPDFInvoiceTemplate.default(props);
console.log( 'object created' + pdfObject + orderPrint)
var props = {
outputType: jsPDFInvoiceTemplate.OutputType.Save,
returnJsPDFDocObject: true,
fileName: "remito",
orientationLandscape: false,
compress: true,
business: {
name: "Isidorito",
address: "San Pedro, Buenos",
phone: "(3329) 069 11 11 111",
email: "contacto#isidorito.com",
website: "www.isidorito.com.ar/nosotros",
},
contact: {
label: "Remito dirigito a:",
name: `${orderPrint.cliente.dueño}`,
address:`${orderPrint.cliente.direccion}`,
phone: `${orderPrint.cliente.telefono1}`,
email: `${orderPrint.cliente.correo}`,
},
invoice: {
label: "Pedido #",
num: 19,
invDate: `${orderPrint.createdAt}`,
invGenDate: `28/10/2022`,
headerBorder: false,
tableBodyBorder: false,
header: [
{
title: "#",
style: {
width: 10
}
},
{
title: "Productos descripción",
style: {
width: 70
}
},
{
title: "Cantidad ",
style: {
width:20
}
},
{ title: "Por Unidad",
style:{width:30}},
// { title: "Cantidad"},
{ title: "Por tot",
style:{
width:30
}},
{ title: "Total",
style:{
width:30
}}
],
table: Array.from(orderPrint.productosPedidosNombre).forEach(function(productoIm, index){[
index + 1,
`${productoIm.nombre} - ${productoIm.marca} - ${productoIm.presentacion}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
]}),
invDescLabel: "Cliente:",
invDesc: `${orderPrint.cliente.nombreLocal}`,
},
footer: {
text: "Este remito generado digitalmente es valido para el pedido realizado",
},
pageEnable: true,
pageLabel: "Page ",
};
} } } catch (error) { console.log(error); }
});
The first note is that "orderPrint.productosPedidosNombre" is an array of products of the order. In the example from the documentation its represented in this way.
table: Array.from(Array(10), (item, index)=>([
index + 1,
"There are many variations ",
"Lorem Ipsum is simply dummy text dummy text ",
200.5,
4.5,
"m2",
400.5
])),
And the way I generate the PDF is:
let pdfObject = jsPDFInvoiceTemplate.default(props);
First I would like to know if it is possible the loops and iteration to generate this type of single file with N number of order pages, and each page with different data. It's possible with this library.
Thanks you. It's my second question I've asked in StackOverflow, so I welcome the feedback on the how to ask in stack overflow.

Google sheets api append multiple values with formatting

I have an array of values that i want to insert to a google sheet via API, i need to give color formatting to certain cells depending on the content of the cell like the image below:
I get to insert the values using append but i have no found any example on formatting append requests.
let values = [["Department", "Product", "Cost", "Status"],
["Clothes", "Socks", "12" "On Stock"],
["Clothes", "Hat", "15.99", "Out of stock"],
["Fresh","Apple", "18", "Pending"],
["Fresh", "Bannana", "17" "Out of stock"],
["Kitchen", "Spoon", "0.99", "Out of stock"]]
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "Products",
valueInputOption: "USER_ENTERED",
resource: {
values: values,
},
});
What is the best approach to achieve this? batchUpdate? how would it be implemented with batchUpdate?
In your situation, how about using ConditionalFormatRule? When ConditionalFormatRule is used, when a script is run one time, the colors are automatically reflected. In order to achieve this, a sample script is as follows.
Sample script:
const googleSheets = google.sheets({ version: "v4", auth }); // Please use your authorization script.
const spreadsheetId = "###"; // Please set Spreadsheet ID.
const sheetId = "###"; // Please set Sheet ID.
// These values and colors are from your showing image.
const colorObj = [
{ value: "On Stock", rgb: [182, 215, 168] }, // #b6d7a8
{ value: "Out of stock", rgb: [244, 204, 204] }, // #f4cccc
{ value: "Pending", rgb: [252, 229, 205] }, // #fce5cd
];
const requests = colorObj.map(({ value, rgb }, i) => ({
addConditionalFormatRule: {
index: 0,
rule: {
booleanRule: {
condition: {
values: [
{
userEnteredValue: value,
},
],
type: "TEXT_EQ",
},
format: {
backgroundColor: {
red: rgb[0] / 255,
green: rgb[1] / 255,
blue: rgb[2] / 255,
},
},
},
ranges: [
{
sheetId,
startColumnIndex: 3,
endColumnIndex: 4,
startRowIndex: 1,
},
],
},
},
}));
const res = await googleSheets.spreadsheets.batchUpdate({
spreadsheetId,
resource: { requests },
});
In this modification, this ConditionalFormatRule is reflected in the range of "D2:D".
Note:
I guessed that from your showing script, you might be using googleapis for Node.js. So, this sample scirpt is for googleapis for Node.js.
References:
Method: spreadsheets.batchUpdate
AddConditionalFormatRuleRequest

ArcGIS API for Javascript: FeatureLayerCollection doesn't displaye all the features

This image shows the result of my implementation.
The problem here is the feaure layer displayed in the map shows only one of the features passed in the code.
How have I done it?
Create a feature layer using new FeatureLayer(featureCollectionObject, options?).
Create a Query and QueryTask to request features from the arcgi server.
var selectQuery: Query = new Query();
selectQuery.returnGeometry = true;
selectQuery.where = "1=1";
selectQuery.outFields = ["NAME", "X", "Y"];
var queryTask_XZQH = new QueryTask(FL_XZQH_URL);
queryTask_XZQH.execute(selectQuery);
Define a event handler for "complete" of queryTask.
function onQueryTask_XZQHComplete(evt: object) {
console.log(evt.featureSet.geometryType);
//console.log(evt.featureSet);
FL_XZQH = new FeatureLayer({
featureSet: evt.featureSet,
layerDefinition: {
geometryType: "esriGeometryPolygon",
className: "xzqh",
objectIdField:"OBJECTID",
fields: [
{
name: "OBJECTID ",
type:"esriFieldTypeOID",
alias:"OBJECTID"
},
{
name: "ID ",
type:"esriFieldTypeInteger ",
alias:"Id"
},
{
name: "Name",
type: "esriFieldTypeString",
length: 50,
alias: "行政区划名称"
},
{
name: "X",
type: "esriFieldTypeDouble",
alias: "经度"
},
{
name: "Y",
type: "esriFieldTypeDouble",
alias: "纬度"
}
]
}
});
map.addLayer(FL_XZQH);
}
The result of QueryTask is fine, and the count of the features is 18.
However, when I use map.addLayer, the map just displays one feature.
The feature layer does not have a valid object ID. Make two changes to fix it:
Change this:
selectQuery.outFields = ["NAME", "X", "Y"];
To this (i.e. include the object ID in your query):
selectQuery.outFields = ["OBJECTID", "NAME", "X", "Y"];
Change this:
{
name: "OBJECTID ",
type:"esriFieldTypeOID",
alias:"OBJECTID"
},
To this (i.e. remove the space at the end of the field name):
{
name: "OBJECTID",
type:"esriFieldTypeOID",
alias:"OBJECTID"
},
Note: this will only work if the feature service actually has a field called OBJECTID.

Amazon S3 JS SDK putBucketLifecycleConfiguration giving XML Schema Error

I'm using the AWS javascript SDK on node. I'm trying to set my bucket life cycle configuration but somewhere my structure is not correct and I can't see where.
I'm basing my code on : http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketLifecycleConfiguration-property
Version : aws-sdk#2.4.9
When I execute the code I get :
The XML you provided was not well-formed or did not validate against
our published schema
Any idea what is wrong with it?
let parms = {
Bucket: 'mybucketname',
LifecycleConfiguration: {
Rules: [
{
Prefix: 'uploads', /* required */
Status: 'Enabled', /* required */
AbortIncompleteMultipartUpload: {
DaysAfterInitiation: 0
},
Expiration: {
Date: Date.UTC(1970, 1),
Days: 1,
ExpiredObjectDeleteMarker: true
},
ID: '1',
NoncurrentVersionExpiration: {
NoncurrentDays: 0
},
NoncurrentVersionTransitions: [
{
NoncurrentDays: 0,
StorageClass: 'STANDARD_IA'
},
/* more items */
],
Transitions: [
{
Date: Date.UTC(1970, 1),
Days: 0,
StorageClass: 'STANDARD_IA'
},
/* more items */
]
}
]
}
};
return this.s3.putBucketLifecycleConfiguration(parms).promise();
Got it working for anyone interested: https://github.com/aws/aws-sdk-js/issues/1071

Categories