Skip to main content

DanfeBuilder

Struct DanfeBuilder 

Source
pub struct DanfeBuilder<'a> {
    pub xml: Option<&'a str>,
    pub paper_size: Option<&'a str>,
    pub as_base64: Option<&'a str>,
    pub as_file: Option<&'a str>,
    pub qr_side: bool,
    pub logo: Option<&'a str>,
}
Expand description

Builder para geração de DANFE (PDF) a partir de XML.

§Exemplo

use dfe::DanfeBuilder;

// Gerar o PDF e salvar em arquivo
let output_as_file = DanfeBuilder::new()
    .xml("./nota.xml")
    .paper_size("80mm")
    .as_file("./danfe.pdf")
    .build()
    .await?;

// Ou obter o PDF em base64
let output_as_base64 = DanfeBuilder::new()
    .xml("./nota.xml")
    .paper_size("a4")
    .as_base64()
    .build()
    .await?;

Fields§

§xml: Option<&'a str>§paper_size: Option<&'a str>§as_base64: Option<&'a str>§as_file: Option<&'a str>§qr_side: bool

Caminho de arquivo (PNG/JPG) ou string base64 do logotipo do emitente. Data URIs (data:image/png;base64,...) também são aceitos.

Implementations§

Source§

impl<'a> DanfeBuilder<'a>

Source

pub fn new() -> Self

Source

pub fn xml(self, xml: &'a str) -> Self

Configura o XML a partir de uma string ou caminho de arquivo. O método detecta automaticamente se a entrada é um caminho de arquivo ou uma string XML. Se a string terminar com “.xml”, será tratada como um caminho de arquivo; caso contrário, será tratada como XML bruto.

Source

pub fn paper_size(self, size: &'a str) -> Self

Configura o tamanho do papel para o DANFE. Exemplos de tamanhos: “a4”, “80mm”, “54mm”. Se não enviado, o padrão será “a4”.

Source

pub fn as_base64(self) -> Self

Configura a saída do DANFE como base64.

Source

pub fn as_file(self, path: &'a str) -> Self

Configura a saída do DANFE como arquivo PDF. O caminho do arquivo deve ser fornecido como argumento.

Define o logotipo do emitente. Aceita: caminho de arquivo (.png / .jpg / .jpeg), base64 puro ou data URI.

Source

pub fn qr_side(self) -> Self

Usa layout lateral para o QR Code (NFC-e 80mm): QR Code à esquerda (~33 mm) com chave de acesso e protocolo à direita. Padrão: QR Code centralizado.

Source

pub async fn build(self) -> Result<String, String>

Constrói e gera o PDF, retornando o resultado. Result<String, String> - Ok(String) com o resultado da geração ou Err(String) com a mensagem de erro. Ok(String) pode ser o caminho do arquivo gerado ou a string base64, dependendo da configuração escolhida.

Trait Implementations§

Source§

impl<'a> Clone for DanfeBuilder<'a>

Source§

fn clone(&self) -> DanfeBuilder<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for DanfeBuilder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for DanfeBuilder<'a>

§

impl<'a> RefUnwindSafe for DanfeBuilder<'a>

§

impl<'a> Send for DanfeBuilder<'a>

§

impl<'a> Sync for DanfeBuilder<'a>

§

impl<'a> Unpin for DanfeBuilder<'a>

§

impl<'a> UnsafeUnpin for DanfeBuilder<'a>

§

impl<'a> UnwindSafe for DanfeBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more