We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Asp.net core web api silent printing with syncfusion.pdfviewer.windows

Thread ID:

Created:

Updated:

Platform:

Replies:

150726 Jan 16,2020 10:09 PM UTC Jan 20,2020 02:20 PM UTC WinForms 4
loading
Tags: PdfViewer
Ali
Asked On January 16, 2020 10:09 PM UTC

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.


Deepak Gunasekaran [Syncfusion]
Replied On January 17, 2020 03:48 PM UTC

Hi Ali, 

Based on the exception details, we could see that the Accessibiity.dll is missing to be referred in the application which caused the issue. Kindly ensure whether the Accessibility.dll available in the location “C:\Windows\Microsoft.NET\Framework64\v4.0.30319” and it is referred properly in the project. You may refer the framework dependencies directly or install via nuget packages to avoid the kind of errors in the application.   

We have created a workable sample to perform silent printing with your code snippet in the ASP.Net core web API using Syncfusion.PdfViewer.Windows and it can be downloaded from the below location. 
 
Please try the sample and let us know whether it meets your requirement. 
 
Regards, 
Deepak G 


Ali
Replied On January 18, 2020 01:48 PM UTC

Dear Deepak.

Thank you for the solution. Everything is working perfectly now.

However, I want to set the printer page size and orientation, since the page size I set when creating the pdf is different from the print out.

Regards.

Uthandaraja Selva Sundara Kani [Syncfusion]
Replied On January 20, 2020 12:53 PM UTC

Hi Ali, 
 
Currently we are checking on this and we will update you shortly. 
 
Regards, 
Uthandaraja S

Uthandaraja Selva Sundara Kani [Syncfusion]
Replied On January 20, 2020 02:20 PM UTC

Hi Ali, 
 
Thanks for your patience. 
 
We can achieve the requirement of customize the page orientation and size using the PrintDocument.DefaultPageSettings API. Please find the code snippet below to customize the page orientation of printing document, 
 
 
PrintDialog dialog = new PrintDialog(); 
 
dialog.Document = pdfViewerControl.PrintDocument; 
 
//Set the page orientation. 
dialog.Document.DefaultPageSettings.Landscape = true; 
 
 
Please let us know if you need further assistance. 
 
Regards, 
Uthandaraja S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon