Skilled in SEO, content writing, and digital marketing. Completed several years of working in many organizations including multinational companies. I love to learn new things in life that keep me motivated.
As of my last knowledge update in September 2021, Microsoft Edge did not provide a direct API for programmatically printing PDF files from a C# application. However, you could use a workaround by launching Microsoft Edge with the PDF file's URL and then letting the user interact with the browser to print the PDF manually. Here's how you can do it:
using System.Diagnostics;
public void PrintPDFViaEdge(string pdfUrl)
{
try
{
// Create a ProcessStartInfo with the URL to the PDF file
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "msedge.exe", // Use the path to msedge.exe if not in system PATH
Arguments = pdfUrl
};
// Start Microsoft Edge with the PDF URL
Process.Start(psi);
}
catch (Exception ex)
{
// Handle any exceptions (e.g., if Microsoft Edge is not installed)
Console.WriteLine("Error: " + ex.Message);
}
}
In this code:
ProcessStartInfo is used to specify the application to be launched (Microsoft Edge) and the URL of the PDF file you want to open for printing.
Process.Start(psi) is used to start Microsoft Edge with the specified URL.
Please note that this approach relies on the user manually interacting with Microsoft Edge to print the PDF. There is no direct programmatic way to trigger printing from C# code using Microsoft Edge's API.
Additionally, the availability and behavior of this method might change with updates to Microsoft Edge. Always check the latest documentation and APIs provided by Microsoft if you need more advanced control over printing PDFs from your C# application.
Liked By
Write Answer
How to print PDF files via Microsoft Edge in C#?
Join MindStick Community
You have need login or register for voting of answers or question.
Aryan Kumar
27-Sep-2023As of my last knowledge update in September 2021, Microsoft Edge did not provide a direct API for programmatically printing PDF files from a C# application. However, you could use a workaround by launching Microsoft Edge with the PDF file's URL and then letting the user interact with the browser to print the PDF manually. Here's how you can do it:
In this code:
Please note that this approach relies on the user manually interacting with Microsoft Edge to print the PDF. There is no direct programmatic way to trigger printing from C# code using Microsoft Edge's API.
Additionally, the availability and behavior of this method might change with updates to Microsoft Edge. Always check the latest documentation and APIs provided by Microsoft if you need more advanced control over printing PDFs from your C# application.