ByteScout PDF SDK - C# - Create Invoice Spanning Multiple Page - ByteScout

ByteScout PDF SDK – C# – Create Invoice Spanning Multiple Page

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Create Invoice Spanning Multiple Page

How to create invoice spanning multiple page in C# and ByteScout PDF SDK

Tutorial on how to create invoice spanning multiple page in C#

These source code samples are listed and grouped by their programming language and functions they use. What is ByteScout PDF SDK? It is the SDK for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings. It can help you to create invoice spanning multiple page in your C# application.

Fast application programming interfaces of ByteScout PDF SDK for C# plus the instruction and the code below will help you quickly learn how to create invoice spanning multiple page. In order to implement the functionality, you should copy and paste this code for C# below into your code editor with your app, compile and run your application. Test C# sample code examples whether they respond your needs and requirements for the project.

Trial version of ByteScout PDF SDK can be downloaded for free from our website. It also includes source code samples for C# and other programming languages.

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.NETCore.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> <GenerateAssemblyTrademarkAttribute>false</GenerateAssemblyTrademarkAttribute> <GenerateAssemblyCultureAttribute>false</GenerateAssemblyCultureAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> </PropertyGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <Reference Include="Bytescout.PDF"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\Bytescout PDF SDK\netcoreapp2.0\Bytescout.PDF.dll</HintPath> </Reference> </ItemGroup> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.VS2005.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{474F52FF-3928-44EA-8F6F-379E9DAA23FF}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>InvoiceDemo</RootNamespace> <AssemblyName>InvoiceDemo</AssemblyName> <FileAlignment>512</FileAlignment> <ProductVersion>8.0.50727</ProductVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.0.0.15, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.VS2008.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{474F52FF-3928-44EA-8F6F-379E9DAA23FF}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>InvoiceDemo</RootNamespace> <AssemblyName>InvoiceDemo</AssemblyName> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <ProductVersion>9.0.30729</ProductVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.0.0.15, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.VS2010.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{474F52FF-3928-44EA-8F6F-379E9DAA23FF}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>InvoiceDemo</RootNamespace> <AssemblyName>InvoiceDemo</AssemblyName> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.0.0.15, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.VS2012.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{474F52FF-3928-44EA-8F6F-379E9DAA23FF}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>InvoiceDemo</RootNamespace> <AssemblyName>InvoiceDemo</AssemblyName> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.0.0.15, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.VS2013.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{474F52FF-3928-44EA-8F6F-379E9DAA23FF}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>InvoiceDemo</RootNamespace> <AssemblyName>InvoiceDemo</AssemblyName> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.0.0.15, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

InvoiceDemo.VS2015.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{474F52FF-3928-44EA-8F6F-379E9DAA23FF}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>InvoiceDemo</RootNamespace> <AssemblyName>InvoiceDemo</AssemblyName> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.0.0.15, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="logo.png"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

Program.cs
      
