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
13 changes: 13 additions & 0 deletions .idea/.idea.HTMLToQPDF/.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.HTMLToQPDF/.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.HTMLToQPDF/.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.HTMLToQPDF/.idea/vcs.xml

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

6 changes: 2 additions & 4 deletions HTMLToQPDF.Example/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Windows;

namespace HTMLToQPDF.Example
namespace HTMLToQPDF.Example
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App
{
}
}
13 changes: 7 additions & 6 deletions HTMLToQPDF.Example/HTMLToQPDF.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Assets\web-programming.ico</ApplicationIcon>
<PublishSingleFile>true</PublishSingleFile>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<DebugType>embedded</DebugType>
<LangVersion>14</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,14 +18,14 @@

<ItemGroup>
<PackageReference Include="DevExpress.Mvvm.CodeGenerators" Version="22.1.1" />
<PackageReference Include="DevExpressMvvm" Version="22.1.3" />
<PackageReference Include="Fody" Version="6.6.4">
<PackageReference Include="DevExpressMvvm" Version="24.1.6" />
<PackageReference Include="Fody" Version="6.9.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="HandyControls" Version="3.4.2" />
<PackageReference Include="PropertyChanged.Fody" Version="4.0.4" />
<PackageReference Include="QuestPDF" Version="2023.12.5" />
<PackageReference Include="HandyControls" Version="3.6.0" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" PrivateAssets="All" />
<PackageReference Include="QuestPDF" Version="2025.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions HTMLToQPDF.Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:HTMLToQPDF.Example"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:HTMLToQPDF.Example.ViewModels"
Title="HTMLToQPDF"
Expand All @@ -29,7 +28,7 @@
IsChecked="{Binding CustomStyles}" />
<Button
Margin="5"
Command="{Binding CreatePDFCommand}"
Command="{Binding CreatePdfCommand}"
Content="Create PDF"
Style="{StaticResource ButtonPrimary}" />
</StackPanel>
Expand All @@ -54,7 +53,7 @@
VerticalContentAlignment="Top"
hc:InfoElement.Placeholder="&lt;body&gt; Hello world! &lt;/body&gt;"
AcceptsReturn="True"
Text="{Binding HTML, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding Html, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
</DockPanel>
</Window>
6 changes: 2 additions & 4 deletions HTMLToQPDF.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Windows;

