Comments (4)
Please provide the source code of your test
from jsprintmanager-blazor.
It is exact the same code from your github examples:
Here ist the code inside my index page:
`@page "/"
@using Neodynamic.Blazor
@using System.IO
@Inject JSPrintManager JSPrintManager
Advanced PDF Printing
@if (JSPrintManager.PrintersInfo == null)
{
Loading...
Getting printers...
}
else
{
Select the PDF File to print
@if (isLoading)
{
Loading files...
}
URL for PDF File
Predefined Sample:
<button type="button" class="btn btn-light btn-sm" @OnClick="@(() => SetFilePath("https://neodynamic.com/temp/mixed-page-orientation.pdf"))">
mixed-page-orientation.pdf
<div class="row">
<div class="col-md-12">
<br />
<div class="alert alert-info">
<strong>Target Printer & PDF Printing Settings</strong>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<label>Printer:</label>
<EditForm Model="@MyPrinter">
<InputSelect Value="MyPrinter.PrinterName" ValueChanged="@((string s)=>PrinterChanged(s))" ValueExpression="@(()=>MyPrinter.PrinterName)" class="form-control form-control-sm">
@foreach (var p in JSPrintManager.PrintersInfo)
{
<option value="@p.Name">@p.Name</option>
}
</InputSelect>
</EditForm>
</div>
<div class="col-md-3">
<label>Tray:</label>
<EditForm Model="@MyPrinter">
<InputSelect @bind-Value="MyPrinter.TrayName" class="form-control form-control-sm">
@if (trays != null)
{
@foreach (var t in trays)
{
<option value="@t">@t</option>
}
}
</InputSelect>
</EditForm>
</div>
<div class="col-md-3">
<label>Paper:</label>
<EditForm Model="@MyPrinter">
<InputSelect @bind-Value="MyPrinter.PaperName" class="form-control form-control-sm">
@if (papers != null)
{
@foreach (var p in papers)
{
<option value="@p">@p</option>
}
}
</InputSelect>
</EditForm>
</div>
<div class="col-md-3">
<label>Print Rotation (Clockwise):</label>
<EditForm Model="@MyPdfFile">
<InputSelect @bind-Value="MyPdfFile.PrintRotation" class="form-control form-control-sm">
@foreach (var pr in Enum.GetValues(typeof(PrintRotation)))
{
<option value="@pr">@pr</option>
}
</InputSelect>
</EditForm>
</div>
</div>
<br />
<div class="row">
<div class="col-md-3">
<label>Pages Range: [e.g. 1,2,3,10-13]</label>
<EditForm Model="@MyPdfFile">
<InputText @bind-Value="MyPdfFile.PrintRange" class="form-control form-control-sm" />
</EditForm>
</div>
<div class="col-md-3">
<EditForm Model="@MyPdfFile">
<label>
Auto Center
<InputCheckbox @bind-Value="MyPdfFile.AutoCenter" />
</label>
</EditForm>
<EditForm Model="@MyPdfFile">
<label>
Auto Rotate
<InputCheckbox @bind-Value="MyPdfFile.AutoRotate" />
</label>
</EditForm>
</div>
<div class="col-md-3">
<label class="@(builtInDuplexSupport ? "" : "propDisabled")">
Use Driver Duplex Printing
<input type="checkbox" @bind="useDriverDuplex" disabled="@(!builtInDuplexSupport)" />
</label>
<EditForm Model="@MyPdfFile">
<label>
Use Manual Duplex Printing
<InputCheckbox @bind-Value="MyPdfFile.ManualDuplex" />
</label>
</EditForm>
</div>
<div class="col-md-3">
<label>Page Sizing:</label>
<EditForm Model="@MyPdfFile">
<InputSelect @bind-Value="MyPdfFile.PageSizing" class="form-control form-control-sm">
@foreach (var pr in Enum.GetValues(typeof(Sizing)))
{
<option value="@pr">@pr</option>
}
</InputSelect>
</EditForm>
</div>
</div>
<br />
<div class="row">
<div class="col-md-3">
<EditForm Model="@MyPdfFile">
<label>
Print In Reverse Order
<InputCheckbox @bind-Value="MyPdfFile.PrintInReverseOrder" />
</label>
</EditForm>
</div>
<div class="col-md-3">
<EditForm Model="@MyPdfFile">
<label>
Print Annotations
<InputCheckbox @bind-Value="MyPdfFile.PrintAnnotations" />
</label>
</EditForm>
</div>
<div class="col-md-3">
<EditForm Model="@MyPdfFile">
<label>
Print As Grayscale
<InputCheckbox @bind-Value="MyPdfFile.PrintAsGrayscale" />
</label>
</EditForm>
</div>
<div class="col-md-3">
</div>
</div>
<div class="row">
<div class="col-md-12">
<br />
<div class="text-center">
<button class="btn btn-success btn-lg" @onclick="DoPrinting">
<i class="fa fa-print" /> Print Now...
</button>
</div>
</div>
</div>
}
@code {
protected override void OnInitialized()
{
JSPrintManager.OnGetPrintersInfo += () => StateHasChanged();
base.OnInitialized();
}
private string[] trays = null;
private string[] papers = null;
private bool builtInDuplexSupport = false;
private bool useDriverDuplex = false;
private void PrinterChanged(string printerName)
{
trays = JSPrintManager.PrintersInfo.FirstOrDefault(p => p.Name == printerName).Trays;
papers = JSPrintManager.PrintersInfo.FirstOrDefault(p => p.Name == printerName).Papers;
builtInDuplexSupport = JSPrintManager.PrintersInfo.FirstOrDefault(p => p.Name == printerName).Duplex;
MyPrinter.PrinterName = printerName;
}
private ClientPrintJob MyCPJ { get; set; } = new();
private InstalledPrinter MyPrinter { get; set; } = new();
private PrintFilePDF MyPdfFile { get; set; } = new();
private void DoPrinting()
{
// Set built-in duplex printing if required
if (builtInDuplexSupport)
{
MyPrinter.Duplex = useDriverDuplex ? Duplex.Default : Duplex.Simplex;
}
// set target printer
MyCPJ.ClientPrinter = MyPrinter;
// set pdf file source...
if (FileFromUrl)
{
MyPdfFile.FileContentType = FileSourceType.URL;
MyPdfFile.FileContent = MyFilePath;
MyPdfFile.FileName = MyFilePath.Substring(MyFilePath.LastIndexOf('/') + 1);
}
else
{
foreach (var fileEntry in loadedFiles)
{
MyPdfFile.FileContentType = FileSourceType.Base64;
MyPdfFile.FileContent = fileEntry.Value;
MyPdfFile.FileName = fileEntry.Key;
}
}
// Add the pdf file to the print job
MyCPJ.Files.Add(MyPdfFile);
// Send job to the client!
JSPrintManager.SendClientPrintJob(MyCPJ);
}
#region File Source Handling
private bool FileFromUrl = false;
private string MyFilePath { get; set; }
private void SetFilePath(string filePath)
{
MyFilePath = filePath;
FileFromUrl = true;
}
private Dictionary<string, byte[]> loadedFiles = new();
private int maxAllowedFiles = 1;
private int maxSizeFile = 5000000; //5MB
private bool isLoading = false;
private int loadingStep = 0;
private async Task LoadFiles(InputFileChangeEventArgs e)
{
isLoading = true;
loadedFiles.Clear();
loadingStep = 0;
var numOfFiles = Math.Min(e.FileCount, maxAllowedFiles);
var i = 1;
foreach (var file in e.GetMultipleFiles(maxAllowedFiles))
{
try
{
await using MemoryStream ms = new();
await file.OpenReadStream(maxSizeFile).CopyToAsync(ms);
loadedFiles.Add(file.Name, ms.ToArray());
loadingStep = (int)(((float)i / (float)numOfFiles) * 100f);
StateHasChanged();
}
catch (Exception ex)
{
}
i++;
}
FileFromUrl = false;
isLoading = false;
}
#endregion
}
`
And Here the code of the programm.cs:
`using BlazorApp3;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Neodynamic.Blazor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add("#app");
builder.RootComponents.Add("head::after");
builder.Services.AddJSPrintManager();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
`
And here from the MainLayout:
`@inherits LayoutComponentBase
@using Neodynamic.Blazor
@Inject JSPrintManager JSPrintManager
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
JSPrintManager.OnStatusChanged += () =>
{
if (JSPrintManager.Status == JSPMWSStatus.Open)
{
JSPrintManager.TryGetPrinters(); //Get printers...
JSPrintManager.TryGetPrintersInfo("", PrinterIcon.Large); //Get printers info...
JSPrintManager.TryGetScanners(); //Get scanners...
}
StateHasChanged();
};
JSPrintManager.Start();
}
base.OnAfterRender(firstRender);
}
}`
Package Neodynamic.Blazor.JSP Version 5.0.22.801 is also installed.
from jsprintmanager-blazor.
And here the failure...
from jsprintmanager-blazor.
Replace this line
myPrintFile.FileContent = fileEntry.Value;
by this one
myPrintFile.FileContent = Convert.ToBase64String(fileEntry.Value);
from jsprintmanager-blazor.
Related Issues (2)
- Feeder Scan Not Working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsprintmanager-blazor.