Pdfnet xamarin.ios doesn't print - xamarin.ios

I'm working with Pdftron PdfNet libraries for Xamarin.iOS and introducing the print function:
if (UIPrintInteractionController.PrintingAvailable)
{
var printerController = UIPrintInteractionController.SharedPrintController;
var printInfo = UIPrintInfo.PrintInfo;
printInfo.Duplex = UIPrintInfoDuplex.LongEdge;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Print";
printerController.PrintInfo = printInfo;
printerController.ShowsPageRange = true;
var formatter = this.mPdfViewCtrl.ViewPrintFormatter;
printerController.PrintFormatter = formatter;
printerController.Present(true, (handler, completed, err) =>
{
if (!completed && err != null)
{
Console.WriteLine("Printer Error");
}
});
}
Where mPdfViewCtrl is PDFViewCtrl type.
Now the problem is that the pages are printed all whites and no errors are triggered.
I think that the problem is the PDFViewCtrl ViewPrinterFormatter that has not the right data.
Has anyone had this promblem?

This will be in the next release of PDFTron for Xamarin.iOS. Are you evaluating PDFTron, or working on a new release?

Related

How to use export excel file with excel 1.1.5 package

I'm currently using this package Excel 1.1.5 ... It currently has a method called save but it just returns a List integers...and I don't know where to go from here..
List<int>? potato = excel.save(fileName: 'namePotato');
Hoping you guys can help!
Thanks!
Found the answer, you can use dart:io and I've also used Permissions_handler
Future exportReport() async {
var excel = Excel.createExcel();
DateTime _now = DateTime.now();
String _name = DateFormat('yyyy-MM-dd').format(_now);
String _fileName = 'surname-' + _name;
List<int>? potato = excel.save(fileName: _name);
PermissionStatus status = await Permission.storage.request();
if (status == PermissionStatus.granted) {
await File('/storage/emulated/0/Download/$_fileName.xlsx').writeAsBytes(potato!, flush: true).then((value) {
log('saved');
});
} else if (status == PermissionStatus.denied) {
log('Denied. Show a dialog with a reason and again ask for the permission.');
} else if (status == PermissionStatus.permanentlyDenied) {
log('Take the user to the settings page.');
}
return null;
}

Cast Application Framework receiver app not working on external cast device 2nd Geneation

