Create a screenshot and save as PDF using C#

A screenshot, also known as a screen capture, or screen grab, is a digital image that shows the contents of a computer display or another device (phone, tablet). The screenshot is created by the operating system or software running on the device powering the display.

This means that the image will show your desktop, open applications, email with correspondence, which tabs are open on your computer or laptop, which document you are currently viewing.

By default, the screenshot covers the entire page on the screen. Programmatically, you can set the desired area or crop the image in a third-party application.

Screenshots are used for technical assistance in the support service, information exchange between employees on the homework and telework. Also, screenshots are often used to confirm payment of bills, personal or business correspondence, indicate the location on the map, pictures from surveillance cameras.

The code example below shows how to create a screenshot and save it to PDF format.

           using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using SautinSoft;

namespace Sample
    class Program
        static void Main(string[] args)

            // Convert Screenshot to PNG file.
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            string screen = @"screenshot.png";

            // Create screen with 1920*1040 px.
            Rectangle rect = new Rectangle(0, 0, 1920, 1040);
            Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bmp);
            g.CopyFromScreen(rect.Right, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
            bmp.Save(screen, ImageFormat.Png);

            // Create object of Image class from file.
            System.Drawing.Image image = Image.FromFile(screen);

            byte[] imgBytes = null;

            using (MemoryStream ms = new System.IO.MemoryStream())
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                imgBytes = ms.ToArray();

            // Convert image stream to PDF file.
            FileInfo outFile = new FileInfo(@"Result.pdf");
            int ret = v.ConvertImageStreamToPDFFile(imgBytes, outFile.FullName);
            if (ret == 0)
                // Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName) { UseShellExecute = true });

The result is a screenshot of the desktop in PNG and PDF formats for further use.

Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:

Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.