Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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: 4 additions & 1 deletion .github/workflows/DFe.NET_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
dotnet pack -o ${{ github.workspace }} -v minimal -c Release -p:NuspecProperties=version=${{ steps.date.outputs.date }} -p:PackageVersion=${{ steps.date.outputs.date }} NuGet\Zeus.Net.MDFe\Zeus.Net.MDFe.csproj
dotnet pack -o ${{ github.workspace }} -v minimal -c Release -p:NuspecProperties=version=${{ steps.date.outputs.date }} -p:PackageVersion=${{ steps.date.outputs.date }} NuGet\Zeus.Net.CTe\Zeus.Net.CTe.csproj
dotnet pack -o ${{ github.workspace }} -v minimal -c Release -p:NuspecProperties=version=${{ steps.date.outputs.date }} -p:PackageVersion=${{ steps.date.outputs.date }} NFe.Danfe.Html\NFe.Danfe.Html.csproj
dotnet pack -o ${{ github.workspace }} -v minimal -c Release -p:NuspecProperties=version=${{ steps.date.outputs.date }} -p:PackageVersion=${{ steps.date.outputs.date }} NFe.Danfe.QuestPdf\NFe.Danfe.QuestPdf.csproj
dotnet pack -o ${{ github.workspace }} -v minimal -c Release -p:NuspecProperties=version=${{ steps.date.outputs.date }} -p:PackageVersion=${{ steps.date.outputs.date }} NFe.Danfe.PdfClown\NFe.Danfe.PdfClown.csproj

- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -132,11 +134,12 @@ jobs:
-d '{
"tag_name": "${{ needs.build.outputs.version }}",
"name": "${{ needs.build.outputs.version }}",
"body": "Esta é a release da versão ${{ needs.build.outputs.version }} do Zeus DFe.NET.\n\n### Links dos pacotes no NuGet:\n- [Zeus.NFe.NFCe](https://www.nuget.org/packages/Zeus.Net.NFe.NFCe/${{ needs.build.outputs.version }})\n- [Zeus.MDFe](https://www.nuget.org/packages/Zeus.Net.MDFe/${{ needs.build.outputs.version }})\n- [Zeus.CTe](https://www.nuget.org/packages/Zeus.Net.CTe/${{ needs.build.outputs.version }})\n- [Zeus.NFe.Danfe.Html](https://www.nuget.org/packages/Zeus.Net.NFe.Danfe.Html/${{ needs.build.outputs.version }})",
"body": "Esta é a release da versão ${{ needs.build.outputs.version }} do Zeus DFe.NET.\n\n### Links dos pacotes no NuGet:\n- [Zeus.NFe.NFCe](https://www.nuget.org/packages/Zeus.Net.NFe.NFCe/${{ needs.build.outputs.version }})\n- [Zeus.MDFe](https://www.nuget.org/packages/Zeus.Net.MDFe/${{ needs.build.outputs.version }})\n- [Zeus.CTe](https://www.nuget.org/packages/Zeus.Net.CTe/${{ needs.build.outputs.version }})\n- [Zeus.NFe.Danfe.Html](https://www.nuget.org/packages/Zeus.Net.NFe.Danfe.Html/${{ needs.build.outputs.version }})\n- [Zeus.NFe.Danfe.QuestPdf](https://www.nuget.org/packages/Zeus.Net.NFe.Danfe.QuestPdf/${{ needs.build.outputs.version }})\n- [Zeus.NFe.Danfe.PdfClown](https://www.nuget.org/packages/Zeus.Net.NFe.Danfe.PdfClown/${{ needs.build.outputs.version }})",
"draft": false,
"prerelease": false
}' \
https://api.github.com/repos/${{ github.repository }}/releases


- name: Discord notification
continue-on-error: true
Expand Down
8 changes: 8 additions & 0 deletions NFe.Danfe.AppTeste.PdfClown/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="NFe.Danfe.AppTeste.PdfClown.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
41 changes: 41 additions & 0 deletions NFe.Danfe.AppTeste.PdfClown/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/********************************************************************************/
/* Projeto: Biblioteca ZeusNFe */
/* Biblioteca C# para emissão de Nota Fiscal Eletrônica - NFe e Nota Fiscal de */
/* Consumidor Eletrônica - NFC-e (http://www.nfe.fazenda.gov.br) */
/* */
/* Direitos Autorais Reservados (c) 2014 Adenilton Batista da Silva */
/* Zeusdev Tecnologia LTDA ME */
/* */
/* Você pode obter a última versão desse arquivo no GitHub */
/* localizado em https://github.com/adeniltonbs/Zeus.Net.NFe.NFCe */
/* */
/* */
/* Esta biblioteca é software livre; você pode redistribuí-la e/ou modificá-la */
/* sob os termos da Licença Pública Geral Menor do GNU conforme publicada pela */
/* Free Software Foundation; tanto a versão 2.1 da Licença, ou (a seu critério) */
/* qualquer versão posterior. */
/* */
/* Esta biblioteca é distribuída na expectativa de que seja útil, porém, SEM */
/* NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU */
/* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral Menor*/
/* do GNU para mais detalhes. (Arquivo LICENÇA.TXT ou LICENSE.TXT) */
/* */
/* Você deve ter recebido uma cópia da Licença Pública Geral Menor do GNU junto*/
/* com esta biblioteca; se não, escreva para a Free Software Foundation, Inc., */
/* no endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. */
/* Você também pode obter uma copia da licença em: */
/* http://www.opensource.org/licenses/lgpl-license.php */
/* */
/* Zeusdev Tecnologia LTDA ME - [email protected] */
/* http://www.zeusautomacao.com.br/ */
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
/********************************************************************************/

