I am writing Windows Phone 8.1 Silverlight app,
I have to convert Image File to PDF.
Is there any way, how to do it and which Libraries are available freely?
Thanks!!
There's a client site js library called jsPDF which is worth giving a try.
Here is the answer, whoever wants it. Its working and tested.
I have added ComponentOne Library in Windows Phone 8.1 Project.
using C1.Phone.Pdf;
using C1.Phone.PdfViewer;
C1PdfDocument pdf = new C1PdfDocument(PaperKind.PrcEnvelopeNumber3Rotated);
pdf.Landscape = true;
var rc = new System.Windows.Rect(20,30,300,200);
pdf.DrawImage(wbitmp, rc);
var fillingName = "Test.pdf";
var gettingFile = IsolatedStorageFile.GetUserStoreForApplication();
using (var loadingFinalStream = gettingFile.CreateFile(fillingName))
{
pdf.Save(loadingFinalStream);
}
Related
I want to convert HTML content to PDF. I have tried using third party API like GemBox, GrapeCity..
these all are working in UWP but in android failing.
Please suggest any solution. I can go with paid API's also.
Thanks!
If you are looking for a one-in-all solution, you can check out the leadtools document converter nuget here: https://www.nuget.org/packages/Leadtools.Document.Sdk/ disclaimer: i am employed by the vendor of this library
LEADTOOLS supports HTML -> PDF as well as a bunch of other formats. You can see more information here: https://www.leadtools.com/sdk/document/document-converter
This library supports Xamarin on Android, UWP, and iOS and is completely offline.
Here is a snippet of code that will work for your use-case:
using (var documentConverter = new DocumentConverter())
{
var htmlString = File.ReadAllText(#"./test.htm");
using (var ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlString)))
{
var htmlDocument = DocumentFactory.LoadFromStream(ms, new LoadDocumentOptions());
var jobData = DocumentConverterJobs.CreateJobData(htmlDocument, "output.pdf", DocumentFormat.Pdf);
var job = documentConverter.Jobs.CreateJob(jobData);
documentConverter.Jobs.RunJob(job);
}
}
I have written a windows store app in XAML & C# to read image from tablet's webcam and decode the barcode using Zxing's lbrary. The code is working fine on a given tablet having an i5 processor while it fails to run on an actual tablet with 2MP camera and "Intel Baytrail Quad-Core" processor.
Any ideas on why this could happen?
Please let me know if you need to see my code for this issue ad I will share.
I am wondering how can the same code work on 1 tablet while fail on another tablet.
Thanks in advance for any help provided.
EDIT
Code used to scan the barcode and read as below - The last if/else block is what I get to. No exception raised :(
string barcodeData = string.Empty;
using (var imageStream = new InMemoryRandomAccessStream())
{
processingImage = true;
var encodingProperties = new ImageEncodingProperties();
encodingProperties.Subtype = "Jpeg";
encodingProperties.Width = 400;
encodingProperties.Height = 400;
await captureMgr.CapturePhotoToStreamAsync(encodingProperties, imageStream);
await imageStream.FlushAsync();
imageStream.Seek(0);
var bitmap = new WriteableBitmap(400, 400);
bitmap.SetSource(imageStream);
preview1.Source = bitmap; //preview1 is an Image control to display the captured image
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(imageStream);
imageStream.Seek(0);
var bitmapDecoder = await BitmapDecoder.CreateAsync(BitmapDecoder.JpegDecoderId, imageStream);
var data = await bitmapDecoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
new BitmapTransform(),
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage
);
if (data != null)
{
BarcodeReader barcodeReader = new BarcodeReader();
var result = barcodeReader.Decode(
data.DetachPixelData(),
(int)bitmapDecoder.PixelWidth,
(int)bitmapDecoder.PixelHeight,
ZXing.RGBLuminanceSource.BitmapFormat.BGR32
);
if (result != null)
{
//Barcode found
}
else
//No data found.
}
}
I guess you are using ZXing.NET library.
Have you ever considered moving to another barcode scanner library?
Accessing the "ISSUES" section in ZXing.NET Library, you can see that there's a lot of bugs still opened for Windows Phone (and should be Window Store also).
http://zxingnet.codeplex.com/workitem/list/basic
One of it called my attention. Check out this comment:
While the WP samples all target Silverlight, you must not forget that the new WP8.1 base is WinRT - so I suggest you use the WinRT sample as a base.
I tried to do the same, but truth to be told, ZXing lacks a lot ATM for WinRT Universal Apps - it's slow, unreliable, and barely ever recognizes a thing.
http://zxingnet.codeplex.com/workitem/13311
I don't know how reliable this is, but the last time the project was updated was on April 7th!!!!
You should really consider changing you library!
Hi,
I made a lib for WinRT using ZXing & Imaging SDK.
It works well (but does not include any additional focus feature).
https://github.com/stepheUp/VideoScanZXing4WP81
There is a lib and a sample app that you can try.
It works for barcodes and QRCode (barcode by default but just change the optional parameter in the scan function code to use QRCode)
Hope it helps,
Stéphanie
I am creating Windows Phone 8.1 application, I am trying to open document using launcher, but getting exception, and document is not MS OFFICE document, it is created in other software. Here is my code.
string file = "readme.txt";
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
if (isf.FileExists(file))
{
isf.DeleteFile(file);
}
var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);
await Launcher.LaunchFileAsync(await ApplicationData.Current.LocalFolder.GetFileAsync(file));
I am getting error like this:
"Can't be Open, File Format doesn't recognize"
and sometimes like this:
"Document has been damaged"
I do not know how to deal with this, I am stuck here, Any help would be greatly appreciated.
The file name without extension is "campaign rev 2", so the file pass to the launcher is definitely not "readme.txt".
You can pass a LauncherOptions.DisplayApplicationPicker to the LaunchFileAsync method.
var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);
var options = new Windows.System.LauncherOptions(){ DisplayApplicationPicker = true};
await Launcher.LaunchFileAsync(filerun, options);
It will open a list of applications for you to choose from, so you can examine the file extension is actually .txt or .xls/.xlsx (Excel).
According to the documentation, this overload is available on Windows Phone 8.1. But I have not upgraded to 8.1 yet, so I can not give you a screenshot of the Application Picker.
Screenshot from the web. Hope this helps.
I am trying to capture MP4 video at a specific resolution in Windows Phone 8 (to be specific, 480x480). I know that I can't use sizes other than the presets, and 480x480 is not a preset. How do I transform a captured video (such as 640x480) and crop the top and bottom to make it 480x480? Any free or open source libraries (that run on Windows Phone) are welcome. Please don't answer with answers such as 'use an external server', I need an on-device solution.
Use the Windows.Phone.Media.Capture APIs and the AudioVideoCaptureDevice class
Second parameter for AudioVideoCaptureDevice.OpenAsync - see this link - is the resolution. And you can get the resolutions using AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensor)
EDIT: To set custom resolutions try AudioVideoCaptureDevice.SetCaptureResolutionAsync
EDIT 2: You could try something like the following to transform recorded video: (can't find where i got the code from soz to author!)
StorageFolder isoStore = await ApplicationData.Current.LocalFolder.GetFolderAsync("Shared");
var file = await isoStore.CreateFileAsync("foos1.wmv", CreationCollisionOption.ReplaceExisting);
using (var s = await file.OpenAsync(FileAccessMode.ReadWrite))
{
Windows.Foundation.Size resolution = new Windows.Foundation.Size(640, 480);
avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).Last());
VideoBrush videoRecorderBrush = new VideoBrush();
videoRecorderBrush.SetSource(avDevice);
viewfinderRectangle.Fill = videoRecorderBrush;
await avDevice.StartRecordingToStreamAsync(s);
Thread.Sleep(30000);
await avDevice.StopRecordingAsync();
}
new MediaPlayerLauncher()
{
Media = new Uri(file.Path, UriKind.Relative),
}.Show();
I'm trying to make a Windows Phone 7 app that will save some images off the web, I have no idea where I can or if I can save images from the web to the phone.
What can I do to save images?
You can download them using WebClient or WebRequest to get the raw bytes.
You can then save to isolated storage fairly easily - but I don't believe you can save in any location seen by the Picture hub, if that's what you were aiming for. (I can't see anything in the Microsoft.Phone.Tasks namespace which would be relevant. There are tasks to capture the camera of choose a photo, but not to save one.)
EDIT: Ooh, I've just found a way. You can use the MediaLibrary class and its SavePicture method... although that's in XNA, so I'd at least have concerns about it working from a Silverlight app. I know some bits of the XNA API do work from Silverlight, and some don't. Worth experimenting with.
On the phone, you can use HttbWebRequest (recommended to avoid UI impact) or WebClient per the project I posted here.
WebClient, HttpWebRequest and the UI Thread on Windows Phone 7
You can then take your stream and pass it into something of this form to write it to isolated storage.
private void PicToIsoStore(Stream pic) {
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
var bi = new BitmapImage();
bi.SetSource(pic);
var wb = new WriteableBitmap(bi);
using (var isoFileStream = isoStore.CreateFile("somepic.jpg")) {
var width = wb.PixelWidth;
var height = wb.PixelHeight;
Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100);
}
}
}
Jon is correct you can also use MediaLibrary.SavePicture. Be aware that this would put the pics mixed in with the users photos in the Picture Hub.
This is as straight forward as
private void PicToMediaLibary(Stream pic) {
MediaLibrary lib = new MediaLibrary();
lib.SavePicture("blah", pic);
}
Storing it in isolated storage is basically your apps private file system.