How to get a img file in LocalFolder and display the image - winrt-xaml

I used this code to get the image file in the localFolder and I encountered the below problem.
The problem is at
BitmapImage src is null even there is data in randomstream
any idea how to overcome this problem? Why BitmapImage is null??
string strFilenm = "SDraw-" + prodId.ToString() + ".png";
var folder_path = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Img");
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folder_path);
StorageFile storagefile = await folder.GetFileAsync(strFilenm);
StorageFile jpgFile = await folder.GetFileAsync(strFilenm);
IRandomAccessStream randomStream = await jpgFile.OpenAsync(FileAccessMode.Read);
randomStream.Seek(0);
BitmapImage src = new BitmapImage();
await src.SetSourceAsync(randomStream);
Image1.Source = src;

I'm not expert but i think to access file from App LocalFolder you should use something like this:
"ms-appx://LocalFolderName/ImageName.extension"

try writing the instance " BitmapImage src = new BitmapImage(); " at class level.
One reason can be that the code might be trying to access a file that does'nt exist.

Related

How to gzip a directory/folder using pako module in Nodejs?

I am trying to gzip my folder with the help of Pako library. I couldn't found any related content about it. Can someone explain me how to use pako to gzip directory. I am using it in my lambda function along with EFS.
let bundle = fs.readdirSync(tempDir);
let zippedFile = pako.gzip(bundle);
My folder location looks like this data/temp/
Error
TypeError: strm.input.subarray is not a function
You can use fs.readdirSync() to list files in the directory, then check the stat of each file before compressing it using fs.lstatSync(). I have tested this locally on my mac.
Then you can write the compressed file to your file system.
const fs = require('fs');
const pako = require('pako');
let files = fs.readdirSync('/tmp/');
let fileContent = '';
files.forEach(file => {
let path = '/tmp/' + file;
let stats = fs.lstatSync(path);
if (stats.isFile()) {
let data = fs.readFileSync(path);
fileContent += data;
}
});
let zippedFile = pako.gzip(fileContent);
const stream = fs.createWriteStream('/tmp/dir.gz');
stream.write(zippedFile);
stream.end();

error by using in PDFTron:' NetworkError(`Unsupported protocol ${this._url.protocol}`'

I trying to convert pdf file to pdfa3 file by using PDFTron.
I added current url_path.
the my code below:
var input_url = './utils/';
var input_filename = 'test.pdf';
var output_filename = 'test_pdfa.pdf';
var convert = true;
var pwd = '';
var exceptions;
var max_ref_objs = 10;
var url_input = input_url + input_filename;
console.log('Converting input document: ' + input_filename);
var pdfa = await PDFNet.PDFACompliance.createFromUrl(true, url_input, '', PDFNet.PDFACompliance.Conformance.e_Level2B, exceptions, max_ref_objs);
get error:
'NetworkError(Unsupported protocol ${this._url.protocol})',
Does anyone know what the problem is,
And why doesn't it recognize the location?
I changed the code to :
here.
Now it's working!!

pdfmake does not include fonts / text in node.js

I have a problem with pdfmake. I would like to generate a PDF on a node.js server. I would like to load data from a database and draw a nice table and simply save it to a folder.
var pdfMakePrinter = require('pdfmake/src/printer');
...
var fonts = {
Roboto: {
normal: './fonts/Roboto-Regular.ttf',
bold: './fonts/Roboto-Medium.ttf',
italics: './fonts/Roboto-Italic.ttf',
bolditalics: './fonts/Roboto-Italic.ttf'
}
};
var PdfPrinter = require('pdfmake/src/printer');
var printer = new PdfPrinter(fonts);
var docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};
var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream('pdf/basics.pdf')).on('finish', function () {
res.send(true);
});
The generated PDF is empty. If I add an image, it is inserted well. But no font is included. The path of the fonts (which are given in the sample) is right.
Has anyone an idea, why no fonts are embedded and how this can be done in node.js? There are no valid samples on the pdfmake documentation.
After some debugging, I found out, that the app crashes in fontWrapper.js in this funktion:
FontWrapper.prototype.getFont = function(index){
if(!this.pdfFonts[index]){
var pseudoName = this.name + index;
if(this.postscriptName){
delete this.pdfkitDoc._fontFamilies[this.postscriptName];
}
this.pdfFonts[index] = this.pdfkitDoc.font(this.path, pseudoName)._font; <-- Crash
if(!this.postscriptName){
this.postscriptName = this.pdfFonts[index].name;
}
}
return this.pdfFonts[index];
};
Does anyone have an idea?
TTF is not issue in your case you can use any font to generate a PDF on a node.js server.
inside pdfmake
TTFFont.open = function(filename, name) {
var contents;
contents = fs.readFileSync(filename);
return new TTFFont(contents, name);
};
on contents = fs.readFileSync(filename); this line
fs can't read file on given path
as per This conversation you have to put your fonts at root folder,
but problem is when we create font object we gives root path and this path is not working for fs.readFileSync this line so you have to exact path of font
add process.cwd().split('.meteor')[0] befor font path
I have created example for same functionality please this below link
https://github.com/daupawar/MeteorAsyncPdfmake

nodejs written file is empty

i have a small problem, when i try to copy one file from my tmp dir to my ftp dir the writen file is empty. I have no error, i don't understand what i'm doing wrong
var ftpPath = "/var/www/ftp/",
zipPath = "/var/www/tmp/",
file = "test";
fs.createReadStream(zipPath + file).pipe(fs.createWriteStream(ftpPath + file));
My test file contain loremipsum sample.
If you have any solution, i take it, this is the only line that bug in my app :(
First, make sure that the file /var/www/tmp/test exists, is a file, and has the right permissions for the user you start the script with.
Second, make sure that /var/www/ftp/ has writing permissions.
Then the following code should work :
var readerStream = fs.createReadStream('/var/www/tmp/test');
var writerStream = fs.createWriteStream('/var/www/ftp/test');
readerStream.pipe(writerStream);
Edit :
try debugging using this snippet :
var data;
var readerStream = fs.createReadStream('/var/www/tmp/test');
readerStream.on('data', function(data) {
data += data;
});
readerStream.on('end', function() {
console.log(data);
});

count images in local folder WinRT

I am new in WinRT ,
Is it possible to count number of images in Assest Folder . So that we can do few operation over it .
Presently i am making a small app.
Thanks in advance
try,
var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
var files = await folder.GetFilesAsync();
and get the files count as
var filesCount = files.Count;
and you can get the files count of specific extension as
var pngFileCount = files.Where(file => file.FileType == ".png").Select(f => f).ToList().Count;
Hope this will helps you :)
Here you go.
var folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
var options = new QueryOptions { FileTypeFilter = { ".png", ".jpg" } };
var query = folder.CreateFileQueryWithOptions(options);
var files = await query.GetFilesAsync();
foreach (var file in files)
{
// TODO
}
I want to point out that this works in Windows but not Windows Phone. Not yet.
Best is luck.

Resources