Giter Club home page Giter Club logo

blazor.printing's Introduction

Blazor Printing

Print and Save files in Blazor using the native dialog box using JavaScript Interop and PrintJS.

Nuget (with prereleases)

The result

Screenshot

The blogpost

You can read more about the service in this blog post.

Documentation

Documentation and examples can be found here

Installing

You can install from NuGet using the following command:

Install-Package Append.Blazor.Printing

Setup

  1. Inject the IPrintingService in program.cs
builder.Services.AddScoped<IPrintingService, PrintingService>();
  1. Use the Service
@using Append.Blazor.Printing
@inject IPrintingService PrintingService
<button @onclick="@(()=> PrintingService.Print("docs/sample.pdf"))">
 Print PDF
</button>

blazor.printing's People

Contributors

jimmys20 avatar msftgits avatar sulmar avatar vertonghenb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blazor.printing's Issues

using Append.Blazor.Printing not available

Hello,

I've added Install-Package Append.Blazor.Printing to my project. when I try to added to my project by adding "using Append.Blazor.Printing" it does not work.
I can't inject IPrintingService in my program.

My project is a Blazor WASM.

Best regards

Close print dialog event

I currently cannot determine when user click Print or Cancle the printing progress , could you please help me

script.js cannot be loaded when Razor component is emended in an Razor page [Blazor Server]

Hi

the Blazor.Print works well in an pure Blazor App. I am adding Blazor to an existing MVC / Rzor pages Project. When calling PrintingService.Print in an Razor component and t5his razor component is embedder in an razor Page the script.js could not be doinloaded to the server.

  • On a pure Blazor project the ImportModule() function try to download the script.js file from _content/Append.Blazor.Printing/scripts.js

  • if the Razor component is embedded the ImportModule() function try to download the script.js file from XXXXRazorPage_content/Append.Blazor.Printing/scripts.js

Using @media print css

I am currently using the service to print an image element. The problem is, I need to scale the element up when printing. I tried using @media print and then scale the element there, but it seems the query does not work with this service. Is there a workaround?

printJS is not defined

Hello,

if i try to print my PDF, i get the error, that the printJS was not found.

