- Demo
- App.xaml
- App.xaml.cs
- App.xaml.vb
- MainWindow.xaml
- MainWindow.xaml.cs
- MainWindow.xaml.vb
The sample demonstrates how to get started with Spire.PDF for WPF.
<Application x:Class="HelloWorld_PDF_WPF.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> </Application.Resources> </Application>
using System.Windows; namespace HelloWorld_PDF_WPF { /// /// Interaction logic for App.xaml /// public partial class App : Application { } }
Namespace HelloWorld_PDF_WPF ''' ''' Interaction logic for App.xaml ''' Partial Public Class App Inherits Application End Class End Namespace
<Window x:Class="HelloWorld_PDF_WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="Run" Height="23" HorizontalAlignment="Left" Margin="394,266,0,0" Name="btn1" VerticalAlignment="Top" Width="75" Click="btn1_Click" /> <TextBlock Height="35" HorizontalAlignment="Left" Margin="12,142,0,0" Name="textBlock1" Text="This sample demonstrates how to use Spire.Pdf for WPF" VerticalAlignment="Top" Width="479" FontSize="14" FontStyle="Oblique" Foreground="#FFF51919" FontWeight="Bold" /> </Window> </UserControl>
using System.Windows; using Spire.Pdf; using Spire.Pdf.Graphics; namespace HelloWorld_PDF_WPF { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void btn1_Click(object sender, RoutedEventArgs e) { //create a new pdf document PdfDocument pdfDoc = new PdfDocument(); //add one blank page PdfPageBase page = pdfDoc.Pages.Add(); //draw a string on the blank page PdfFont font = new PdfFont(PdfFontFamily.Courier, 14f); page.Canvas.DrawString("This sample demonstrates how to use Spire.Pdf for WPF!", font, PdfBrushes.Blue, new System.Drawing.PointF(0, 20f)); //save the pdf document pdfDoc.SaveToFile(@"..\..\sample.pdf"); //launch the pdf document System.Diagnostics.Process.Start(@"..\..\sample.pdf"); } } }
Imports Spire.Pdf Imports Spire.Pdf.Graphics Namespace HelloWorld_PDF_WPF ''' ''' Interaction logic for MainWindow.xaml ''' Partial Public Class MainWindow Inherits Window Public Sub New() InitializeComponent() End Sub Private Sub btn1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) 'create a new pdf document Dim pdfDoc As New PdfDocument() 'add one blank page Dim page As PdfPageBase = pdfDoc.Pages.Add() 'draw a string on the blank page Dim font As New PdfFont(PdfFontFamily.Courier, 14f) page.Canvas.DrawString("This sample demonstrates how to use Spire.Pdf for WPF!", font, PdfBrushes.Blue, New PointF(0, 20f)) 'save the pdf document pdfDoc.SaveToFile("..\..\sample.pdf") 'launch the pdf document Process.Start("..\..\sample.pdf") End Sub End Class End Namespace