namespace HTMLToQPDF.Example
namespace HTMLToQPDF.Example
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow
{
public MainWindow()
{
Expand Down
35 changes: 13 additions & 22 deletions HTMLToQPDF.Example/Properties/Resources.Designer.cs

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

12 changes: 7 additions & 5 deletions HTMLToQPDF.Example/Utilities/FileDialogHelper.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Microsoft.Win32;

namespace HTMLToQPDF.Example.DialogWindows
namespace HTMLToQPDF.Example.Utilities
{
internal static class FileDialogHelper
{
public static string GetSaveFilePath(string file)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
var saveFileDialog = new SaveFileDialog
{
Filter = "PDF file|*.pdf",
Title = "Save an PDF File",
FileName = file
};

saveFileDialog.Filter = "PDF file|*.pdf";
saveFileDialog.Title = $"Save an PDF File";
saveFileDialog.FileName = file;
saveFileDialog.ShowDialog();

if (saveFileDialog.FileName != "")
Expand Down
8 changes: 5 additions & 3 deletions HTMLToQPDF.Example/Utilities/PDFCreator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using HTMLQuestPDF.Extensions;
using HTMLToQPDF.Extensions;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;

namespace HTMLToQPDF.Example.Utilities
{
internal static class PDFCreator
internal static class PdfCreator
{
public static void Create(string html, string path, bool customStyles)
{
Expand All @@ -19,7 +19,9 @@ public static void Create(string html, string path, bool customStyles)
page.MarginHorizontal(0.5f, Unit.Centimetre);
page.MarginVertical(1f, Unit.Centimetre);

#pragma warning disable CS0618 // Type or member is obsolete
page.DefaultTextStyle(TextStyle.Default.FontFamily("Arial").FontSize(8).Fallback(y => y.FontFamily("Segoe UI Emoji")));
#pragma warning restore CS0618

/* page.DefaultTextStyle(TextStyle.Default
// .Fallback(y => y.FontFamily("MS Reference Sans Serif")
Expand All @@ -30,7 +32,7 @@ public static void Create(string html, string path, bool customStyles)

page.Content().Column(col =>
{
col.Item().HTML(handler =>
col.Item().Html(handler =>
{
if (customStyles)
{
Expand Down
13 changes: 6 additions & 7 deletions HTMLToQPDF.Example/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using DevExpress.Mvvm;
using DevExpress.Mvvm.CodeGenerators;
using HTMLToQPDF.Example.DialogWindows;
using HTMLToQPDF.Example.Properties;
using HTMLToQPDF.Example.Utilities;
using System;
Expand All @@ -11,14 +10,14 @@ namespace HTMLToQPDF.Example.ViewModels
[GenerateViewModel]
public partial class MainWindowViewModel : ViewModelBase
{
public string HTML { get; set; }
public string Html { get; set; }
public string SavePath { get; set; }
public bool CustomStyles { get; set; }

public MainWindowViewModel()
{
HTML = Resources.testHtml;
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Html = Resources.testHtml;
var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
SavePath = Path.Combine(desktop, "example.pdf");
}

Expand All @@ -29,11 +28,11 @@ private void SelectSavePath()
}

[GenerateCommand]
private void CreatePDF()
private void CreatePdf()
{
PDFCreator.Create(HTML, SavePath, CustomStyles);
PdfCreator.Create(Html, SavePath, CustomStyles);
}

private bool CanCreatePDF() => !string.IsNullOrEmpty(HTML);
private bool CanCreatePdf() => !string.IsNullOrEmpty(Html);
}
}
40 changes: 20 additions & 20 deletions HTMLToQPDF/Components/BaseHTMLComponent.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using HtmlAgilityPack;
using HTMLQuestPDF.Extensions;
using HTMLToQPDF.Components;
using HTMLToQPDF.Extensions;
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;

namespace HTMLQuestPDF.Components
namespace HTMLToQPDF.Components
{
internal class BaseHTMLComponent : IComponent
internal class BaseHtmlComponent : IComponent
{
protected readonly HTMLComponentsArgs args;
protected readonly HtmlNode node;
protected readonly HtmlComponentsArgs Args;
protected readonly HtmlNode Node;

public BaseHTMLComponent(HtmlNode node, HTMLComponentsArgs args)
public BaseHtmlComponent(HtmlNode node, HtmlComponentsArgs args)
{
this.node = node;
this.args = args;
Node = node;
Args = args;
}

public void Compose(IContainer container)
{
if (!node.HasContent() || node.Name.ToLower() == "head") return;
if (!Node.HasContent() || Node.Name.Equals("head", StringComparison.CurrentCultureIgnoreCase)) return;

container = ApplyStyles(container);

if (node.ChildNodes.Any())
if (Node.ChildNodes.Count != 0)
{
ComposeMany(container);
}
Expand All @@ -35,7 +34,7 @@ public void Compose(IContainer container)

protected virtual IContainer ApplyStyles(IContainer container)
{
return args.ContainerStyles.TryGetValue(node.Name.ToLower(), out var style) ? style(container) : container;
return Args.ContainerStyles.TryGetValue(Node.Name.ToLower(), out var style) ? style(container) : container;
}

protected virtual void ComposeSingle(IContainer container)
Expand All @@ -47,14 +46,14 @@ protected virtual void ComposeMany(IContainer container)
container.Column(col =>
{
var buffer = new List<HtmlNode>();
foreach (var item in node.ChildNodes)
foreach (var item in Node.ChildNodes)
{
if (item.IsBlockNode() || item.HasBlockElement())
{
ComposeMany(col, buffer);
buffer.Clear();

col.Item().Component(item.GetComponent(args));
col.Item().Component(item.GetComponent(Args));
}
else
{
Expand All @@ -67,13 +66,14 @@ protected virtual void ComposeMany(IContainer container)

private void ComposeMany(ColumnDescriptor col, List<HtmlNode> nodes)
{
if (nodes.Count == 1)
switch (nodes.Count)
{
col.Item().Component(nodes.First().GetComponent(args));
}
else if (nodes.Count > 0)
{
col.Item().Component(new ParagraphComponent(nodes, args));
case 1:
col.Item().Component(nodes.First().GetComponent(Args));
break;
case > 0:
col.Item().Component(new ParagraphComponent(nodes, Args));
break;
}
}
}
Expand Down
Loading