|
53 | 53 | using NFe.Utils;
|
54 | 54 | using NFe.Utils.InformacoesSuplementares;
|
55 | 55 | using NFe.Utils.NFe;
|
| 56 | +using PdfSharpCore.Drawing; |
| 57 | +using PdfSharpCore.Pdf; |
56 | 58 | using NFeZeus = NFe.Classes.NFe;
|
57 | 59 |
|
58 | 60 | namespace NFe.Danfe.Nativo.NFCe
|
@@ -165,6 +167,48 @@ public byte[] GerarImagem()
|
165 | 167 | }
|
166 | 168 | }
|
167 | 169 |
|
| 170 | + public Func<Stream> ConverterBytesParaFuncStream(byte[] bytes) |
| 171 | + { |
| 172 | + Func<Stream> funcStream = () => |
| 173 | + { |
| 174 | + MemoryStream stream = new MemoryStream(bytes); |
| 175 | + // Certifique-se de que a posição do stream esteja no início. |
| 176 | + stream.Position = 0; |
| 177 | + return stream; |
| 178 | + }; |
| 179 | + |
| 180 | + return funcStream; |
| 181 | + } |
| 182 | + |
| 183 | + public byte[] ConverterImagemParaPdfBytes(byte[] imagemBytes) |
| 184 | + { |
| 185 | + using (MemoryStream stream = new MemoryStream()) |
| 186 | + { |
| 187 | + using (PdfDocument pdf = new PdfDocument()) |
| 188 | + { |
| 189 | + PdfPage page = pdf.AddPage(); |
| 190 | + XGraphics gfx = XGraphics.FromPdfPage(page); |
| 191 | + |
| 192 | + XImage image = XImage.FromStream(ConverterBytesParaFuncStream(imagemBytes)); |
| 193 | + |
| 194 | + page.Width = image.PointWidth; |
| 195 | + page.Height = image.PointHeight; |
| 196 | + |
| 197 | + |
| 198 | + gfx.DrawImage(image, 0, 0); |
| 199 | + |
| 200 | + pdf.Save(stream); |
| 201 | + } |
| 202 | + |
| 203 | + return stream.ToArray(); |
| 204 | + } |
| 205 | + } |
| 206 | + |
| 207 | + public byte[] PdfBytes() |
| 208 | + { |
| 209 | + return ConverterImagemParaPdfBytes(GerarImagem()); |
| 210 | + } |
| 211 | + |
168 | 212 | public void GerarJPEG(string filename)
|
169 | 213 | {
|
170 | 214 | GerarImagem(filename, ImageFormat.Jpeg);
|
@@ -262,7 +306,12 @@ private void GerarNfCe(Graphics graphics)
|
262 | 306 | #region preencher itens
|
263 | 307 | foreach (det detalhe in det)
|
264 | 308 | {
|
265 |
| - AdicionarTexto codigo = new AdicionarTexto(g, detalhe.prod.cProd, 7); |
| 309 | + var codigoXml = detalhe.prod.cProd; |
| 310 | + |
| 311 | + if (detalhe.prod.cProd.Length > 7) |
| 312 | + codigoXml = detalhe.prod.cProd.Remove(7); |
| 313 | + |
| 314 | + AdicionarTexto codigo = new AdicionarTexto(g, codigoXml, 7); |
266 | 315 | codigo.Desenhar(x, _y);
|
267 | 316 |
|
268 | 317 | AdicionarTexto nome = new AdicionarTexto(g, detalhe.prod.xProd, 7);
|
|
0 commit comments