RE: How to use portrait as default orientation in PDF Suitelet ?
Hi everyone
I am stuck in a situation where when i try to print a PDF through suitelet script , it is printed in landscape orientation while i want it to be printed in portrait orientation , i use these values for width and height in body tag
<body width=”65mm” height=”45mm” >
Does anybody know how to resolve this ?
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define([‘N/ui/serverWidget’,’N/record’,’N/search’],
function (serverWidget,record,search) {
function onRequest(context) {
try {
log.debug(‘Context request’,context.request);
if(context.request.method==”GET”)
{
var form = serverWidget.createForm({
title : ‘Print Asset Labels’
});
//MULTISELECT
var selectAssets = form.addField({
id : ‘custpage_select_assets’,
type : serverWidget.FieldType.MULTISELECT,
label : ‘Select Assets to Print’,
source: ‘customrecord_fa_asset’
});
form.addSubmitButton({
label : ‘Submit’
});
context.response.writePage(form);
}
else
{
log.debug(‘POST context is ‘,context.request.parameters.custpage_select_assets);
var delimiter = /\u0005/;
assetIds=context.request.parameters.custpage_select_assets.split(delimiter);
assetIdsCount=assetIds.length;
xml='<?xml version=”1.0″?><!DOCTYPE pdf PUBLIC “-//big.faceless.org//report” “report-1.1.dtd”>’;
xml+='<pdf>’;
xml+='<head>’;
xml+='<style>’;
xml+=’body{‘;
xml+=’font-family: Arial, Helvetica, sans-serif;’;
xml+=’font-weight: 400;’;
xml+=’font-size: 10px;’;
xml+=’padding: 5px;’;
xml+=’}’;
xml+=’barcode{‘;
xml+=’padding-left:-4px;’;
xml+=’margin-left:-4px;’;
xml+=’margin-top:-3px;’;
xml+=’padding-top:-3px;’;
xml+=’}’;
xml+=’#assetNumberRow’;
xml+='{‘;
xml+=’padding-bottom: -6px;’;
xml+=’}’;
xml+=’#locationRow’;
xml+='{‘;
xml+=’padding-bottom: -5px;’;
xml+=’}’;
/* xml+=’.descTable’;
xml+='{‘;
xml+=’width:20%’;
xml+=’}’; */
xml+='</style>’;
xml+='</head>’;
xml+='<body width=”65mm” height=”45mm”>’;
for(id in assetIds)
{
asset=record.load({
type: ‘customrecord_fa_asset’,
id: assetIds[id],
isDynamic: true
});
assetName=asset.getValue(‘name’);
assetDescription=asset.getValue(‘altname’);
assetTagId=asset.getValue(‘custrecord_fa_ast_tag_id’);
departmentId=asset.getValue(‘custrecord_fa_ast_department’);
location=asset.getText(‘custrecord_asset_location’);
if(departmentId)
{
departmentsearch = search.lookupFields({
type: search.Type.DEPARTMENT,
id: departmentId,
columns: [‘namenohierarchy’]
});
department=departmentsearch.namenohierarchy;
}
else
{
department=””;
}
if(id>0 && id<assetIdsCount)
{
xml+='<pbr/>’;
}
xml+='<table>’;
xml+='<tr>’;
xml+='<td>TITLE</td>’;
xml+='</tr>’;
xml+='<tr>’;
xml+='<td><barcode codetype=”code128″ width=”90″ height=”15″ showtext=”false” value=”‘+assetName+'”/></td>’;
xml+='</tr>’;
xml+='<tr id=”assetNumberRow”>’;
xml+='<td>Asset No:’+assetName+'</td>’; //assetName
xml+='</tr>’;
xml+='<tr>’;
xml+='<td>CostC: ‘+department+'</td>’; //department
xml+='</tr>’;
xml+='</table>’;
xml+='<table width=”100%” style=”padding-top:2px;padding-bottom:2px”>’; //style=”padding-top:3px;padding-bottom:3px”
xml+='<tr>’;
xml+='<td width=”7%”>Desc: </td>’; //assetDescription
xml+='<td width=”93%”>’+assetDescription+'</td>’;
xml+='</tr>’;
xml+='</table>’;
xml+='<table width=”100%” >’;
xml+='<tr id=”locationRow”>’;
xml+='<td width=”25%” >Location: </td>’; //location
xml+='<td width=”75%” >’+location+'</td>’; //location
xml+='</tr>’;
xml+='<tr>’;
xml+='<td width=”25%”>Serial No: </td>’;
xml+='<td width=”75%”>’+assetTagId+'</td>’;
xml+='</tr>’;
xml+='</table>’;
}
xml+='</body>’;
xml+='</pdf>’;
context.response.renderPdf({ xmlString: xml });
}
}
catch (e) {
log.debug(‘Error in PDF Suitelet ‘, e);
}
}
return {
onRequest: onRequest
};
});
Hi,
Does swapping the 65 and the 45 make any difference?
Thanks,
Chris