我使用的Acrobat Reader 11.0.3和窗口7時,Visual Studio 2012,並已顯示在Web瀏覽器控件PDF而不是打開Acrobat Reader軟件的啓用Acrobat Reader軟件中管理附加組件如何
,並按照WPF webbrowser opens PDF file in Adobe reader window
仍然有錯誤嘗試兩種方法
導航到該網頁被取消後 即使使用管理員帳戶打開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);
方法2
我也有試過其中添加引用windowformintegration和使用的WinForm的用戶控件,它只是在一個獨立的WPF小項目 工作時,在我的大項目這個整合的另一種方法,它得到了上面的錯誤
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)
{
}
更新:它要求允許在HTML文件塊內容和灰色屏幕在Internet Explorer之前集成到大項目
<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>
更新:當運行大型的WPF項目的代碼,它顯示一個紅叉
更新:更新的HTML後,它工作在獨立的HTML文件,但集成在WPF大項目,它未能顯示,只顯示一個紅色十字
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"));
更新雖然運行從CodeProject上下載的項目,它顯示一個錯誤,然後CA n顯示pdf並在打開時有幾次空白,然後我將代碼和庫複製到一個小WPF項目並運行,它也有錯誤出來,只顯示白色空白https://docs.google.com/file/d/0Bxs_ao6uuBDUeV8yREVBOExSbW8/edit?usp=sharing
你發現了它,而不是在你的大項目中的工作?我也有完全一樣的問題。我在我的真實項目中有一個(黑色)十字,但在Prototyp應用程序中它工作得很好。 – Florian