Stream to File in WinRT - windows-8

How i can save a Stream to File in WinRT. Currently i am working on a Open Source library for creating PDF file in windows 8. I build the stream with pdf content, now my requirement is to save this stream to file. Can anyone please guide me to solve this issue.

I assume you're working with C#? One way to do it would be to read the stream content using DataReader and store it into a byte[] buffer. After that you can create the file like this:
var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("filename", Windows.Storage.CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);
Then again, if you already have to byte data for the pdf, you can skip making it a stream in the first place.
Hope this helped.

Related

How can i generate and download PDFs in Flask without saving them in my Webapp?

im trying to get a PDF with the ReportLab Module which works fine so far. My problem is that im saving the PDF with the .build()-method in my Webapps directory. What i want is that i can send the PDF for downloading without saving it before. That is somehow possible with the wkhtmltopdf module, but i dont want to use any other servers for this.
The process would be like: User presses a button 'download as pdf', a pdf is generated and instant returned as a download without saving it first.
Do you know if this is possible?
You want to create the PDF server side, return it to the client, without saving the PDF (for example, in S3)?
Yes, this is possible, you create the PDF in memory using
buffer = io.BytesIO()
myPDF = canvas.Canvas(buffer, pagesize=letter)
Then after creating your pdf you save it using
myPDF.save()
buffer.seek(0)
Then when you are ready to return the PDF as a reponse you can return it with:
response = HttpResponse(buffer, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="{}"'.format("myFile.pdf")
return response

Print a pdf downloaded through a webservice in Flutter / Dart

I'm working with Flutter.
I have a pdf document that I download from a webservice.
The http body response of this pdf sent by http package is typed as Uint8List.
Then, I would like to print it with printing which is working with pdf package.
So I need an instance of a PdfDocument from this class.
Is there a way that I can convert this Uint8List to pdf ? I tried some other dart packages, but they didn't answer my needs because I need to print pdf, not just view them.
I also looked with flutter_downloader in order to simply get pdf file without bothering myself with Uint8List, but it seems the package is not working at the moment: https://github.com/fluttercommunity/flutter_downloader/issues/132
Thank you very much for answering.
Use:
var data = await getThePdfData(); // obtain the Uint8List
Printing.sharePdf(bytes: data);

Render HTML or GSP as a PDF and save it on server

I have an html template which I need to render as a .PDF and then save that pdf file on server. I'm using "rendering" plugin of grails. I'm able to render file as PDF but I don't understand how to save it on server location and not on user's system. Can anybody please help me ?
The pdfRenderingService provided by the plugin allows you to call render and get back an OutputStream. Using that output stream you can write that to a file on your server. The documentation explains the basics of using the service.
Your code may look something like this:
new File("report.pdf").withOutputStream { outputStream ->
outputStream << pdfRenderingService.render(template: '/report/report', model: [serial: 12345])
}
Well, actually I changed my plugin. Got Wkhtmltopdf plugin of grails more helpful. you can find it here --
https://github.com/quorak/grails-wkhtmltopdf
Also instructions regarding using this plugin you can find on the same link or here --
[https://github.com/quorak/grails-wkhtmltopdf]
Using this you can get "bytes" which you can write to file system.

Load base data in Windows 8 app

I'm new to Windows 8 app development. I'm trying to port a old application I wrote in .NET. This application uses base data which is stored as four XML files that were added to the project as "Ressource" and deserializes them using the System.Xml.Serialization.XmlSerializer.
What would be the best way to ship data like this with an Windows 8 Store App? Just put them in the Assets Folder?
What is the best way to load and bind data like this in an Windows 8 app?
I'm grateful for everything you can give me, a direct answer, helpful links or an video on data loading and binding in Windows 8 ...
You can use resources in store app, here is the example :
public static string GetXmlContentsFromResource(Assembly asm, string dataName)
{
string contents = "";
Stream stream = asm.GetManifestResourceStream(asm.GetName().Name + "." + dataName);
using (StreamReader reader = new StreamReader(stream))
{
contents = reader.ReadToEnd();
}
return contents;
}
You should add XML files to solution and mark it as "Embedded Resource", and if you put XML files in subdirectory, for example if folder is named Data and xml file is Data1.xml then you should send parameter dataName to above method like this "data.Data1.xml".
For Data Binding best aproach is to deserialize that XML to object or list of objects that reflects XML contents.
What would be the best way to ship data like this with an Windows 8 Store App? Just put them in the Assets Folder?
Yes, put them in your assets folder. Be sure to set the build properties to "Content" + "Copy To Output". Once you have done this, you can access them from your app using the following url: ms-appx:///Assets/myxmlfile.xml
For example:
StorageFile xmlFile = await StorageFile.GetFileFromApplicationUriAsync
(new Uri("ms-appx:///Assets/myxmlfile.xml"));
The above gives you a file object that you can use to read your file. Obviously, since you are reading from the Assets folder, your file will be read-only.
What is the best way to load and bind data like this in an Windows 8 app?
As to data binding, that is probably a bit too large to cover in one answer. You might want to take a look at this Windows 8 Data Binding Sample.

How can I embed a swf object in a vb.net winform?

I have a swf object that I would like to embed using the COM Shockwave Flash Object control. I've searched around, but I've only found answers that involve using file or internet URLs. As I am using the One-Click publishing method, I would like to have a way to embed my flash object as a resource file into my application.
Thanks,
Matt
I've done something similar in the past but loading from a DB table rather than a resource
Swf is a AxShockwaveFlash Object on the Form to display the flash item.
If you add your resource as a .swf and set the FileType to binary it should return it as a byte array which you can then use in the memorystream constructor
Using ms As New IO.MemoryStream(my.resources.TheFlashFile), fs As New IO.MemoryStream()
Using bwriter As New IO.BinaryWriter(fs)
' Write length of stream for flash AxHost.State
bwriter.Write(8 + ms.ToArray.Length)
bwriter.Write(&H55665566)
' Length of flash movie file
bwriter.Write(ms.ToArray.Length)
bwriter.Write(ms.ToArray)
fs.Seek(0, IO.SeekOrigin.Begin)
swf.OcxState = New AxHost.State(fs, 1, False, Nothing)
End Using
End Using