open a PDF : WPF - 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.

Related

Window.close not Working in page Refernce Apex method

I have page reference method in apex controller.
I need to close the current tab .
Here is my code:
public PageReference savePostSurveyAnswer(){
String sitePathPrefix = Site.getPathPrefix();
System.debug('savePostSurveyAnswer method start');
CaseIdentifierIdValue = ApexPages.currentPage().getParameters().get('caseIdentifierId');
ShGl_PostChatSurvey__c postChatSurvey = new ShGl_PostChatSurvey__c();
postChatSurvey.ShGl_SurveyQuestion1__c = question1;
postChatSurvey.ShGl_SurveyQuestion2__c = question2;
postChatSurvey.ShGl_SurveyQuestion3__c = question3;
postChatSurvey.ShGl_SurveyQuestion4__c = question4;
postChatSurvey.ShGl_SurveyResponse1__c = questionAnsSelected1;
postChatSurvey.ShGl_SurveyResponse2__c = questionAnsSelected2;
postChatSurvey.ShGl_SurveyResponse3__c = questionAnsSelected3;
postChatSurvey.ShGl_SurveyResponse4__c = questionAnsSelected4;
postChatSurvey.ShGl_Market_Code__c = 'US'; //new data base model
postChatSurvey.ShGl_UniqueCaseIdentifier__c = CaseIdentifierIdValue;
//postChatSurvey.ShGl_LiveTranscriptChatKey__c = chatKeyIdValue;
//postChatSurvey.ShGl_CaseOfSurvey__c = (Id) LiveChatTranscriptObj.CaseId; //through trigger
Database.SaveResult postSaveResult = Database.insert(postChatSurvey);
return new PageReference('javascript:window.close();');
}
Thanks in advance.
Any help would be appreciated.
When you check the documentation for Window.close() you will find the reason:
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
In short: The browser won't let you. This is not specific to Salesforce or VF. Windows.close() would anyway not close a tab, but the whole browser window.
If you are looking to close a console tab, this question/answer might provide what you are looking for.

How to automate upload multiple files using sikuli and selenium webdriver in java

I am new with sikuli, Unable to generate Sikuli script for upload functionality for web application.
Please note that typically, you can automate file upload scenario using Selenium only, no need for Sikuli.
For uploading a file you just need to callsendKeys() method (with file path as argument) on the WebElement that is displayed for file uploading. Code goes like this:
//Put this for textbox near to upload button
driver.findElement(By.id("id_or_other_locator_goes_here")).sendKeys("file_path_goes_here");
And then click the upload button:
driver.findElement(By.xpath("locator_for_upload_button")).click(); // Click Upload button
Sikuli :
I have used Sikuli to automate file download scenario in IE and below are the steps for this:
First capture image of Save button in File download dialog box and save it
Put Sikuli jar in your Java project
Use following code snippet
// Code:
//Save the file in Downloads directory by using on Sikuli
ScreenRegion s = new DesktopScreenRegion();
Target target = new ImageTarget(new File("SavedImagePath.png"));
ScreenRegion r = s.find(target);
Mouse mouse = new DesktopMouse();
if (r != null) {
mouse.click(r.getCenter());
Thread.sleep(5000);
} else {
System.out.println("Unable to click using Sikuli")
}
Thanks sandeep!
tried below script using Screen and Pattern class of Sikuli to capture desktop based file from open folder windows at run time and it works!!
String FileToUpload = "/location of file to upload/"
String fileNameLoc = "/fileName_input sikuli image location"
String openButtonLoc = "/Open button sikuli image location/"
//Code to perform action using action using sikuli script
Screen src = new Screen();
src.setAutoWaitTimeout(80);
Pattern fileName = new Pattern(fileNameLoc).similar((float) 0.5);
if (src.exists(fileName, 10) != null)
{
System.out.println("File Name Pattern exist..");
Match match = src.getLastMatch();
match.find(fileName);
match.click(fileName);
match.type(fileName, FileToUpload);
match.setAutoWaitTimeout(50);
}
else
{
System.out.println("File Name pattern not found on screen..");
}
Pattern open = new Pattern(openButtonLoc).similar((float) 0.5);
if (src.exists(open, 5) != null)
{
System.out.println("Open Button pattern exist..");
Match match = src.getLastMatch();
match.find(open);
match.click(open);
match.setAutoWaitTimeout(30);
}
else
{
System.out.println("Open buton pattern not found on screen..");
}

XAML OpenFileDialog(), missing namespace

I recently started doing some WPF windows 8.1 apps and now I searched for a open file dialog. Some information is available at Microsoft and some blogs but the results are not that great.
Tried these lines:
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;
}
This should work greatly as there are way more examples like this one, unfortunately not in my case because of the missing assembly reference.. It does not know Win32 in the Microsoft using.
If in any way someone can clear this out to me, I would appreciate it.

Open PDF in WPF Application

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.

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.

Resources