I'm trying to develop CAF v3 receiver app and it's working with in-built and setup boxes cast devices but not working on external cast devices.
External cast devices NC2-A65 throws PIPELINE_INITIALIZATION_ERROR or VIDEO_ERROR with shaka error code 3016
After debugging, observation is drm License Url doesn't get called when useLegacyDashSupport is true
Any help is appreciated
Here is the code,
<script>
const context = cast.framework.CastReceiverContext.getInstance();
context.setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
const options = new cast.framework.CastReceiverOptions();
const castDebugLogger = cast.debug.CastDebugLogger.getInstance();
const playerManager = context.getPlayerManager();
const playbackConfig = (Object.assign(new cast.framework.PlaybackConfig(), playerManager.getPlaybackConfig()));
options.maxInactivity = 3600;
options.supportedCommands = cast.framework.messages.Command.ALL_BASIC_MEDIA;
castDebugLogger.setEnabled(true);
// Show debug overlay
castDebugLogger.showDebugLogs(true);
let useLegacyDashSupport = false;
if (context.canDisplayType('video/mp4; codecs="avc1.640028"; width=3840; height=2160')) {
// The device and display can both do 4k. Assume a 4k limit.
castDebugLogger.info("Hardware Resolution: ", '3840x2160');;
options.touchScreenOptimizedApp = true;
} else {
// Chromecast has always been able to do 1080p. Assume a 1080p limit.
castDebugLogger.info("Hardware Resolution: ", '1920x1080');
useLegacyDashSupport = true;
}
options.useLegacyDashSupport = useLegacyDashSupport;
context.loadPlayerLibraries(useLegacyDashSupport);
context.addEventListener(cast.framework.system.EventType.ERROR, event => {
castDebugLogger.info('Context Error - ', JSON.stringify(event));
});
playerManager.addEventListener(cast.framework.events.EventType.ERROR, event => {
castDebugLogger.info('Error - ', "ERROR event: " + JSON.stringify(event));
});
playerManager.addEventListener(cast.framework.events.EventType.MEDIA_STATUS, (event) => {
castDebugLogger.info('Player State - ', event.mediaStatus.playerState);
});
// Intercept the LOAD request to be able to read in a contentId and get data.
playerManager.setMessageInterceptor(cast.framework.messages.MessageType.LOAD, loadRequestData => {
castDebugLogger.info('LoadRequest Data - ', JSON.stringify(loadRequestData));
const error = new cast.framework.messages.ErrorData(cast.framework.messages.ErrorType.LOAD_CANCELLED);
if (!loadRequestData.media) {
error.reason = cast.framework.messages.ErrorReason.INVALID_PARAM;
return error;
}
if (!loadRequestData.media.contentId) {
error.reason = cast.framework.messages.ErrorReason.INVALID_PARAM;
return error;
}
loadRequestData.autoplay = true;
let url = loadRequestData.media.contentId;
castDebugLogger.info('Content Id - ', url);
const ext = url.substring(url.lastIndexOf('.'), url.length);
loadRequestData.media.contentType = 'video/mp4';
if (ext.includes('mpd')) {
loadRequestData.media.contentType = 'application/dash+xml';
} else if (ext.includes('m3u8')) {
loadRequestData.media.contentType = 'application/vnd.apple.mpegurl';
// TODO: Create option to set hlsSegmentFormat option.
loadRequestData.media.hlsSegmentFormat = cast.framework.messages.HlsSegmentFormat.TS;
} else if (ext.includes('ism')) {
loadRequestData.media.contentType = 'application/vnd.ms-sstr+xml';
}
if (loadRequestData.media.customData && loadRequestData.media.customData.drm) {
playerManager.setMediaPlaybackInfoHandler((loadRequest, playbackConfigData) => {
playbackConfigData.licenseUrl = loadRequest.media.customData.drm.widevine.url;
playbackConfigData.protectionSystem = cast.framework.ContentProtection.WIDEVINE;
castDebugLogger.info('PlaybackConfig Data - ', JSON.stringify(playbackConfigData));
return playbackConfigData;
});
}
return loadRequestData;
});
options.playbackConfig = playbackConfig;
context.start(options);
</script>

NetSuite SuiteScript 2.0 disable field based on checkbox