namespace NFe.Danfe.AppTeste.PdfClown;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
}
10 changes: 10 additions & 0 deletions NFe.Danfe.AppTeste.PdfClown/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
34 changes: 34 additions & 0 deletions NFe.Danfe.AppTeste.PdfClown/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Window x:Class="NFe.Danfe.AppTeste.PdfClown.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Gerador de DANFE NF-e" Height="400" Width="400">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<GroupBox Header="Logomarca" Margin="0,0,0,15">
<StackPanel Orientation="Horizontal">
<Border BorderThickness="1" BorderBrush="Gray" Width="100" Height="100" Margin="5">
<Image x:Name="LogoEmitente" Stretch="Uniform"/>
</Border>
<StackPanel Margin="10,0,0,0" VerticalAlignment="Center">
<Button Content="Carregar Logo" Width="120" Click="BtnCarregarLogo_Click" Margin="0,0,0,5"/>
<Button Content="Remover Logo" Width="120" Click="BtnRemoverLogo_Click"/>
</StackPanel>
</StackPanel>
</GroupBox>

<Button Width="250"
Padding="10"
Click="Btn_GerarDanfe_Click">
<TextBlock TextWrapping="Wrap"
TextAlignment="Center"
Text="Selecionar XML e gerar DANFE NF-e"/>
</Button>
</StackPanel>
</Grid>
</Window>
177 changes: 177 additions & 0 deletions NFe.Danfe.AppTeste.PdfClown/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/********************************************************************************/
/* Projeto: Biblioteca ZeusNFe */
/* Biblioteca C# para emissão de Nota Fiscal Eletrônica - NFe e Nota Fiscal de */
/* Consumidor Eletrônica - NFC-e (http://www.nfe.fazenda.gov.br) */
/* */
/* Direitos Autorais Reservados (c) 2014 Adenilton Batista da Silva */
/* Zeusdev Tecnologia LTDA ME */
/* */
/* Você pode obter a última versão desse arquivo no GitHub */
/* localizado em https://github.com/adeniltonbs/Zeus.Net.NFe.NFCe */
/* */
/* */
/* Esta biblioteca é software livre; você pode redistribuí-la e/ou modificá-la */
/* sob os termos da Licença Pública Geral Menor do GNU conforme publicada pela */
/* Free Software Foundation; tanto a versão 2.1 da Licença, ou (a seu critério) */
/* qualquer versão posterior. */
/* */
/* Esta biblioteca é distribuída na expectativa de que seja útil, porém, SEM */
/* NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU */
/* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral Menor*/
/* do GNU para mais detalhes. (Arquivo LICENÇA.TXT ou LICENSE.TXT) */
/* */
/* Você deve ter recebido uma cópia da Licença Pública Geral Menor do GNU junto*/
/* com esta biblioteca; se não, escreva para a Free Software Foundation, Inc., */
/* no endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. */
/* Você também pode obter uma copia da licença em: */
/* http://www.opensource.org/licenses/lgpl-license.php */
/* */
/* Zeusdev Tecnologia LTDA ME - [email protected] */
/* http://www.zeusautomacao.com.br/ */
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
/********************************************************************************/

