Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PDFiumSharp/PDFium.tt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ var Imports = new[] {
Documentation = new string[] { "<seealso cref='PdfPage.Size'/>" },
Attributes = new string[] { } },

new { Method = "void FPDF_RenderPage(IntPtr dc, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, PageOrientations rotation, RenderingFlags flags)",
AccessModifier = "public",
Documentation = new string[] { "<seealso cref='PdfPage.Render'/>" },
Attributes = new string[] { } },

new { Method = "void FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, PageOrientations rotation, RenderingFlags flags)",
AccessModifier = "public",
Documentation = new string[] { "<seealso cref='PdfPage.Render'/>" },
Expand Down
15 changes: 15 additions & 0 deletions PDFiumSharp/PdfPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ public PageOrientations Orientation
internal static PdfPage Load(PdfDocument doc, int index) => new PdfPage(doc, PDFium.FPDF_LoadPage(doc.Handle, index), index);
internal static PdfPage New(PdfDocument doc, int index, double width, double height) => new PdfPage(doc, PDFium.FPDFPage_New(doc.Handle, index, width, height), index);

/// <summary>
/// Renders the page to a device context (dc)
/// </summary>
/// <param name="renderTarget">The bitmap to which the page is to be rendered.</param>
/// <param name="rectDest">The destination rectangle in <paramref name="renderTarget"/>.</param>
/// <param name="orientation">The orientation at which the page is to be rendered.</param>
/// <param name="flags">The flags specifying how the page is to be rendered.</param>
public void Render(IntPtr renderTarget, (int left, int top, int width, int height) rectDest, PageOrientations orientation = PageOrientations.Normal, RenderingFlags flags = RenderingFlags.None)
{
if (renderTarget == IntPtr.Zero)
throw new ArgumentNullException(nameof(renderTarget));

PDFium.FPDF_RenderPage(renderTarget, this.Handle, rectDest.left, rectDest.top, rectDest.width, rectDest.height, orientation, flags);
}

/// <summary>
/// Renders the page to a <see cref="PDFiumBitmap"/>
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Samples/Test.Print/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
43 changes: 43 additions & 0 deletions Samples/Test.Print/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PDFiumSharp;
using System.IO;

using System.Drawing;
using System.Drawing.Printing;

namespace TestPrint
{
class Program
{

static void Main(string[] args)
{
using (var doc = new PdfDocument("TestDoc.pdf", "password"))
{
PrintDocument printDoc = new PrintDocument();
//printDoc.PrinterSettings.PrinterName = "Some Printer Name"; // Use a named printer rather than default
printDoc.PrintController = new StandardPrintController(); // Use StandardPrintController to prevent "page I of N" box being shown in WIndows
int i = 0;
printDoc.PrintPage += new PrintPageEventHandler((sender, ev) => {
if (i < doc.Pages.Count) {
PdfPage page = doc.Pages[i];
ev.Graphics.PageUnit = GraphicsUnit.Pixel;
Rectangle r = Rectangle.Round(ev.Graphics.VisibleClipBounds);
page.Render(ev.Graphics.GetHdc(), (r.Left, r.Top, r.Width, r.Height), PageOrientations.Normal, RenderingFlags.Printing);
}
i++;
if (i >= doc.Pages.Count)
ev.HasMorePages = false;
else
ev.HasMorePages = true;
});
printDoc.Print();
}
Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions Samples/Test.Print/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Test.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Test.Console")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c07538e4-238c-42ac-bc19-8afa66bd6bc2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
82 changes: 82 additions & 0 deletions Samples/Test.Print/Test.Print.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{ADDA41B4-261D-416B-B2BB-5363DF5A621C}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Test.Print</RootNamespace>
<AssemblyName>Test.Print</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</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>
<Prefer32Bit>false</Prefer32Bit>
</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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\TestDoc.pdf">
<Link>TestDoc.pdf</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\Nuget\pdfium_x64.dll">
<Link>pdfium_x64.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\Nuget\pdfium_x86.dll">
<Link>pdfium_x86.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\PDFiumSharp\PDFiumSharp.csproj">
<Project>{782d0c5a-2a13-480c-af88-6dadc726566e}</Project>
<Name>PDFiumSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>