ZPL label format output resolution(DPI Support)
Title | DPI support in label |
Author(s) | @naveenkumar |
Team (POD) | Support-POD |
Reviewer(s) | @shikar-sharma2 @avs |
Requirement :
DPI (Dots Per Inch) Support in Label:By default, the output for the ZPL format is set to 203 DPI. need to make the DPI setting dynamic.
Approach :
changes in cloud function (pdfToZpl)+ code free label
Consignment-label changes :
In organisationconfig.json
, we add the key “zplFormatDPI"
corresponding to the organisationId.
in pdfToZplDataStream.js
→ getZplApiResult
() , we add const dpi = orgConfig[orgId].zplFormatDPI || 203;
by default we hardcode to 203, if “zplFormatDPI” key not present w.r.t. organisationId & we pass dpi to
cloud Function request Body.
body: {
pdfFile: pdfbase64,
organisationId: orgId,
dpi: dpi
}
Present Cloud Function :
def lambda_handler(event, context):
# requestBody = json.loads(event.get('body'))
# pdfFile = requestBody['pdfFile']
pdfFile = event['pdfFile']
if not pdfFile:
return {
'statusCode': 200,
'body': json.dumps({"reason": "data not present"})
}
try:
pdfFileStr = base64.b64decode(pdfFile)
pagesZpl = GRF.from_pdf(pdfFileStr, 'DEMO')
zplString = ""
for grf in pagesZpl:
grf.optimise_barcodes()
zplString += grf.to_zpl()
encodedZplString = base64.b64encode(zplFormatStr.encode())
decodedZplString = encodedZplString.decode('ascii')
return dict(
statusCode=200,
body=json.dumps({"data": decodedZplString}),
isBase64Encoded=True
)
except Exception as e:
print(e)
return {
'statusCode': 400,
'body': json.dumps({"reason": "unable to generate zpl file"})
}
changes in Cloud Function :
Taking dpi = event['dpi']
at line 12 in cloud function , We add “dpi”,
GRF.from_pdf(pdfFileStr, 'DEMO', dpi )