using Microsoft.Win32;
using NFe.Danfe.PdfClown;
using NFe.Danfe.PdfClown.Modelo;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace NFe.Danfe.AppTeste.PdfClown
{
public partial class MainWindow : Window
{
private byte[]? _logoMarcaBytes;

public MainWindow()
{
InitializeComponent();
}

private void BtnCarregarLogo_Click(object sender, RoutedEventArgs e)
{
var caminhoImagem = SelecionarImagem();
if (string.IsNullOrEmpty(caminhoImagem))
return;

try
{
var bitmap = CarregarImagem(caminhoImagem);
LogoEmitente.Source = bitmap;
_logoMarcaBytes = ConverterParaJpegBytes(bitmap);
}
catch (Exception ex)
{
MessageBox.Show($"Erro ao carregar logomarca: {ex.Message}", "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

private void BtnRemoverLogo_Click(object sender, RoutedEventArgs e)
{
_logoMarcaBytes = null;
LogoEmitente.Source = null;
}

private void Button_GerarDanfe_Click(object sender, RoutedEventArgs e)
{
var caminhoXml = SelecionarXml();
if (string.IsNullOrEmpty(caminhoXml))
return;

try
{
var xml = File.ReadAllText(caminhoXml);
var pdfBytes = GerarDanfeZion(xml, _logoMarcaBytes);
AbrirPdfTemporario(pdfBytes);
}
catch (Exception ex)
{
MessageBox.Show($"Erro ao gerar DANFE: {ex.Message}", "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

private static string? SelecionarImagem()
{
var dialog = new OpenFileDialog
{
Filter = "Imagens (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg",
Title = "Selecione uma imagem para a logomarca"
};

var result = dialog.ShowDialog() == true ? dialog.FileName : null;
return result;
}

private static string? SelecionarXml()
{
var dialog = new OpenFileDialog
{
Filter = "Arquivos XML (*.xml)|*.xml",
Title = "Selecione o XML da NF-e"
};

return dialog.ShowDialog() == true ? dialog.FileName : null;
}

private static BitmapImage CarregarImagem(string caminho)
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.UriSource = new Uri(caminho);
bitmap.EndInit();
return bitmap;
}

private static byte[] ConverterParaJpegBytes(BitmapImage bitmap)
{
var imageControl = new Image
{
Source = bitmap,
Width = bitmap.PixelWidth,
Height = bitmap.PixelHeight
};

imageControl.Measure(new Size(bitmap.PixelWidth, bitmap.PixelHeight));
imageControl.Arrange(new Rect(new Size(bitmap.PixelWidth, bitmap.PixelHeight)));

var render = new RenderTargetBitmap(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
render.Render(imageControl);

var encoder = new JpegBitmapEncoder { QualityLevel = 100 };
encoder.Frames.Add(BitmapFrame.Create(render));

using var stream = new MemoryStream();
encoder.Save(stream);
return stream.ToArray();
}

private static byte[] GerarDanfeZion(string xmlNfeProc, byte[]? logoMarca)
{
xmlNfeProc = xmlNfeProc.Replace("\u00a0", " ");
var model = DanfeViewModelCreator.CriarDeStringXml(xmlNfeProc);

using var pdfStream = new MemoryStream();
using var danfe = new DanfeDoc(model);

if (logoMarca != null)
{
using var logo = new MemoryStream(logoMarca);
danfe.AdicionarLogoImagem(logo);
}

danfe.Gerar();
return danfe.ObterPdfBytes(pdfStream);
}

private static void AbrirPdfTemporario(byte[] pdfBytes)
{
var caminhoTemporario = Path.Combine(Path.GetTempPath(), "danfe-nfe.pdf");
File.WriteAllBytes(caminhoTemporario, pdfBytes);
Process.Start(new ProcessStartInfo(caminhoTemporario) { UseShellExecute = true });
}
}
}
15 changes: 15 additions & 0 deletions NFe.Danfe.AppTeste.PdfClown/NFe.Danfe.AppTeste.PdfClown.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\NFe.Danfe.PdfClown\NFe.Danfe.PdfClown.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions NFe.Danfe.AppTeste.QuestPdf/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="NFe.Danfe.AppTeste.QuestPdf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
44 changes: 44 additions & 0 deletions NFe.Danfe.AppTeste.QuestPdf/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************/
/* Projeto: Biblioteca ZeusNFe */
/* Biblioteca C# para emissão de Nota Fiscal Eletrônica - NFe e Nota Fiscal de */
/* Consumidor Eletrônica - NFC-e (http://www.nfe.fazenda.gov.br) */
/* */
/* Direitos Autorais Reservados (c) 2014 Adenilton Batista da Silva */
/* Zeusdev Tecnologia LTDA ME */
/* */
/* Você pode obter a última versão desse arquivo no GitHub */
/* localizado em https://github.com/adeniltonbs/Zeus.Net.NFe.NFCe */
/* */
/* */
/* Esta biblioteca é software livre; você pode redistribuí-la e/ou modificá-la */
/* sob os termos da Licença Pública Geral Menor do GNU conforme publicada pela */
/* Free Software Foundation; tanto a versão 2.1 da Licença, ou (a seu critério) */
/* qualquer versão posterior. */
/* */
/* Esta biblioteca é distribuída na expectativa de que seja útil, porém, SEM */
/* NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU */
/* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral Menor*/
/* do GNU para mais detalhes. (Arquivo LICENÇA.TXT ou LICENSE.TXT) */
/* */
/* Você deve ter recebido uma cópia da Licença Pública Geral Menor do GNU junto*/
/* com esta biblioteca; se não, escreva para a Free Software Foundation, Inc., */
/* no endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. */
/* Você também pode obter uma copia da licença em: */
/* http://www.opensource.org/licenses/lgpl-license.php */
/* */
/* Zeusdev Tecnologia LTDA ME - [email protected] */
/* http://www.zeusautomacao.com.br/ */
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
/********************************************************************************/

using System.Windows;

namespace NFe.Danfe.AppTeste.QuestPdf;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

Loading