Coder Social home page Coder Social logo

deltazero-cz / node-isdoc-pdf Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 653 KB

Create ISDOC.PDF (PDF/A-3 with ISDOC attachment), create ISDOCX (ZIP archive with PDF and ISDOC) or extract ISDOC from PDF - Czechia's standard invoice format for data exchange

License: ISC License

TypeScript 100.00%

node-isdoc-pdf's Introduction

ISDOC-PDF Node.js library

ISDOC is an XML Invoicing Standard for the Czech Republic.

This library can:

  • extract ISDOC invoices from PDFs
  • create ISDOC.PDF (PDF/A-3B with ISDOC attached)
  • create IDDOCX archives (zips with PDF and ISDOC)

It also provides Node.js API for ISDOC format, see node-isdoc, incl. XSD xchema validation.

Installation

npm i isdoc-pdf

To create ISDOC.PDF (PDF/A-3B with ISDOC attached), this package depends on Bash-like shell and Ghostscript, see isdoc-pdf (bash).

Usage

Extract ISDOC from existing PDF

import { hasISDOC, extractISDOC } from 'isdoc-pdf'

const plainInvoice = await fs.readFile('invoice.pdf'),
      isdocInvoice = await fs.readFile('invoice.isdoc.pdf')

await hasISDOC(plainInvoice)
// -> false

await hasISDOC(isdocInvoice)
// -> true

await extractISDOC(plainInvoice)
// -> null 

await extractISDOC(isdocInvoice)
// -> Invoice { DocumentType: number, ID: string, IssueDate: Date, ... }

Create ISDOC.PDF (attach ISDOC to PDF and convert into PDF/A-3)

import { attachISDOC } from 'isdoc-pdf'

const invoice = await fs.readFile('invoice.pdf'),
      isdoc = await fs.readFile('invoice.isdoc')

const pdfa = await attachISDOC(invoice, isdoc)
// -> Buffer with PDF/A-3

Create ISDOC.PDF with a new Invoice

import { Invoice, attachISDOC } from 'isdoc-pdf'

const isdoc = new Invoice({
  DocumentType: 1,
  ID: '2022123456',
  ... // see https://github.com/deltazero-cz/node-isdoc
})

const pdf = await fs.readFile('invoice.pdf')

const pdfa = await attachISDOC(pdf, isdoc)
// -> Buffer with PDF/A-3

Create IDDOCX archives (ZIP archives with PDF and ISDOC)

import { createISDOCX } from 'isdoc-pdf'

const invoice = await fs.readFile('invoice.pdf'),
      isdoc = await fs.readFile('invoice.isdoc')

const isdocx = await createISDOCX(invoice, invoice)
// -> Buffer with ISDOCX (ZIP archive)

Create IDDOCX with a new Invoice

import { Invoice, createISDOCX } from 'isdoc-pdf'

const isdoc = new Invoice({
  DocumentType: 1,
  ID: '2022123456',
  ... // see https://github.com/deltazero-cz/node-isdoc
})

const pdf = await fs.readFile('invoice.pdf')

const isdocx = await createISDOCX(pdf, isdoc)
// -> Buffer with ISDOCX (ZIP archive)

node-isdoc-pdf's People

Contributors

deltazero-cz avatar

Stargazers

Tomáš Dinh avatar  avatar Boris Grigorov avatar  avatar Jiří Macháček avatar

Watchers

 avatar  avatar

node-isdoc-pdf's Issues

Path to isdoc-pdf executable

V souboru attachIsdoc je definovana cesta k bashi isdoc-pdf:
const bin = __dirname + '/../node_modules/isdoc-pdf-bash/isdoc-pdf'
Funkce attachISDOC mi vraci attachISDOC: Cannot find [isdoc-pdf] executable

Po uprave cesty na __dirname + '/../../isdoc-pdf-bash/isdoc-pdf script funguje
Tobe funguje i s puvodni cestou?

Vyexportovany isdoc neni validni

Zkousel jsem sve pdf vygenerovane z Pohody a pote i vzorove z isdoc-pdf a oboje hlasi ze neni validni. Testovano v Ubuntu, exportovaci js prilozeno nize.

ISDOCReader (verze: 4.0.1, podporované verze: 6.0.2, 6.0.1, 5.3.1, 5.3, 5.2.3, 5.2.2, 5.2.1, 5.2, 5.1, 5.0)

Seznam chybových hlášení

Datum 5.3.2024 18:39:18
ISDOCReader verze 4.0.1
Podporované verze 6.0.2, 6.0.1, 5.3.1, 5.3, 5.2.3, 5.2.2, 5.2.1, 5.2, 5.1, 5.0
Dokument test001.isdoc.isdoc
Verze dokumentu


Při kontrole formální správnosti dokumentu 'test001.isdoc.isdoc' byla zjištěna chyba.
Zpracování dokumentu nebude provedeno.
Text chyby:
Nepodařilo se zjistit verzi ISDOC dokumentu. Verze dokumentu není podporována nebo soubor není validní XML dokument.
###########JS##########

const fs = require('fs');
const { hasISDOC, extractISDOC } = require('isdoc-pdf');