using System; using System.Diagnostics; using Bytescout.PDF; namespace Tables { /// <summary> /// This example demonstrates how to create invoice which can span multiple pages. /// </summary> class Program { #region Global Declarations const int HeightConsumedByTableRow = 20; static int ContentHeightStart = 100; static int ContentHeightEnd = 700; static int HeightUtilized = 100; static int _RowCounter = 1; static Document pdfDocument; static Page page; #endregion static void Main() { #region Declarations and Implementations SolidPen solidPen = new SolidPen(); Brush blackBrush = new SolidBrush(new ColorRGB(0, 0, 0)); Font headerFont = new Font(StandardFonts.TimesBold, 24); Font headerFont2 = new Font(StandardFonts.TimesBold, 16); Font contentFont_12 = new Font(StandardFonts.TimesBold, 12); Font contentFont_10 = new Font(StandardFonts.Times, 10); // Create new document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; #endregion // Add new page AddNewPage(); /* 1. Add Content */ page.Canvas.DrawString("COMPANY NAME", contentFont_12, blackBrush, 50, (HeightUtilized += 20)); page.Canvas.DrawString("Address", contentFont_10, blackBrush, 50, (HeightUtilized += 20)); page.Canvas.DrawString("DATE", contentFont_10, blackBrush, 400, HeightUtilized); page.Canvas.DrawString("Phone, fax", contentFont_10, blackBrush, 50, (HeightUtilized += 20)); page.Canvas.DrawString("INVOICE #", contentFont_10, blackBrush, 400, HeightUtilized); page.Canvas.DrawString("E-mail", contentFont_10, blackBrush, 50, (HeightUtilized += 20)); page.Canvas.DrawString("FOR", contentFont_10, blackBrush, 400, HeightUtilized); // Add some vertical space HeightUtilized += 50; /* 2. Add Table which can span multipage */ Console.WriteLine("Enter the number of rows to add to the table:"); int numberOfRows = Convert.ToInt32(Console.ReadLine()); DrawTable(NumberOfRows: numberOfRows); /* 3. Add Signature */ // Check new page needed for adding signature if (CheckNewPageNeeded(70)) { AddNewPage(); } page.Canvas.DrawString("Signature", contentFont_12, blackBrush, 400, (HeightUtilized + 57)); page.Canvas.DrawLine(solidPen, 450, (HeightUtilized + 70), 570, (HeightUtilized + 70)); /* 4. Add Header And Footer*/ for (int pageIndex = 0; pageIndex < pdfDocument.Pages.Count; pageIndex++) { var curPage = pdfDocument.Pages[pageIndex]; // Add Logo Image imageLogo = new Image("logo.png"); curPage.Canvas.DrawImage(imageLogo, 20, 45, imageLogo.Width / 2, imageLogo.Height / 2); // Add requisites curPage.Canvas.DrawString("INVOICE", headerFont, blackBrush, 450, 55); // Add Page Number curPage.Canvas.DrawLine(solidPen, 20, 750, 590, 750); curPage.Canvas.DrawString({code}quot;Page: {pageIndex + 1} of {pdfDocument.Pages.Count}", contentFont_10, blackBrush, 30, 760); } // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } /// <summary> /// Checks whether new page is needed /// </summary> /// <param name="expectedHeight"></param> /// <returns></returns> static bool CheckNewPageNeeded(int expectedHeight) { return (HeightUtilized + expectedHeight) > ContentHeightEnd; } /// <summary> /// Adds new page, and also set height utilized /// </summary> static void AddNewPage() { // Add page page = new Page(PaperFormat.Letter, PaperOrientation.Portrait); pdfDocument.Pages.Add(page); // Reset Height Utilized HeightUtilized = ContentHeightStart; } /// <summary> /// Draw table /// </summary> /// <param name="NumberOfRows"></param> static void DrawTable(int NumberOfRows) { while (NumberOfRows > 0) { // Get number of rows can be added in current page var NumberOfRowsCanBeAddedInCurrentPage = GetNumberOfRowsCanBeAddedInCurrentPage(); if (NumberOfRowsCanBeAddedInCurrentPage > 0) { var table = GetTable(Math.Min(NumberOfRows, NumberOfRowsCanBeAddedInCurrentPage)); page.Canvas.DrawTable(table, 50, HeightUtilized); // Update Height Utilized HeightUtilized += (Math.Min(NumberOfRows, NumberOfRowsCanBeAddedInCurrentPage) * HeightConsumedByTableRow); NumberOfRows -= Math.Min(NumberOfRows, NumberOfRowsCanBeAddedInCurrentPage); } else { // Add new page AddNewPage(); } } } /// <summary> /// Get Table Header with Content /// </summary> /// <param name="NumberOfRows"></param> /// <returns></returns> private static Table GetTable(int NumberOfRows) { Font fontTableHeader = new Font(StandardFonts.TimesBold, 11); Font fontTableRow = new Font(StandardFonts.Times, 10); Table table = new Table(); /* 1. Add Table Header */ table.Columns.Add(new TableColumn("Description", "Description")); table.Columns[0].Width = 220; table.Columns[0].Font = fontTableHeader; table.Columns[0].TextFormat.HorizontalAlign = HorizontalAlign.Left; table.Columns.Add(new TableColumn("Quantity", "Quantity")); table.Columns[1].Width = 80; table.Columns[1].Font = fontTableHeader; table.Columns[1].TextFormat.HorizontalAlign = HorizontalAlign.Right; table.Columns.Add(new TableColumn("Price", "Price")); table.Columns[2].Width = 100; table.Columns[2].Font = fontTableHeader; table.Columns[2].TextFormat.HorizontalAlign = HorizontalAlign.Right; table.Columns.Add(new TableColumn("Amount", "Amount")); table.Columns[3].Width = 120; table.Columns[3].Font = fontTableHeader; table.Columns[3].TextFormat.HorizontalAlign = HorizontalAlign.Right; /* 2. Add Table Content */ for (int index = 0; index < NumberOfRows; index++) { // Create new row and set its background color TableRow row = table.NewRow(); // Set row header text row["Description"].Text = {code}quot;Description for item - {_RowCounter++}"; row["Description"].Font = fontTableRow; row["Description"].TextFormat.HorizontalAlign = HorizontalAlign.Left; row["Quantity"].Text = "###"; row["Quantity"].Font = fontTableRow; row["Quantity"].TextFormat.HorizontalAlign = HorizontalAlign.Right; row["Price"].Text = "$.
<!-- code block begin -->
    <h5>
      <strong>{codeFileName}</strong>
    </h5>
    
    <pre>
      <div class="code-editor {codeExtension}">{code}</div>
    </pre>

    <p>
        Try it today: <a class="btn btn-sm btn-default" href="https://bytescout.com/download/web-installer">Get 60 Day Free Trial</a> or <a class="btn btn-lg btn-primary" href="https://app.pdf.co/signup">sign up for Web API</a> 
    </p>    
            
<!-- code block end -->    

quot;;
row["Price"].Font = fontTableRow;
row["Price"].TextFormat.HorizontalAlign = HorizontalAlign.Right;

row["Amount"].Text = "$.

<!-- code block begin -->
    <h5>
      <strong>{codeFileName}</strong>
    </h5>
    
    <pre>
      <div class="code-editor {codeExtension}">{code}</div>
    </pre>

    <p>
        Try it today: <a class="btn btn-sm btn-default" href="https://bytescout.com/download/web-installer">Get 60 Day Free Trial</a> or <a class="btn btn-lg btn-primary" href="https://app.pdf.co/signup">sign up for Web API</a> 
    </p>    
            
<!-- code block end -->    

quot;;
row["Amount"].Font = fontTableRow;
row["Amount"].TextFormat.HorizontalAlign = HorizontalAlign.Right;

// Add the row to the table
table.Rows.Add(row);
}

return table;
}

/// <summary>
/// Get number of rows can be added in current page
/// </summary>
/// <returns></returns>
private static int GetNumberOfRowsCanBeAddedInCurrentPage()
{
return (ContentHeightEnd - HeightUtilized) / HeightConsumedByTableRow;
}

}
}

Try it today: Get 60 Day Free Trial or sign up for Web API

MORE INFORMATION

Get 60 Day Free Trial or Visit ByteScout PDF SDK page

Explore ByteScout PDF SDK documentation

WEB API VERSION

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next