PDF/3-A 호환 PDF 작성 및 파이썬으로 ZugFERD 인보이스 첨부

주그퍼드를 PDF에 첨부하기

ZugFERD를 PDF에 첨부하려면 다음 단계를 따르는 것이 좋습니다.

  1. 편의를 위해 Aspose.PDF 라이브러리를 가져오고 ap의 별칭을 지정합니다.
  2. 입력 및 출력 PDF 파일이 있는 디렉토리의 경로를 정의합니다.
  3. 처리할 PDF 파일의 경로를 정의합니다.
  4. path 변수에서 PDF 파일을 로드하고 문서 객체를 만듭니다.
  5. 인보이스 메타데이터를 포함하는 XML 파일의 FileSpeification 객체를 생성합니다.경로 변수와 설명 문자열을 사용하여 FileSpeification 객체를 만들 수 있습니다.
  6. 설정 mime_typeaf_relationship 파일 사양 객체의 속성을 text/xmlALTERNATIVE, 각각.
  7. 문서 객체의 포함된 파일 컬렉션에 FileSpection 객체를 추가합니다.그러면 XML 파일이 PDF 문서에 인보이스 메타데이터 파일로 첨부됩니다.
  8. PDF 문서를 PDF/A-3A 형식으로 변환합니다.로그 파일 경로를 사용하십시오. PdfFormat.PDF_A_3A 열거, 및 ConvertErrorAction.DELETE 문서 객체를 변환하기 위한 열거입니다.
  9. 첨부된 ZugFerd와 함께 PDF 문서를 저장합니다.
import sys
import os
import aspose.pdf as ap

def attach_invoice_zugferd_format(infile, invoice, outfile):
    document = ap.Document(infile)

    # Create a FileSpecification object for the XML file that contains the invoice metadata
    description = "Invoice metadata conforming to ZUGFeRD standard"
    file_specification = ap.FileSpecification(invoice, description)

    # Set the MIME type and the AFRelationship properties of the embedded file
    file_specification.mime_type = "text/xml"
    file_specification.af_relationship = ap.AFRelationship.ALTERNATIVE

    # Add the embedded file to the PDF document's embedded files collection
    document.embedded_files.add("factur", file_specification)

    # Convert the PDF document to the PDF/A-3A format
    log_path = outfile.replace(".pdf", "_log.xml")
    document.convert(log_path, ap.PdfFormat.PDF_A_3A, ap.ConvertErrorAction.DELETE)
    document.save(outfile)