This guide explains how to create a program that uses DsImaging to generate and save to disk a JPEG image with the "Hello, World!" text.
Document Solutions for Imaging assemblies are built for .NET Standard 2.0, and can be used with any target that supports it. In this short tutorial, we show how to build a .NET console application. The tutorial takes you through the steps required to do that in Visual Studio on Windows, or Visual Studio Code on macOS and Linux.
This will add the required references to your application. You can now jump to Adding Code topic below to modify the application so that it generates the JPEG.
$ mkdir ~/MyApp # create a directory for the application$ cd ~/MyApp$ dotnet new console # create a .NET console application with MyApp.csproj and Program.cs files$ dotnet add package DS.Documents.Imaging # add a reference to the package and fetch it<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="DS.Documents.Imaging" Version="9.2.2" /> </ItemGroup></Project>$ cd ~/MyApp$ dotnet run # runs the default appAt this point you should see the "Hello, World!" printed in the terminal window (the default behavior of a new console app). Now modify the application so that it generates the JPEG instead.
using System;using System.Drawing;using System.IO;using GrapeCity.Documents.Drawing;using GrapeCity.Documents.Imaging;using GrapeCity.Documents.Text;
namespace MyApp{ class Program { static void Main(string[] args) { // Create a new GcBitmap: var bmp = new GcBitmap(600, 600, true); // Create a graphics to draw on (should be disposed when no longer needed): using (var g = bmp.CreateGraphics(Color.White)) { // Add a radial gradient: var rc = new RectangleF(0, 0, bmp.Width, bmp.Height); var b = new RadialGradientBrush(Color.White, Color.CadetBlue, new PointF(0.5f, 0.5f), true); g.FillRectangle(rc, b); // Prepare a TextFormat and draw the string using it: var tf = new TextFormat { // NOTE: this assumes that a Resources/Fonts/FreeSerif.ttf font file exists: Font = Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")), FontSize = 40 }; g.DrawString("Hello, World!", tf, rc, TextAlignment.Center, ParagraphAlignment.Center, false); } bmp.SaveAsJpeg("HelloWorld.jpg"); } }}$ cd ~/MyApp$ dotnet run # runs MyAppThat's all it takes to generate a PDF file using DsImaging. The HelloWorld.pdf should now appear in your project directory.
Essentially the same program is implemented by the Hello, World! sample, so you can see it in action:
This concludes this short guide. For more information please see the About page.