ByteScout Premium Suite - C# - Print pdf with pdf renderer sdk - ByteScout

ByteScout Premium Suite – C# – Print pdf with pdf renderer sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout Premium Suite – C# – Print pdf with pdf renderer sdk

How to print pdf with pdf renderer sdk in C# and ByteScout Premium Suite

Step-by-step tutorial on how to print pdf with pdf renderer sdk in C#

Source code documentation samples give simple and easy method to install a needed feature into your application. ByteScout Premium Suite can print pdf with pdf renderer sdk. It can be applied from C#. ByteScout Premium Suite is the set that includes 12 SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording.

The following code snippet for ByteScout Premium Suite works best when you need to quickly print pdf with pdf renderer sdk in your C# application. Simply copy and paste in your C# project or application you and then run your app! Complete and detailed tutorials and documentation are available along with installed ByteScout Premium Suite if you’d like to learn more about the topic and the details of the API.

You can download free trial version of ByteScout Premium Suite from our website to see and try many others source code samples for C#.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Form1.Designer.cs
      
namespace PrintPDF { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.printDocument1 = new System.Drawing.Printing.PrintDocument(); this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog(); this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog(); this.printDialog1 = new System.Windows.Forms.PrintDialog(); this.buttonPageSetup = new System.Windows.Forms.Button(); this.buttonPrintPreview = new System.Windows.Forms.Button(); this.buttonPrint = new System.Windows.Forms.Button(); this.SuspendLayout(); // // printDocument1 // this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage); // // printPreviewDialog1 // this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0); this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0); this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300); this.printPreviewDialog1.Document = this.printDocument1; this.printPreviewDialog1.Enabled = true; this.printPreviewDialog1.Icon = ((System.Drawing.Icon) (resources.GetObject("printPreviewDialog1.Icon"))); this.printPreviewDialog1.Name = "printPreviewDialog1"; this.printPreviewDialog1.UseAntiAlias = true; this.printPreviewDialog1.Visible = false; // // pageSetupDialog1 // this.pageSetupDialog1.Document = this.printDocument1; // // printDialog1 // this.printDialog1.Document = this.printDocument1; this.printDialog1.UseEXDialog = true; // // buttonPageSetup // this.buttonPageSetup.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.buttonPageSetup.Location = new System.Drawing.Point(12, 12); this.buttonPageSetup.Name = "buttonPageSetup"; this.buttonPageSetup.Size = new System.Drawing.Size(253, 41); this.buttonPageSetup.TabIndex = 0; this.buttonPageSetup.Text = "Page Setup"; this.buttonPageSetup.UseVisualStyleBackColor = true; this.buttonPageSetup.Click += new System.EventHandler(this.buttonPageSetup_Click); // // buttonPrintPreview // this.buttonPrintPreview.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.buttonPrintPreview.Location = new System.Drawing.Point(12, 59); this.buttonPrintPreview.Name = "buttonPrintPreview"; this.buttonPrintPreview.Size = new System.Drawing.Size(253, 41); this.buttonPrintPreview.TabIndex = 1; this.buttonPrintPreview.Text = "Print Preview"; this.buttonPrintPreview.UseVisualStyleBackColor = true; this.buttonPrintPreview.Click += new System.EventHandler(this.buttonPrintPreview_Click); // // buttonPrint // this.buttonPrint.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.buttonPrint.Location = new System.Drawing.Point(12, 106); this.buttonPrint.Name = "buttonPrint"; this.buttonPrint.Size = new System.Drawing.Size(253, 41); this.buttonPrint.TabIndex = 2; this.buttonPrint.Text = "Print"; this.buttonPrint.UseVisualStyleBackColor = true; this.buttonPrint.Click += new System.EventHandler(this.buttonPrint_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(277, 161); this.Controls.Add(this.buttonPrint); this.Controls.Add(this.buttonPrintPreview); this.Controls.Add(this.buttonPageSetup); this.Name = "Form1"; this.Text = "Print PDF"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion private System.Drawing.Printing.PrintDocument printDocument1; private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1; private System.Windows.Forms.PageSetupDialog pageSetupDialog1; private System.Windows.Forms.PrintDialog printDialog1; private System.Windows.Forms.Button buttonPageSetup; private System.Windows.Forms.Button buttonPrintPreview; private System.Windows.Forms.Button buttonPrint; } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Form1.cs
      
using System; using System.Drawing; using System.Windows.Forms; using Bytescout.PDFRenderer; namespace PrintPDF { public partial class Form1 : Form { private string _document = @"multipage.pdf"; readonly RasterRenderer _rasterRenderer = null; private int _page = 0; public Form1() { InitializeComponent(); // Create an instance of Bytescout.PDFRenderer.RasterRenderer object and register it. _rasterRenderer = new RasterRenderer(); _rasterRenderer.RegistrationName = "demo"; _rasterRenderer.RegistrationKey = "demo"; } private void Form1_Load(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; try { // Load PDF document _rasterRenderer.LoadDocumentFromFile(_document); } catch (Exception exception) { MessageBox.Show("Could not open PDF document.\n\n" + exception.Message); } finally { Cursor = Cursors.Default; } } private void buttonPageSetup_Click(object sender, EventArgs e) { // Set landscape orientation if needed RectangleF pageRectangle = _rasterRenderer.GetPageRectangle(0); if (pageRectangle.Width > pageRectangle.Height) pageSetupDialog1.PageSettings.Landscape = true; pageSetupDialog1.ShowDialog(); } private void buttonPrintPreview_Click(object sender, EventArgs e) { _page = 0; printPreviewDialog1.Width = 800; printPreviewDialog1.Height = 600; printPreviewDialog1.ShowDialog(); } private void buttonPrint_Click(object sender, EventArgs e) { if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Cursor = Cursors.WaitCursor; try { // For the best quality set the rendering resolution equal to the printer resolution float renderingResolution = e.PageSettings.PrinterResolution.X; // Render page to image using (Image image = _rasterRenderer.GetImage(_page, renderingResolution)) { // Fit image into the print rectangle keeping the aspect ratio Rectangle printRect = e.MarginBounds; float ratio = printRect.Width / (float) image.Width; int width = printRect.Width; int height = (int) (image.Height * ratio); if (height > printRect.Height) { ratio = printRect.Height / (float) image.Height; width = (int) (image.Width * ratio); height = printRect.Height; } // Draw image on device e.Graphics.DrawImage(image, new Rectangle(printRect.X, printRect.Y, width, height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); } if (_page < _rasterRenderer.GetPageCount() - 1) { _page++; e.HasMorePages = true; } } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { Cursor = Cursors.Default; } } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Program.cs
      
using System; using System.Collections.Generic; using System.Windows.Forms; namespace PrintPDF { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next