async function main() {
    try {
        const inputFileName = process.argv[2]; // Získání názvu souboru z příkazové řádky
        const isdocInvoice = await fs.promises.readFile(inputFileName);

        const hasIsdocISDOC = await hasISDOC(isdocInvoice);
        console.log('ISDOC PDF contains ISDOC:', hasIsdocISDOC);

        const extractedISDOC = await extractISDOC(isdocInvoice);
        if (extractedISDOC) {
            console.log('Extracted ISDOC:', extractedISDOC);

            // Uložení extrahovaných ISDOC dat do souboru s příponou .isdoc
            const outputFileName = inputFileName.replace('.pdf', '.isdoc');
            await fs.promises.writeFile(outputFileName, JSON.stringify(extractedISDOC, null, 2));
            console.log(`Extracted ISDOC data saved to ${outputFileName}`);
        } else {
            console.log('No ISDOC found in the provided PDF.');
        }
    } catch (error) {
        console.error('Error reading file:', error.message);
    }
}

main();

Command failed

Ahoj,

asi to nebude chyba knihovny, ale zatim si s tim sam nevim rady, tak te zkusim poprosit o pomoct.
Zkousim k pdf attachnout isdoc.

Vrati se mi vsak vzdy chyba:
Command failed: /var/www/capp/napi/node_modules/isdoc-pdf/lib/../node_modules/isdoc-pdf-bash/isdoc-pdf /tmp/tmp.h8Vvlr3enr /tmp/tmp.hWWfkqYqcL /tmp/tmp.sIAAJzOfQ8

Zkousel jsem to i na Google compute enginu a ten mi vrati obdobnou chybu (jen cesty jsou pochopitelne jine)

Script je pomerne jednoduchy. Zkousim zatim pouzit fragmenty z tve dokumentace a jako pdf soubor test000.pdf:

`const data = new Invoice({
DocumentType: 1,
ID: '2022123456',
IssuingSystem: 'node-isdoc',
IssueDate: new Date(),
TaxPointDate: new Date(),
VATApplicable: true,
AccountingSupplierParty: {
Party: {
PartyIdentification: { ID: '12345678' },
PartyName: { Name: 'Test s.r.o.' },
PostalAddress: {
StreetName: 'Dodavatelská',
BuildingNumber: '1',
CityName: 'Dodavatelov',
PostalZone: '12345',
Country: { IdentificationCode: 'CZ', Name: '' }
},
PartyTaxScheme: {
CompanyID: 'CZ12345678',
TaxScheme: 'VAT'
},
Contact: {
Telephone: '222111000',
ElectronicMail: '[email protected]'
}
}
},
AccountingCustomerParty: {
Party: {
PartyIdentification: { ID: '12345678' },
PartyName: { Name: 'Test s.r.o.' },
PostalAddress: {
StreetName: 'Dodavatelská',
BuildingNumber: '1',
CityName: 'Dodavatelov',
PostalZone: '12345',
Country: { IdentificationCode: 'CZ', Name: '' }
},
PartyTaxScheme: {
CompanyID: 'CZ12345678',
TaxScheme: 'VAT'
},
Contact: {
Telephone: '222111000',
ElectronicMail: '[email protected]'
}
}
},
InvoiceLines: {
InvoiceLine: [
{
ID: '10001',
InvoicedQuantity: 1,
LineExtensionAmount: 100,
LineExtensionAmountTaxInclusive: 121,
LineExtensionTaxAmount: 21,
UnitPrice: 100,
UnitPriceTaxInclusive: 121,
ClassifiedTaxCategory: {
Percent: 21,
VATCalculationMethod: 0,
VATApplicable: true
},
Item: { Description: 'Zboží 10001' }
},
]
},
TaxTotal: {
TaxSubTotal: {
TaxableAmount: 100,
TaxAmount: 21,
TaxInclusiveAmount: 121,
AlreadyClaimedTaxableAmount: 0,
AlreadyClaimedTaxAmount: 0,
AlreadyClaimedTaxInclusiveAmount: 0,
DifferenceTaxableAmount: 100,
DifferenceTaxAmount: 21,
DifferenceTaxInclusiveAmount: 121,
TaxCategory: {
Percent: 21,
VATApplicable: true,
}
},
TaxAmount: 21
},
LegalMonetaryTotal: {
TaxExclusiveAmount: 100,
TaxInclusiveAmount: 121,
AlreadyClaimedTaxExclusiveAmount: 0,
AlreadyClaimedTaxInclusiveAmount: 0,
DifferenceTaxExclusiveAmount: 100,
DifferenceTaxInclusiveAmount: 121,
PayableRoundingAmount: 0,
PaidDepositsAmount: 0,
PayableAmount: 121
},
PaymentMeans: {
Payment: {
PaidAmount: 121,
PaymentMeansCode: 42,
Details: {
PaymentDueDate: new Date(),
ID: '43-1234567890',
BankCode: '0100',
Name: '',
IBAN: '',
BIC: '',
VariableSymbol: 2022123456,
ConstantSymbol: '',
SpecificSymbol: ''
}
}
}
})

  attachISDOC(file, data)
    .then((response)=>{
      console.log('response', response)
    })
    .catch((e)=>{
      console.log('e', e)
    })`

Nemel bys pro me nejaky hint, na co se zamerit? Ta chybova hlaska je pro me tak obecna, ze si zatim nevim rady.

Diky moc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.