Skip to content

Commit

Permalink
Implemented new IronPDF Hello World Project
Browse files Browse the repository at this point in the history
Up to date with latest version: 2022.8.8138
  • Loading branch information
michael-ironsoftware committed Aug 19, 2022
1 parent aeec443 commit 4bc5ef4
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.IronPDF-Sample-Project/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.IronPDF-Sample-Project/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.IronPDF-Sample-Project/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.IronPDF-Sample-Project/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions IronPDF-Sample-Project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>IronPDF_Sample_Project</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IronPdf" Version="2022.8.8138" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions IronPDF-Sample-Project.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronPDF-Sample-Project", "IronPDF-Sample-Project.csproj", "{D1E21083-795A-40C4-B9FC-73E505BB0345}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D1E21083-795A-40C4-B9FC-73E505BB0345}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1E21083-795A-40C4-B9FC-73E505BB0345}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1E21083-795A-40C4-B9FC-73E505BB0345}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1E21083-795A-40C4-B9FC-73E505BB0345}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
68 changes: 68 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using IronPdf;
using IronPdf.Engines.Chrome;
using IronPdf.Rendering;

namespace IronPDF_Sample_Project
{
class Program
{
// Example of HTML string to be rendered into a PDF
private const string SampleHtmlString = "<h1>Hello World!</h1><br><p>This is IronPdf.</p>";

static void Main(string[] args)
{
// Get a free license key instantly: https://ironpdf.com/#trial-license
IronPdf.License.LicenseKey = "ENTER-KEY-HERE";

Console.WriteLine("Welcome to the IronPDF `Hello World' Tutorial!");

// Example of an HTML String to PDF
HtmlToPdfExample(SampleHtmlString);

// Example of URL to PDF
UrlToPdfExample("https://getbootstrap.com/");

Console.WriteLine("IronPDF Tutorial Complete! Press any key to exit!");
Console.ReadKey();
}

public static void HtmlToPdfExample(string htmlString)
{
// Start by initializing the Chrome Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render a new PdfDocument using an HTML string
PdfDocument newPdf = renderer.RenderHtmlAsPdf(SampleHtmlString);

// Save new PDF File
newPdf.SaveAs("pdf_from_html.pdf");
}

public static void UrlToPdfExample(string url)
{
// Start by initializing the Chrome Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Set Pdf CssMediaType to Screen to get all the background
renderer.RenderingOptions = new ChromePdfRenderOptions()
{
// Screen vs Print: https://ironpdf.com/tutorials/pixel-perfect-html-to-pdf/#decide-to-use-css-media-type-print-or-screen
CssMediaType = PdfCssMediaType.Screen,
PrintHtmlBackgrounds = true,

// Set Margins
MarginTop = 10,
MarginBottom = 10,
MarginLeft = 10,
MarginRight = 10
};

// Render a new PdfDocument from a URL
PdfDocument newPdf = renderer.RenderUrlAsPdf(url);

// Save new PDF File
newPdf.SaveAs("pdf_from_url.pdf");
}
}
}
Binary file added pdf_from_html.pdf
Binary file not shown.
Binary file added pdf_from_url.pdf
Binary file not shown.

0 comments on commit 4bc5ef4

Please sign in to comment.