Printing in landscape from a Windows Forms WebBrowser control - c#

I have a WebBrowser control in a Windows Forms Host in a WPF application. I know that in order to print it's contents, I use simply WebBrowser.Print(), however, how can I tell the printer to print the contents in landscape rather than a portrait orientation? I've been searching the Internet on this and oddly enough, it seems to be actually something that is a bit hard to do -- is this really the case? It seems odd to me that it wouldn't be easily implementable.
Thanks!

INFO: WebOCHostCSharp.exe Hosts the WebBrowser Control in C# .NET
http://support.microsoft.com/kb/326217
The Print(String) method prints a document and does not display a dialog box. This method uses a Microsoft HTML (MSHTML) print template to automatically control print options such as paper size, orientation, and number of copies.
Note: This project does NOT contain this mystery overloaded method "Print(string)", It's actually called "PrintFormatted(string)"

Related

WPF WebBrowser opens Adobe Reader 10 instead of displaying the pdf inside the browser

I'm facing a quite difficult problem. I inherited a software framework (roughly 100k lines of code) and now I want to display PDF files within this software. Since I can put WPF UserControls into this, I created a light-weight UC containing a WPF WebBrowser. I then used the Navigate() method to load a PDF document. Unfortunately, the WebBrowser does not display the PDF document, but instead opens up Adobe Reader 10 in a separate window/process. It will display HTML just fine, but even embedding the PDF inside HTML (using the <object>-tag or <iframe> did not display the pdf though, but caused Adobe Reader to open). When I use the same code in a standalone app (with no code from the framework), the WebBrowser displays the PDF as expected.
Modifying the Registry to allow feature emulation did not solve this issue either.
I've been looking for a solution for days now and cannot seem to find anything. So here is were I hope to get some insight:
How do I get my standalone app to behave like my framework? I did not seem to find anything about this either, but I hope that by managing this, I'll be able to fix the issue with my framework.
Okay, I kinda feel dumb for not paying attention to this:
My test app works because its being compiled in x86, while my Framework uses x64. Apparently, the WPF WebBrowser (same's true for the WinForms WebBrowser Control) are not able to render PDFs when they are running in an x64 app. Once it changed the target platform in my test app from x86 to x64, it also began opening up Adobe Reader...

Display PDF preview in WPF and search for a phrase

I need to display PDF preview in WPF control, programmatically search for text in it, highlight found text and be able to copy text. Sounds simple, but I am struggling with different approaches for a week already.
Here what I have considered:
Find PDF controls for WPF
Most of them just render PDF as images or cost too much. Royalty or subscription fee is not an option.
The only suitable control that I found is:
http://www.syncfusion.com/products/wpf/pdf-viewer
I was even able to do searches programmatically with reflection hacks, but it renders text too blurry (Syncfusion promise to fix this soon) and load pages with a noticeable lag during scrolling.
Using AcroPDFlib as an ActiveX component
I was not able to make it work with the latest Adobe reader on Windows 10 64-bit. But I don't see methods for search anyway, so I dropped this. Also, it seems that it is not free for commercial use:
AcroPDFlib, AxAcroPDFLib commercial use
Load PDF in WebBrowser control
It works and even allow searches, but it can search only for single words which make this search useless. If I search for "big apple" it highlights all big and apple and also open this search panel that cover the document.
Send CTRL+F and text to the browser control to trigger search
I have tried to use this library
http://inputsimulator.codeplex.com/
But PDF in browser control seems to ignore keystrokes from there or maybe I am doing something wrong. Still considering this option.
Use pdf.js in browser control
IE7-based control from WPF won't support that, so I need another browser control. And it seems that I also need to start nodejs to make it work. Seems like a too much overhead for this task. And also it is not clear does PDF.js supports search for a phrase or not.
But I am still not discarding this option. Does anyone were able to make it work inside WPF?
Any suggestions?

How to tail text from a specific control from an external program?

I have tried inspecting this window using Inspect.exe provided on Windows' 8.1 Software Development Kit Testing Tools. I couldn't seem to identify the control handle for this huge rich textbox like control. I could however get the control handle of the edit box below the textbox. I was hoping I could talk directly to the control and use a library such as WindowScrape to get the text.
I believe the external program is created in VC++ . If that helps.
This is the window. I am trying to get text from that is boxed in red color. This is a chat window , messages come in every 5 to 10 seconds. This box scrolls automatically. I want to tail through the text and get the latest message.
Is there any other way to accomplish this?
Tesseract maybe, but I do not know where to start to monitor a specific position relative to the window. So that when I move the window it will still be able to monitor that window.
Can you provide a screenshot of Inspect results showing both the tree and details panes while selecting the chat box?

Print windows form to PDF with controls that use scrollbars? C#

Similar question:
convert windows form to pdf file
I am trying to print a Windows form to PDF in a similar manner as the above question, however the method described in that particular answer is essentially taking an image of the form. I have controls that use a scrollbar (e.g. tablelayoutpanel) and need to see all of the information within, rather than whatever selection the scrollbar happens to be on.
Is this possible?
You will need to take a screen shot and use that image to generate a pdf.
The only way I have seen this done is using a program called Snagit, which scrolls the application window automatically whilst capturing it and I assume stitches that together.
I would imagine you would need to do that programatically to get the output you need?

disable windows font size increase in my C# application

I built a windows application in C# that is very size specific. I hard coded the size of the form so that it could not be resized. The problem is when someone changes there windows settings to font size for example (125% or 150%) my application breaks and buttons get moved over, and things fall off of screen. The entire application is a mess.
Is there a way in C# to disable the custom font effects of windows and use the pre-set font I told it to use in my form. I want all windows custom features to be turned to default on my application.
Is this possible at all, like import a DLL and call a function or change my program.cs some how.
Don't do that. Write your application so it adapts to the user's selected font size.

Categories