Open PDF in WPF Application - wpf

I have followed this link - Display a PDF in WPF Application to open PDF in a WPF application:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AxAcroPDFLib.AxAcroPDF)); ` // axAcroPdf1 = new AxAcroPDFLib.AxAcroPDF();
//this.axAcroPdf1.Dock = System.Windows.Forms.DockStyle.Fill;
//this.axAcroPdf1.Enabled = true;
//this.axAcroPdf1.Name = "Demo";
//this.axAcroPdf1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPdf1.OcxState")));
//axAcroPdf1.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "\\FileStorage\\Demo.pdf");
// axAcroPdf1.Visible = true;
Got an exception like this:
Could not find any resources appropriate for the specified culture or the neutral >culture. Make sure "AxAcroPDFLib.AxAcroPDF.resources" was correctly embedded or linked >into assembly "AxInterop.AcroPDFLib" at compile time, or that all the satellite >assemblies required are loadable and fully signed.

Related

How to upload file in silverlight

I want to save (upload) a file in silverlight into the silverlight application folder.
I get the URI of the application
string str3 = App.Current.Host.Source.AbsoluteUri + "/Recording/";
but i don't know how to save file.
I use this code.....
string extension = "wav";
// Create an instance of the open file dialog box.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
// Set filter options and filter index.
openFileDialog1.Filter = String.Format("{1} files (*.{0})|*.{0}|WAV FILES (*.*)|*.*", extension, "Audio");
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = false;
// Call the ShowDialog method to show the dialog box.
bool? userClickedOK = openFileDialog1.ShowDialog();
// Process input if the user clicked OK.
if (userClickedOK == true)
{
string str = App.Current.Host.Source.AbsoluteUri + "/Recording/";
openFileDialog1.File.CopyTo(str);
}
That won't work by itself (I assume your application is hosted on a web server), you need an uploader that will send the content to the server, and a server side handler that will receive and store the file.
Take you pick from one of those Silverlight uploaders:
Silverlight File Uploader
Silverlight File Upload
Silverlight Multi File Uploader
Personally I went with the first one, but I believe they're all quite good.

open a PDF : WPF

I want to open a PDF file in a button click. I'll keep the PDF file within the solution/namespace of the project. Can anyone give me solution for this?
To start the standard PDF viewer you can simply start an external process:
Process proc = new Process( );
proc.StartInfo = new ProcessStartInfo( ) {
FileName = path //put your path here
};
proc.Start( );
To show the file inside your application you have to use the pdf viewer as an ActiveX-component.
My solution:
private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();
this.axAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axAcroPDF1.Enabled = true;
this.axAcroPDF1.Name = "axAcroPDF1";
this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPDF1.OcxState")));
axAcroPDF1.LoadFile(DownloadedFullFileName);
axAcroPDF1.Visible = true;
You have many options:
User WPF WebBrowser control and open the pdf:
Link 1, Link 2
User WinformsHost to host ActiveX Stackoverflow link.

WPF control hosted in Windows Forms: Is it possible to access resource files?

I have a WPF control hosted in Windows Forms and I would like to access it's resources, specifically images. What is the best way to do that?
I was thinking of using a ResourceDictionary, but I'm not sure how I can access it from within a Windows Form.
This is a standalone WPF control, in a DLL? There are two ways that the resources can be embedded... as part of a .resources file (e.g. the Project's "Resoruces" tab), or as files included as "Embedded Resources"...
To get the assembly reference to the DLL this is usually the easiest:
var ass = typeof(ClassInOtherDll).Assembly;
In the Resources
If this is part of the default project resources, and not a different .resources file included inside the DLL, you can use the default base-name.
var ass = typeof(ClassInTargetDLL).Assembly;
var rm = new ResourceManager("...BaseName...", ass);
BaseName for default project resources is :
C# := Namespace.Properties.Resources
VB := Namespace.Resources
After that you can just call GetObject() and do a cast back:
var myImage = rm.GetObject("check_16");
return myImage as Bitmap;
If you want to find out whats in there, get the assembly reference and call
ass.GetManifestResourceNames()
.resources files can be used with a ResourceManager
embedded resources will just show up as a list. Use the other method for these.
And this is all assuming they default culture =)
As Embedded Resources
You can use the regular methods on the assembly to get an embedded resource. You find it by name, and then Basically you will need to convert the stream back into your desired type.
GetManifestResourceNames()
GetManifestResourceStream(name)
help getting the desired file with a helper function to find files by name.
I usually use these like this:
// called GetMp3 in the post, but it returns a stream. is the same thing
var stream = GetResourceStream("navigation.xml");
var reader = New XmlTextReader(stream);
return reader;
To get an image that is an embedded resource, this works for me:
var stream = GetResoureStram("check_32.png");
var bmp = new Bitmap(stream);
this.MyButton.Image = bmp;

Load image not in xap Silverlight

i'm developing an application and i would load an image that isn't in the clientbin folder, but in a folder placed in my server. I would do something like this
BitmapImage bit = new BitmapImage();
string path = "c:/image.png";
bit.UriSource = new Uri(path, UriKind.Absolute);
identity.Source = bit;
but it doesn't function.Any idea?
Thanks
Try:
Image.Source = New Imaging.BitmapImage(New Uri("http://www.Pic.jpg", UriKind.Absolute))
You do not want to include it in your project or the .xap will get huge.
Silverlight applications run on the client, not on the server, so referencing the path as you had been trying to do, would really point to the path on client machine running the application. However, Silverlight does not have rights to read or write from or to the client's disk anyway, due to sercurity reasons. The Isolated Storage functionality is the exception to that.
Therefore, your option is to try the first answer given by Bill, or a WebService, which is more complex to implement.
ib.
To add to Bill's answer. You can also use server side resources using the following helper method which is derived from the location of the xap file.
public static string GetUrlForResource(string resourcePage)
{
var webUrl = Application.Current.Host.Source.ToString();
//Get ClientBin Directory
var stub = webUrl.Substring(0, webUrl.LastIndexOf("/"));
//Get application root.
stub = stub.Substring(0, stub.LastIndexOf("/") + 1);
//Append the application root to the resource page.
webUrl = stub + resourcePage;
return webUrl;
}
To use it like Bill's answer, use the following:
Image.Source = new Imaging.BitmapImage(new Uri(GetUrlForResource("images/myimage.png"), UriKind.Absolute));

how to Play .flv files in WPF?

How to Play .flv files in WPF? please anyone help me out.
// Create the interop host control.
var host = new WindowsFormsHost();
// Create the ActiveX control.
var axShockwaveFlash = new AxShockwaveFlash();
// Assign the ActiveX control as the host control's child.
host.Child = axShockwaveFlash;
// Add the interop host control to the Grid
// control's collection of child controls.
this.MainGrid.Children.Add(host);
axShockwaveFlash.Location = new System.Drawing.Point(0, 0);
axShockwaveFlash.LoadMovie(0, #"C:\player.swf");
axShockwaveFlash.SetVariable("quality", "Low");
axShockwaveFlash.ScaleMode = 0;
axShockwaveFlash.AllowScriptAccess = "always";
//axShockwaveFlash.FlashVars = #"file=C:\barsandtone.flv" +
//&autostart=true&fullscreen=true&controlbar=none&repeat=" +
//"always&stretching=fill";
axShockwaveFlash.CallFunction("<invoke name=\"loadFLV\" " +
"returntype=\"xml\"><arguments><string>barsandtone.flv</string>" +
"</arguments></invoke>");
axShockwaveFlash.Play();
Reference:
Hosting Flash movie in a WPF project
Hosting Flash Movie in WPF (Part 2): Some ‘Strictly Microsoft Technology Please’ options
If you want to use DirectShow, you must use WPFMediaKit.
With http://www.free-codecs.com/download/K_lite_codec_pack.htm it will be ok.
Max #GoTactile
If thats using DirectShow then you probably just need a codec installed:
http://www.free-codecs.com/download/K_lite_codec_pack.htm

Resources