I apologize if this is a dumb question, but I am new to NetSuite, and have noticed that their documentation is absolutely ridiculously horrifyingly and atrociously disgusting. All humor and bitterness aside though, I can't find the details that should exists in SuiteAnswers. I can find the type Field or Record, but it doesn't show me the options available for those types. It just shows what methods to call to return a field or record.
So I have it on the fieldChanged event as the training specifies, and below is what I have.
function fieldChanged(context) {
debugger;
var customer = context.currentRecord
if (context.fieldId == 'custentity_apply_coupon') {
var field = record.getField("custentity_apply_coupon");
if (record.getValue("custentity_apply_coupon") == true) {
reord.getField("custentity_coupon_code").isDisabled = false;
}
else{
reord.getField("custentity_coupon_code").isDisabled = true;
}
field.isDisabled = false;
}
}
Turns out that, and I never found this in the documentation, that once you get the field from currentRecord.currentRecord, you can set it to disabled via field.isDisabled. Took me forever to find out that isDisabled was a property of field, and then took a complete guess to see that isDisabled was a get/set call for ClientSide Scripts. Below is the code that ended up working.
function fieldChanged(scriptContext) {
var customer = scriptContext.currentRecord;
if(scriptContext.fieldId == "custentity_sdr_apply_coupon"){
debugger;
var field = customer.getField("custentity_sdr_coupon_code");
field.isDisabled = !customer.getValue(scriptContext.fieldId);
if(field.isDisabled){
customer.setValue(field.id, "");
}
}
}
I hope this will help.
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var approvalChkBox = currentRecord.getValue({
fieldId: 'supervisorapproval'
});
var memoField = currentRecord.getField("memo");
if (approvalChkBox)
memoField.isDisabled = true;
else
memoField.isDisabled = false;
}
Thats a good question, this is the simplest solution you are looking for. use getValue method and isDisabled to meet this requirement. the code is self explanatory. Good Luck.
function fieldChanged(context) {
var record = context.currentRecord;
var fieldname = context.fieldId;
var changedValue = record.getValue(fieldname); //getValue method is the key here
var couponid = record.getField('custentity_kld_coupon_code');
if (fieldname == 'custentity_kld_apply_coupon' && changedValue == true) {
couponid.isDisabled = false; //isDisabled helps you to enable or disable a field
} else {
couponid.isDisabled = true;
}
}
Totally agree. I think the SuiteScript 2.0 Student Guide could've been more helpful if they included a preview of their codes along the way.
For anyone else who is still following along, this code below worked for me. Thanks for everyone else that contributed in this post. Used your codes to create this too. I also included some other codes from the previous exercises (i.e. displaying a message when entering 'x' into the coupon code).
/**
* #NScriptType ClientScript
* #NApiVersion 2.0
*/
define([],
function() {
function fieldChanged (context) {
var customer = context.currentRecord;
if(context.fieldId = 'custentity_sdr_apply_coupon') {
var check = customer.getValue('custentity_sdr_apply_coupon');
var code = customer.getField('custentity_sdr_coupon_code');
if (check == true){
code.isDisabled = false;
} else {
code.isDisabled = true;
}
}
}
function saveRecord(context) {
var customer = context.currentRecord;
var empCode = customer.getValue('custentity_sdr_coupon_code')
if(empCode == 'x') {
alert('Invalid code value. Please try again');
return false;
}
return true;
}
return {
fieldChanged: fieldChanged,
saveRecord: saveRecord,
};
});
var objRec_Curr = scriptContext.currentRecord;
var TransferType = objRec_Curr.getCurrentSublistValue({sublistId:'xxxxxxxxxx', fieldId : 'xxxxxxxxxxxx'});
if(TransferType == 'ABC')
eval("nlapiDisableLineItemField('custpage_sublist_out', 'custpage_out_transfer_location', true)");
else
eval("nlapiDisableLineItemField('custpage_sublist_out', 'custpage_out_transfer_location', false)");

NodeJS Error Encapsulation

I am currently trying to handle exceptions and errors in a NodeJS app which will be used for critical information. I need a clean error management !
I've been wondering if there is something similar to Java Exceptions encapsulation.
I'm explaning.
In Java you can do something like that :
try {
// something that throws Exception
} catch (Throwable t) {
throw new Exception("My message", t);
}
That allows you to decide when to log your exception and you get the whole stack trace and call path !
I would like to know if there is a way to do the same in NodeJS because logging at every step seems not to be the right way of doing things.
Thank you.
You should look at this module :
https://www.npmjs.com/package/verror
Joyent quote it on his error management best pratices : https://www.joyent.com/developers/node/design/errors
At Joyent, we use the verror module to wrap errors since it's
syntactically concise. As of this writing, it doesn't quite do all of
this yet, but it will be extended to do so.
It allow you to get details on error message. And tracking the step of the error.
And also hide details to the client with wrapped error : WError() who returns only the last error message.
I answer my own question to explain what i finaly did to have the wanted encapsulation.
I used https://www.npmjs.com/package/verror as Sachacr suggested.
Then I extended it that way :
my_error.js :
var VError = require('verror');
var _ = require('lodash');
function MyError() {
var args = [];
var httpErrorCode;
var cause;
if (arguments.length > 0) {
var lastArgumentIndex = [arguments.length];
cause = manageCause(lastArgumentIndex, arguments);
httpErrorCode = manageHttpCode(lastArgumentIndex, arguments);
for (var i = 0; i < lastArgumentIndex; i++) {
args[i] = arguments[i];
}
}
this.__proto__.__proto__.constructor.apply(this, args);
if (cause) {
if (this.stack) {
this.stack += '\n' + cause.stack;
} else {
this.stack = cause.stack;
}
}
this.httpErrorCode = httpErrorCode;
}
MyError.prototype.__proto__ = VError.prototype;
function manageCause(lastArgumentIndex, arguments) {
if (lastArgumentIndex[0] > 0
&& arguments[lastArgumentIndex[0] - 1] instanceof Error) {
lastArgumentIndex[0]--;
return arguments[lastArgumentIndex[0]];
}
}
function manageHttpCode(lastArgumentIndex, arguments) {
if (lastArgumentIndex[0] > 0
&& _.isNumber(arguments[lastArgumentIndex[0] - 1])) {
lastArgumentIndex[0]--;
return arguments[lastArgumentIndex[0]];
}
}
module.exports = MyError;
It allows me to use it easily in my code :
var MyError = require('./my_error.js');
function withErrors() {
try {
// something with errors
} catch (err) {
// This is the same pattern as VError
return new MyError("My message", err, 401);
}
}
function somethingToDo(req, res) {
var result = withErrors();
if (result instanceof MyError) {
logger.warn(result);
res.status(result.httpErrorCode).send(result.message).end();
return
}
}
That way, i hace a nice stack trace with call path and every line involved in error/exception.
Hope it will help people, cause i searched a looooong time :)
EDIT : I modified my MyError class to add HTTP Error codes and clean arguments management.
You should be able to do something like:
funtion exception(message, error) {
this.message = message;
this.stacktrace = error.stack;
}
try {
if(someData == false)
throw new exception("something went wrong!", new Error());
}
catch(ex) {
console.log(ex.message);
console.log(ex.stacktrace);
}
You can then throw your own custom exception instance containing whatever debugging info you need.
EDIT: added stack trace to exception object

