This repository has been archived by the owner on Nov 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Javascript call the C# method to print content.
- Loading branch information
1 parent
8ccd54e
commit 8813d77
Showing
12 changed files
with
301 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 liangminhua | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Printing; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PrintBrowser | ||
{ | ||
class Internal | ||
{ | ||
[STAThread] | ||
public void print(string printerName, string xaml) | ||
{ | ||
Print.PrintXaml(printerName, xaml); | ||
} | ||
|
||
public string[] GetPrinters() | ||
{ | ||
PrintQueueCollection pqc = Print.GetPrintQueues(); | ||
var Printers = from queues in pqc | ||
select queues.FullName; | ||
return Printers.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using CefSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace PrintBrowser | ||
{ | ||
internal class MenuHandler : IContextMenuHandler | ||
{ | ||
private const int ShowDevTools = 26501; | ||
private const int CloseDevTools = 26502; | ||
private const int ReloadNoCache = 103; | ||
|
||
void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) | ||
{ | ||
//To disable the menu then call clear | ||
// model.Clear(); | ||
|
||
//Removing existing menu item | ||
//bool removed = model.Remove(CefMenuCommand.ViewSource); // Remove "View Source" option | ||
|
||
//Add new custom menu items | ||
model.Clear(); | ||
model.AddItem((CefMenuCommand)ReloadNoCache, "Refresh"); | ||
model.AddItem((CefMenuCommand)ShowDevTools, "Show DevTools"); | ||
model.AddItem((CefMenuCommand)CloseDevTools, "Close DevTools"); | ||
} | ||
|
||
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) | ||
{ | ||
if ((int)commandId == ShowDevTools) | ||
{ | ||
browser.ShowDevTools(); | ||
} | ||
if ((int)commandId == CloseDevTools) | ||
{ | ||
browser.CloseDevTools(); | ||
} | ||
return false; | ||
} | ||
|
||
void IContextMenuHandler.OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame) | ||
{ | ||
|
||
} | ||
|
||
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<html> | ||
|
||
<head> | ||
<title></title> | ||
</head> | ||
|
||
<body> | ||
<h1>PrintTest</h1> | ||
<div id="printers"></div> | ||
<button onclick="print()">PrintSomething</button> | ||
</body> | ||
<script> | ||
var printers = Internal.getPrinters(); | ||
for (var i = 0; i < printers.length; ++i) { | ||
var radio = "<input name='currentPrinter' type='radio' value='" + printers[i] + "'>" + printers[i] + "</input><br>"; | ||
document.getElementById('printers').innerHTML += radio; | ||
} | ||
function print() { | ||
var currentPrinter= null; | ||
var radios = document.getElementsByTagName('input'); | ||
for (var i = 0; i < radios.length; ++i) { | ||
if (radios[i].checked) { | ||
console.log(radios[i].value); | ||
currentPrinter =radios[i].value; | ||
} | ||
} | ||
var template = ' \ | ||
<FlowDocument PagePadding="0" \ | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> \ | ||
<Paragraph TextAlignment="Center">Print Test</Paragraph> \ | ||
</FlowDocument> \ | ||
'; | ||
Internal.print(currentPrinter,template); | ||
} | ||
</script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="cef.redist.x64" version="3.2785.1486" targetFramework="net452" /> | ||
<package id="cef.redist.x86" version="3.2785.1486" targetFramework="net452" /> | ||
<package id="CefSharp.Common" version="53.0.1" targetFramework="net452" /> | ||
<package id="CefSharp.Wpf" version="53.0.1" targetFramework="net452" /> | ||
</packages> |
Oops, something went wrong.