blazor.server.js:1 [2023-06-29T10:25:53.508Z] Error: Microsoft.JSInterop.JSException: printJS is not defined ReferenceError: printJS is not defined at Module.print (http://localhost:5019/_content/Append.Blazor.Printing/scripts.js:3:5) at http://localhost:5019/_framework/blazor.server.js:1:3506 at new Promise (<anonymous>) at Ft.beginInvokeJSFromDotNet (http://localhost:5019/_framework/blazor.server.js:1:3480) at Ft._invokeClientMethod (http://localhost:5019/_framework/blazor.server.js:1:75072) at Ft._processIncomingData (http://localhost:5019/_framework/blazor.server.js:1:72696) at Ft.connection.onreceive (http://localhost:5019/_framework/blazor.server.js:1:67009) at i.onmessage (http://localhost:5019/_framework/blazor.server.js:1:51322) at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args) at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args) at Append.Blazor.Printing.PrintingService.Print(PrintOptions options) at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Giving Default Names to PDFs

I am using this tool in a Web Assembly PWA and I have it printing from html but now I want to be able to give a file a default name when saving it.

Blazor server Example

Hi, Your Software it's a like a piece of gold! really needed that. Unfortunately I am a beginner with blazor and I cannot understand how to use is with Blazor Server. ( the example is for WASM but there are differences ) would be possible for you to put an example for Blazor Server ?
thank you so much.

Error when printing in Kiosk mode

I want to print from the browser immediately without a print dialog. To do this, you can start the browser in kiosk mode. For example:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://localhost:5000 --kiosk-printing

When you run it, an error will be displayed immediately.I want to print from the browser immediately without a print dialog. To do this, you can start the browser in kiosk mode. For example:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://localhost:5000 --kiosk-printing

When you run it, an error will be displayed immediately

Error.in.kiosk-mode-printing.mp4

.

Getting cross-origin error in Edge but it works in Google Chrome

Firstly I want to thank you for your efforts and making this library. It is greatly apreciated.

I am getting this error in microsoft edge version 104.0.1293.63 but not google chrome. I have pasted the errors from the browser console below.

      
Uncaught DOMException: Blocked a frame with origin "http://localhost:51490" from accessing a cross-origin frame.
    at u (http://localhost:51490/_content/Append.Blazor.Printing/scripts.js:1:4641)
    at n.onload (http://localhost:51490/_content/Append.Blazor.Printing/scripts.js:1:5701)
onError @ scripts.js:1
u @ scripts.js:1
n.onload @ scripts.js:1
load (async)
send @ scripts.js:1
b @ scripts.js:1
(anonymous) @ scripts.js:1
load (async)
m @ scripts.js:1
x @ scripts.js:1
print @ scripts.js:3
(anonymous) @ blazor.webassembly.js:1
beginInvokeJSFromDotNet @ blazor.webassembly.js:1
St @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.6.0.8.5qvbcwublj.js:1
$func219 @ 00971db2:0x1a48f
$func167 @ 00971db2:0xce5d
$func166 @ 00971db2:0xbd70
$func2812 @ 00971db2:0xabf00
$func1616 @ 00971db2:0x6fcc1
$func1620 @ 00971db2:0x7032e
$func3214 @ 00971db2:0xc4e92
$mono_background_exec @ 00971db2:0x9434b
Module._mono_background_exec @ dotnet.6.0.8.5qvbcwublj.js:1
pump_message @ dotnet.6.0.8.5qvbcwublj.js:1
setTimeout (async)
_schedule_background_exec @ dotnet.6.0.8.5qvbcwublj.js:1
$func2389 @ 00971db2:0x942fc
$func3213 @ 00971db2:0xc4e22
$func219 @ 00971db2:0x1a4f7
$func167 @ 00971db2:0xce5d
$func166 @ 00971db2:0xbd70
$func2812 @ 00971db2:0xabf00
$func1616 @ 00971db2:0x6fcc1
$func1614 @ 00971db2:0x6fc33
$func967 @ 00971db2:0x50684
$func219 @ 00971db2:0x1a448
$func167 @ 00971db2:0xce5d
$func166 @ 00971db2:0xbd70
$func2812 @ 00971db2:0xabf00
$func1616 @ 00971db2:0x6fcc1
$func1614 @ 00971db2:0x6fc33
$func967 @ 00971db2:0x50684
$func219 @ 00971db2:0x1a448
$func167 @ 00971db2:0xce5d
$func166 @ 00971db2:0xbd70
$func2812 @ 00971db2:0xabf00
$func1616 @ 00971db2:0x6fcc1
$func1620 @ 00971db2:0x7032e
$mono_wasm_invoke_method @ 00971db2:0x969c
Module._mono_wasm_invoke_method @ dotnet.6.0.8.5qvbcwublj.js:1
managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet @ managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet:19
beginInvokeDotNetFromJS @ blazor.webassembly.js:1
b @ blazor.webassembly.js:1
invokeMethodAsync @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
invokeWhenHeapUnlocked @ blazor.webassembly.js:1
A @ blazor.webassembly.js:1
N @ blazor.webassembly.js:1
dispatchGlobalEventToAllElements @ blazor.webassembly.js:1
onGlobalEvent @ blazor.webassembly.js:1
Show 28 more frames

Passing headers

I can't seem to find see a way to pass headers to the internal HttpClient. Is there a way?
It's useful if the URL of that serves the PDF requires an authorization header (as any decent API should).

Thanks!

Printing doesn't work on Firefox

I've been getting blank pages when printing with Firefox (111). I also tested it with Chromium, and it works fine there.

grafik

This appears to be a recent issue, something caused by Firefox itself, because when I originally tested it, it worked. And downgrading the library to an older version didn't help either.

Is there a way to bypass the dialog?

Hi there! I've been looking at your library and it seems to do almost everything I need for a project I am working on. We have a new requirement where we need to bypass the dialog and set things like printer name, copies, ect in code. I didn't see any of these properties exposed but wanted to ask and see if this was something available.

If these properties aren't available in the Blazor side of things, does PrintJs allow this?

Printing HTML with barcode font

I am converting raw HTML to PDF: await PrintingService.Print(html, PrintType.RawHtml);

The css style applied for printing barcodes is style="font-family: 'connectcode39';" . But it is not being reflected in the print.

Any way to print horizontally?

Because the datagrid I am using is to big for a normal print page, I would like to print it horizontally (landscape mode).
But I can't find any option that would allow it.

Error Could not find 'print'

Hello everyone! I'm trying to use the library in my Blazor Server project. But I get an error message. (trying to print Base64).

Microsoft.JSInterop.JSException: "Could not find 'print' ('print' was undefined).
Error: Could not find 'print' ('print' was undefined).
at https://localhost/_framework/blazor.server.js:2:29250
at Array.forEach ()
at n.value (https://localhost/_framework/blazor.server.js:2:29211)
at w (https://localhost/_framework/blazor.server.js:2:28290)
at https://localhost/_framework/blazor.server.js:2:30739
at new Promise ()
at i.beginInvokeJSFromDotNet (https://localhost/_framework/blazor.server.js:2:30713)
at https://localhost/_framework/blazor.server.js:2:111546
at Array.forEach ()
at i.value (https://localhost/_framework/blazor.server.js:2:111517)"

P.S. one more note. I use Blazor.Polifyll to make the app run on the older devices. Even if I include the print.js in my project, it doesn't work.

Maybe someone knows what the problem is?

VG

var test = await DokumentService.PrintPdfFile(selectedItems.Select(s=>s.DocumentId).ToList());
await PrintingService.Print(new PrintOptions(test) { Base64 = true });

Is it possible to print a local file?

Is it possible to print a local PDF file?

example:
string LocalFileName = "C:\Users\work\AppData\Local\Temp\fileExample.pdf";

PrintingService.Print(LocalFileName, showModal: true);

I tried, but without success.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.