Error when trying to setTitle on new DB

I'm working on an Archiving Application with this code in it:
var arcName:String = "Archives/" + aDBName + "-Backup-" + toDay + "-" + thisTime.slice(0,5);
var server:String = appDB.getServer();
var arcDB:NotesDatabase = appDB.createCopy(server, arcName);
arcDB.setTitle("This is a Test");
but it fails at the arcDB.setTitle - the new copy of the Database is created so there is no issue to that point.
This is from the IBM Knowledge base:
var db2:NotesDatabase = db.createCopy(null, "names2");
db2.setTitle("Copy of names");
I can't see the difference between these two pieces of code.
Am I missing something?
Usually when something doesn't work with XPages that relates to database or design objects the first thing I check is the Maximum Internet Name and password Access https://stackoverflow.com/a/23045860/1187943
Or change so I do the work using sessionAsSigner or sessionAsSignerWithFullAccess
If you don't care about the effectiveUser's access to the source database, their permissions to make a copy, and their access rights to create a NotesDatabase on the target Domino server, I'd absolutely second Fredrik's suggestion to use sessionAsSigner/WithFullAccess.
Additionally, I find it's best practice to use try/catches (helps with troubleshooting and errorHandling), object testing (.isOpen() when accessing a NotesDatabase), and returning an Object that can be read by the calling function.
Here's some example code that might help:
var copyNotesDatabase = function(dbName) {
var isSuccessful = true;
var responseMessage = "";
try {
//set appDB using dbName from function arguments
var appDB = session.getDatabase(session.getServerName(),dbName);
//var appDB = sessionAsSigner.getDatabase(session.getServerName(),"sourceDb.nsf");
//var appDB = sessionAsSignerWithFullAccess.getDatabase(session.getServerName(),"sourceDb.nsf");
if(appDB.isOpen()) {
var arcName:String = "Archives/" + aDBName + "-Backup-" + toDay + "-" + thisTime.slice(0,5);
var server:String = appDB.getServer();
//arcDB will be created based on appDB permissions, ie effectiveUser, or sessionAsSigner, etc.
var arcDB:NotesDatabase = appDB.createCopy(server, arcName);
if(arcDB.isOpen()) {
arcDB.setTitle("This is a Test");
responseMessage = "Successfully copied NotesDatabase!"
} else {
isSuccessful = false;
responseMessage = "Unable to open copied NotesDatabase.";
}
} else {
isSuccessful = false;
responseMessage = "Unable to open source NotesDatabase.";
}
} catch(e) {
print("Error from SSJS: " + e);
isSuccessful = false;
responseMessage = e;
}
return { status : isSuccessful, message : responseMessage };
}
With this function, you could do something like this:
function makeCopy(appName) {
var fObj = copyNotesDatabase(appName);
if(fObj.status) {
return "Successfully copied " + appName;
} else {
return fObj.message;
}
}
... at the very least, using a try/catch and returning your error will at least tell you why your current code isn't working. Hope this helps!

Resources