Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example for using library in web server.
- Loading branch information
Showing
10 changed files
with
9,691 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using DinkToPdf.Contracts; | ||
using System.IO; | ||
|
||
namespace DinkToPdf.TestWebServer.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ConvertController : Controller | ||
{ | ||
private IConverter _converter; | ||
|
||
public ConvertController(IConverter converter) | ||
{ | ||
_converter = converter; | ||
} | ||
|
||
// GET api/values | ||
[HttpGet] | ||
public IActionResult Get() | ||
{ | ||
var doc = new HtmlToPdfDocument() | ||
{ | ||
GlobalSettings = { | ||
PaperSize = PaperKind.A3, | ||
Orientation = Orientation.Landscape, | ||
}, | ||
|
||
Objects = { | ||
new ObjectSettings() | ||
{ | ||
Page = "http://google.com/", | ||
}, | ||
new ObjectSettings() | ||
{ | ||
Page = "https://github.com/", | ||
|
||
} | ||
} | ||
}; | ||
|
||
byte[] pdf = _converter.Convert(doc); | ||
|
||
|
||
return new FileContentResult(pdf, "application/pdf"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>292a280a-24fd-41d9-867c-058e6ee6028f</ProjectGuid> | ||
<RootNamespace>DinkToPdf.TestWebServer</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace DinkToPdf.TestWebServer | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:50554/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"DinkToPdf.TestWebServer": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "http://localhost:5000/api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using DinkToPdf.Contracts; | ||
|
||
namespace DinkToPdf.TestWebServer | ||
{ | ||
//************************************* IMPORTANT *********************************** | ||
// Copy native library to root folder of your project. From there .NET Core loads native library when native method is called with P/Invoke. You can find latest version of native library https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4. Select appropriate library for your OS and platform (64 or 32 bit). | ||
public class Startup | ||
{ | ||
public Startup(IHostingEnvironment env) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(env.ContentRootPath) | ||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | ||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); | ||
|
||
if (env.IsEnvironment("Development")) | ||
{ | ||
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. | ||
builder.AddApplicationInsightsSettings(developerMode: true); | ||
} | ||
|
||
builder.AddEnvironmentVariables(); | ||
Configuration = builder.Build(); | ||
} | ||
|
||
public IConfigurationRoot Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
// Add converter to DI | ||
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); | ||
// Add framework services. | ||
services.AddApplicationInsightsTelemetry(Configuration); | ||
|
||
services.AddMvc(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | ||
{ | ||
loggerFactory.AddConsole(Configuration.GetSection("Logging")); | ||
loggerFactory.AddDebug(); | ||
|
||
app.UseApplicationInsightsRequestTelemetry(); | ||
|
||
app.UseApplicationInsightsExceptionTelemetry(); | ||
|
||
app.UseMvc(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"dependencies": { | ||
"Microsoft.NETCore.App": { | ||
"version": "1.0.1", | ||
"type": "platform" | ||
}, | ||
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0", | ||
"Microsoft.AspNetCore.Mvc": "1.0.1", | ||
"Microsoft.AspNetCore.Routing": "1.0.1", | ||
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1", | ||
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", | ||
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", | ||
"Microsoft.Extensions.Configuration.Json": "1.0.0", | ||
"Microsoft.Extensions.Logging": "1.0.0", | ||
"Microsoft.Extensions.Logging.Console": "1.0.0", | ||
"Microsoft.Extensions.Logging.Debug": "1.0.0", | ||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", | ||
"Autofac": "4.0.0-rc3-293", | ||
"Autofac.Extensions.DependencyInjection": "4.0.0-rc3-280", | ||
"DinkToPdf": "1.0.7" | ||
}, | ||
|
||
"tools": { | ||
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" | ||
}, | ||
|
||
"frameworks": { | ||
"netcoreapp1.0": { | ||
"imports": [ | ||
"dotnet5.6", | ||
"portable-net45+win8" | ||
] | ||
} | ||
}, | ||
|
||
"buildOptions": { | ||
"emitEntryPoint": true, | ||
"preserveCompilationContext": true | ||
}, | ||
|
||
"runtimeOptions": { | ||
"configProperties": { | ||
"System.GC.Server": true | ||
} | ||
}, | ||
|
||
"publishOptions": { | ||
"include": [ | ||
"wwwroot", | ||
"**/*.cshtml", | ||
"appsettings.json", | ||
"web.config" | ||
] | ||
}, | ||
|
||
"scripts": { | ||
|
||
}, | ||
|
||
"commands": { | ||
"Kestrel": "Microsoft.AspNetCore.Server.Kestrel" | ||
} | ||
} |
Oops, something went wrong.