Every layout below is drawn by one call, SefazDanfe.render/2. The previews are the first page of the PDF rendered at 100 dpi from the synthetic XML of the test suite; regenerate them with mix run scripts/previews.exs. The text printed on the documents stays in Portuguese, as the official manuals (MOC, DACTE and DAMDFE) require.

The document is recognised from the XML, so the only thing that changes between the calls is the options.

DANFE, portrait

The default layout of an NF-e (model 55) whose tpImp is 1: canhoto, emitter, access key with its CODE-128C barcode, authorization protocol, recipient, invoice and installments, tax calculation, carrier and volumes, items, ISSQN and the additional data at the foot of the last sheet. A document with many items runs over several sheets, repeating the header and the column titles and numbering them "Folha N/M".

{:ok, pdf} = SefazDanfe.render(File.read!("nfe-proc.xml"))

DANFE, portrait

DANFE, landscape

A4 on its side, with the vertical canhoto on the left, as the MOC (Anexo II) lays it out. It is chosen by tpImp 2 in the XML, or forced with orientation: :landscape (:portrait forces the other way; :auto is the default).

{:ok, pdf} = SefazDanfe.render(File.read!("nfe-proc.xml"), orientation: :landscape)

DANFE, landscape

DANFE NFC-e, 80 mm

The receipt of an NFC-e (model 65), with the QR code 2.00. The paper is 80 mm wide by default; the page is as tall as the content.

{:ok, pdf} = SefazDanfe.render(File.read!("nfce-proc.xml"))

DANFE NFC-e, 80 mm

DANFE NFC-e, 58 mm

The same document on the narrow roll.

{:ok, pdf} = SefazDanfe.render(File.read!("nfce-proc.xml"), paper: :mm58)

DANFE NFC-e, 58 mm

copy: :establishment prints "Via do Estabelecimento" next to the emission date and time.

DACTE

The auxiliary document of a CT-e (model 57), laid out after the DACTE of the MOC for the road modal (RNTRC and the road data the XML carries).

{:ok, pdf} = SefazDanfe.render(File.read!("cte-proc.xml"))

DACTE

DACTE OS

The CT-e OS (model 67, cteOSProc) uses the same call.

{:ok, pdf} = SefazDanfe.render(File.read!("cte-os-proc.xml"))

DACTE OS

DAMDFE

The auxiliary document of an MDF-e, with its QR code, the vehicle and the linked documents. closed: true marks a closed (encerrado) MDF-e.

{:ok, pdf} = SefazDanfe.render(File.read!("mdfe-proc.xml"))
{:ok, closed} = SefazDanfe.render(File.read!("mdfe-proc.xml"), closed: true)

DAMDFE

Marks and options on every layout

  • canceled: true (NF-e, NFC-e) marks the document as canceled ("NF-e CANCELADA" banner and a "CANCELADA" watermark).
  • An XML of the homologation environment (tpAmb 2) prints "SEM VALOR FISCAL"; no option is needed.
  • logo: {:png, binary} or logo: {:svg, binary} draws the emitter's logo in a fixed box.
SefazDanfe.render(xml, canceled: true, logo: {:png, File.read!("logo.png")})

Contingency examples

The notice comes from the tpEmis of the XML; nothing is asked of the caller. The texts and the sources are in SefazDanfe.Contingency.

NF-e, FS-DA

tpEmis 5 prints "DANFE EM CONTINGÊNCIA - IMPRESSO EM DECORRÊNCIA DE PROBLEMAS TÉCNICOS", the second barcode "DADOS DA NF-E" (Code 128C of 36 digits, in place of the consulta URL) and the same digits in the protocol box. The entry time (dhCont) and the reason (xJust) go in the additional data.

{:ok, pdf} = SefazDanfe.render(File.read!("nfe-fsda.xml"))

DANFE in FS-DA contingency

NFC-e, offline

tpEmis 9 prints "EMITIDA EM CONTINGÊNCIA" and "Pendente de autorização", with no protocol line. The QR code still prints.

{:ok, pdf} = SefazDanfe.render(File.read!("nfce-offline.xml"))

DANFE NFC-e offline

MDF-e, contingency

tpEmis 2 prints "EMISSÃO EM CONTINGÊNCIA" in the place of the authorization protocol.

{:ok, pdf} = SefazDanfe.render(File.read!("mdfe-contingency.xml"))

DAMDFE in contingency

The DACTE has its own FS-DA notice ("DACTE EM CONTINGÊNCIA - IMPRESSO EM DECORRÊNCIA DE PROBLEMAS TÉCNICOS", with the second barcode "DADOS DO CT-E"); the EPEC emission of an NF-e prints "DANFE impresso em contingência - EPEC regularmente recebida pela Receita Federal do Brasil".