Dear Team.
I am trying to do a silent printing in asp.net core web api. I have reference the necessary assemblies, i.e system.windows.form from "C:\Windows\Microsoft.NET\Framework64\v4.0.30319". find below code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using EventWebApi;
using EventWebApi.Models;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System.IO;
using Syncfusion.Drawing;
using System.Drawing;
using Syncfusion.Windows.Forms.PdfViewer;
using Syncfusion.Pdf.Parsing;
using System.Windows.Forms;
namespace PrintWebApi.Controllers
{
public async Task CreatePrintPDF()
{
PdfDocument document = new PdfDocument();
/
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
//Draw the text.
graphics.DrawString(participant.FullName.ToUpper(), font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
//Save the PDF document to stream
MemoryStream stream = new MemoryStream();
document.Save(stream);
//If the position is not set to '0' then the PDF will be empty.
stream.Position = 0;
//Close the document.
document.Close(true);
//Defining the ContentType for pdf file
string contentType = "application/pdf";
//Define the file name
string fileName = "NameTag.pdf";
//Creates a FileContentResult object by using the file contents, content type, and file name
PdfViewerControl viewer = new PdfViewerControl(); error at this point : find error below.
viewer.Load(stream);
PrintDialog dialog = new PrintDialog();
dialog.Document = viewer.PrintDocument;
dialog.Document.Print();
return Ok();
}
}
error after executing the api.