Skip to content

Handle escape characters in ModDate #1118

@GwendalSuperG

Description

@GwendalSuperG

We are using pdfcpu to handles eInvoicing with Factur-X. The Factur-X format add an XML as an attachments to the PDF invoice to allow easy processing.

We encounter an issue with some samples PDF provided by Factur-X https://fnfe-mpe.org/factur-x/
The ModDate is invalid:

$ pdfcpu attachments list Facture_F20220023-LE_FOURNISSEUR-POUR-LE_CLIENT_MINIMUM.pdf 
validating URIs..

pdfcpu: invalid date ModDate

This is because the ModDate contains escaped characters for example:
D\07220200707112545\05300\04700\047

It can be solved by adding an Unqote call on the DateTime function:

// DateTime decodes s into a time.Time.
func DateTime(s string, relaxed bool) (time.Time, bool) {
	// 7.9.4 Dates
	// (D:YYYYMMDDHHmmSSOHH'mm)
	var d time.Time
        // Add an unquote
        var err error
	s, err = strconv.Unquote(fmt.Sprintf("\"%s\"", s))
	if err != nil {
		return d, false
	}


	var ok bool
	s, ok = prevalidateDate(s, relaxed)
	if !ok {
		return d, false
	}
...

You can find a PDF file with this issue and the full verbose report

verbose.txt
Facture_F20220023-LE_FOURNISSEUR-POUR-LE_CLIENT_MINIMUM.pdf

If you are ok with this I can submit a PR

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions