Jak wyświetlić plik PDF w sterowaniu przeglądarki internetowej zamiast otwierać program Acrobat Reader
Korzystam z Acrobat Reader 11.0.3 i okna 7, Visual Studio 2012 i już włączyłem Acrobat Reader w Manage Addon
i podążajPrzeglądarka WPF otwiera plik PDF w oknie czytnika Adobe
nadal występuje błąd po wypróbowaniu dwóch metod
Nawigacja na stronę została anulowana, nawet jeśli przy użyciu konta administratora otworzysz program WPF
private void CheckAndFixWebBrowserRenderingEngine()
{
RegistryKey baseRegistryKey = Registry.LocalMachine;
string renderingEngineSubKeyString = @"SOFTWARE";
// 64bit operationg systems have another registry path
if (Environment.Is64BitOperatingSystem)
{
renderingEngineSubKeyString += @"\Wow6432Node";
}
renderingEngineSubKeyString += @"\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
//var assemblyValueKey = System.IO.Path.GetFileName(App.ResourceAssembly.Location);
var assemblyValueKey = System.IO.Path.GetFileName(System.Windows.Application.ResourceAssembly.Location);
var renderingEngingeValue = 9999; // check other values below
try
{
RegistryKey sk1 = baseRegistryKey.CreateSubKey(renderingEngineSubKeyString);
var value = sk1.GetValue(assemblyValueKey);
if (value == null || value.ToString() != renderingEngingeValue.ToString())
{
sk1.SetValue(assemblyValueKey, renderingEngingeValue);
//LogHandler.Instance.Add(string.Format("Did update webbrowser rendering engine from {0} to 9000.", value == null ? "[missing]" : value));
}
}
catch (Exception ex)
{
//LogHandler.Instance.Add("Could not check webbrowser rendering engine in registry.");
//LogHandler.Instance.Add(ex.ToString(), Logging.LoggingPriorities.Exception);
}
/*
9999 (0x270F)
Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328)
Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
8888 (0x22B8)
Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
8000 (0x1F40)
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
7000 (0x1B58)
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
*/
}
public ReportForm()
{
this.formID = "Test Report";
//base.Initialization();
InitializeComponent();
CheckAndFixWebBrowserRenderingEngine();
String PDFPath = @"C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf";
WebBro1.Navigate("file:///" + PDFPath);
Metoda 2
wypróbowałem również inną metodę, która dodaje integrację okienka odniesienia i używa UserControl z winform i działa tylko w niezależnym małym projekcie WPF, gdy integruje się to w moim dużym projekcie, ale błąd przekroczył
String PDFPath = @"C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf";
//WebBro1.Navigate("file:///" + PDFPath);
webBrowser1.Navigate("file:///" + PDFPath);
private System.Windows.Forms.WebBrowser webBrowser1;
<WindowsFormsHost Margin="1" x:Name="windowsFormsHost1" Height="600" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="1000"/>
var uc = new UserControl1();
this.windowsFormsHost1.Child = uc;
application.UI.CreateNewForm("Test Report", new Client.Reporting.Pages2.ClientStatement.ReportForm());
public partial class ReportForm : BaseForm
public void CreateNewForm(string title, BaseForm form)
mw.CreateNewForm(title, form);
public class BaseMainWindow : MetroWindow
{
public virtual void CreateNewForm(string title, BaseForm form)
{
}
aktualizacja: prosi o zezwolenie na blokowanie zawartości i szary ekran w przeglądarce Internet Explorer w pliku html przed integracją z dużym projektem
<html>
<body>
<object
classid="clsid:ca8a9780-280d-11cf-a24d-444553540000" id="pdf1"
type="application/pdf"
data="C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf"
style="width: 100%; height: 100%">
<param name="src" "value="C:\Users\LAB-User2\Downloads\Elimination_Methods_in_Polynomial_Computer_Alge(Bookos.org).pdf"></param>
</object>
</body>
</html>
aktualizacja: po uruchomieniu kodu w dużym projekcie WPF, wyświetlany jest czerwony krzyżyk
update: po zaktualizowanym html działa w niezależnym pliku html, jednak zintegrowany z dużym projektem WPF, nie pokazał się i pokazuje tylko czerwony krzyżyk
String temphtml = "<!-- saved from url=(0016)http://localhost --><body style=\"border: 0; margin: 0; padding: 0\"><object classid=\"clsid:ca8a9780-280d-11cf-a24d-444553540000\" id=\"pdf1\" type=\"application/pdf\" data=\"02_LAB_LeaveApplication.pdf\" style=\"width: 100%; height: 100%; border: 0; margin: 0; padding: 0\"></object><script>window.onload = function(){ window.focus();pdf1.setActive(); }</script></body>";
System.IO.File.WriteAllText(@"C:\Users\LAB-User2\Desktop\vpfs-ivpfs-client\iVPFS_Client\Application\bin\Debug\a.html", temphtml);
this.WebBro1.Navigate(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "a.html"));
aktualizuj mimo uruchomienia projektu pobranego z projektu kodowego, pokazuje błąd, a następnie może pokazać pdf i mieć kilka razy puste po otwarciu, a następnie kopiować kody i bibliotekę do małego projektu WPF i uruchamiać, również ma błąd i tylko pokaż białe pustehttps://docs.google.com/file/d/0Bxs_ao6uuBDUeV8yREVBOExSbW8/edit?usp=sharing