2017-01-17 5 views
0

현재 TIFF to PDF 형식 변환기 인 프로젝트를 진행 중입니다. 일련의 스캔 된 컬렉션 TIFF 파일을 가져 와서 단일 다중 페이지 PDF/A3 파일로 변환합니다. 프로젝트의이 부분을 마치고 메타 데이터 처리 문제에 집중했습니다.XMP 메타 데이터를 여러 페이지 PDF/A3 파일에 포함시키는 방법은 무엇입니까?

내 상사가 각 TIFF의 메타 데이터를 PDF 파일의 각 해당 페이지에 임베드하고 싶습니다. 어떻게해야할지 모르겠다. PDF/A 메타 데이터 구조에 대한 제 연구에 따르면 PDF에 xmp 파일이 하나만있는 것처럼 보입니다. 특정 페이지의 matadata를 포함하려면 원하는 위치로 포인터를 지정해야합니다. 있다. 내 프로젝트에서 생각한 기본 아이디어는 각 TIFF 파일에서 메타 데이터를 추출하고 (이 단계를 수행하는 방법을 알고 있습니다.)이 모든 것을 결합하여 PDF 파일로 변환합니다. 나는 iText를 사용하려고 시도했지만이 방법을 지원하지 않는 것 같습니다.

누구든지 어떻게하는지 압니까? 이런 식으로 할 수있는 열린 도구가 있습니까? 나의 주요 언어는 Java이다.

감사합니다 !!!

+0

* "PDF에 하나 개의 XMP 파일이 있어야처럼 PDF/A 메타 데이터 구조에 대한 내 연구에 따르면, 그것은 보인다"* - 종종 문서와와 관련된 하나 하나 개의 메타 데이터 스트림이있다 전체. Samuel의 답변에 대한 더 많은 의견이 있습니다. – mkl

답변

0

귀하의 연구에서 정확합니다.

대부분의 경우 pdf 문서 전체에 속한 메타 데이터와 TIFF 이미지에 속한 메타 데이터를 구별하는 것이 중요하기 때문입니다. 첫 번째는 실제로 pdf 당 하나의 인스턴스로 제한됩니다. 두 번째는 PDF 메타 데이터에 독립적이지만 첨부 파일로 추가 할 수 있으며 PDF/A-3 표준에서 허용됩니다. 두 유형 모두 어떤 페이지와도 독립적이므로 이러한 의미에서 Boss의 요청은 PDF 형식에 대한 지식 부족을 형식으로 나타냅니다.

그러나 메타 데이터를 가리키는 각 Tiff에 링크 주석을 넣을 수도 있습니다. 선택 사항으로 두 번째 pdf 파일에 저장되어 데이터가 어떻게 든 페이지에 표시된다는 환상을 제공 할 수 있습니다.

이제 iText가이 문제를 해결할 도구를 제공하지 않는다는 사실에 정중히 동의해야합니다. Chapter 7 of the iText7 Jumpstart tutoria l은 파일 포함을 포함하여 PDF/A-X 생성을 처리합니다. PDF/A-3은 세 번째 예입니다.

링크 주석은 Pdf-spec (내장 된 Go-To 작업) 및 iText의 하위 수준 조작 방법에 대한 지식을 가지고 가능합니다. 지금 당장은 준비된 예가 없지만 나중에 추출 할 수 있는지 알아볼 것입니다.

편집 : 음, Foxit도 Adobe의 독자도 포함 된 이동 작업을 지원하지 않습니다. 그래도 관심이있는 경우, iText7을 사용하여 PDF/A-3 규격 문서를 작성하고 메타 데이터를 별도의 Pdf로 추가하는 데 사용 된 코드는 다음과 같습니다.

public static String INTENT = "src/test/resources/StackOverflow/EmbeddedLinking/sRGB_CS_profile.icm"; 
public static String IMG = "src/test/resources/StackOverflow/EmbeddedLinking/itis.jpg"; 
public static String META = "target/output/StackOverflow/EmbeddedLinking/metadata.pdf"; 
public static String DEST = "target/output/StackOverFlow/EmbeddedLinking/embeddedMetaData.pdf"; 

public static void main(String[] args) throws IOException, java.io.IOException { 
    File file = new File(DEST); 
    file.getParentFile().mkdirs(); 
    new EmbeddedLinking().createPdf(META); 
    new EmbeddedLinking().createPdfWithEmbeddedFile(DEST,META,IMG,INTENT); 
} 

public void createPdf(String dest) throws IOException, FileNotFoundException{ 
    PdfWriter writer = new PdfWriter(dest); 
    PdfDocument pdfDoc = new PdfDocument(writer); 
    Document doc = new Document(pdfDoc); 
    //Put some data here 
    doc.add(new Paragraph("This is the metadata")); 
    doc.add(new Paragraph("The Cake is Lie")); 
    doc.add(new Paragraph("42")); 
    doc.add(new Paragraph("The Spice must flow")); 
    doc.close(); 
} 

public void createPdfWithEmbeddedFile(String dest, String embeddedPath, String imgPath, String intent) throws java.io.IOException { 
    PdfWriter writer = new PdfWriter(dest); 
    PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "","http://www.color.org", "sRGB IEC61966-2.1", new FileInputStream(intent)); 
    PdfADocument pdfADoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3A,outputIntent); 

    //Setting some required parameters 
    pdfADoc.setTagged(); 
    pdfADoc.getCatalog().setLang(new PdfString("en-US")); 
    pdfADoc.getCatalog().setViewerPreferences(
      new PdfViewerPreferences().setDisplayDocTitle(true)); 
    PdfDocumentInfo info = pdfADoc.getDocumentInfo(); 
    info.setTitle("iText7 PDF/A-3 Embedded Go-To example"); 

    //Add attachment 
    PdfDictionary parameters = new PdfDictionary(); 
    parameters.put(PdfName.ModDate, new PdfDate().getPdfObject()); 
    PdfFileSpec fileSpec = PdfFileSpec.createEmbeddedFileSpec(
      pdfADoc, Files.readAllBytes(Paths.get(embeddedPath)), "metadata.pdf", 
      "metadata.pdf", new PdfName("application/pdf"), parameters, 
      PdfName.Data, false); 
    fileSpec.put(new PdfName("AFRelationship"), new PdfName("Data")); 
    pdfADoc.addFileAttachment("metadata.pdf", fileSpec); 
    PdfArray array = new PdfArray(); 
    array.add(fileSpec.getPdfObject().getIndirectReference()); 
    pdfADoc.getCatalog().put(new PdfName("AF"), array); 

    //Add Image 
    int imagePage = 1; //We know the image will end up on the first page since it's the only thing we add to the document 
    Document doc = new Document(pdfADoc, PageSize.A4); 
    Image img = new Image(ImageDataFactory.create(imgPath)); 
    doc.add(img); 


    //Add link annotation to embedded file 
    float pageHeight = PageSize.A4.getHeight(); 
    float imageWidth = img.getImageWidth(); 
    float imageHeight = img.getImageHeight(); 
    float x = doc.getLeftMargin(); 
    float y = pageHeight - doc.getTopMargin() - imageHeight; 
    Rectangle linkAnnotationPosition = new Rectangle(x,y,imageWidth,imageHeight); 

    PdfLinkAnnotation linkAnnotation = new PdfLinkAnnotation(linkAnnotationPosition); 
    //Setup the Embedded GoTO action 
    PdfExplicitDestination explicitDestination = PdfExplicitDestination.createFit(imagePage);//Destination in the target file 
    PdfTargetDictionary targetDictionary = PdfTargetDictionary.createChildTarget("metadata.pdf"); //Target embedded file 
    PdfAction action = PdfAction.createGoToE(fileSpec,explicitDestination,true,targetDictionary); 
    linkAnnotation.setAction(action); 
    //PDF/A requires the presence of the F -bit flag array in every dictionary. The print flag needs to be 1, and some other flags 0. 
    //See the spec for details and options, but the bit pattern represented by the integer 4 suffices for conformance to PDF/A-3 
    int fBitArray = 4; 
    linkAnnotation.put(PdfName.F,new PdfNumber(fBitArray)); 
    //Add annotation to page 
    pdfADoc.getPage(imagePage).addAnnotation(linkAnnotation); 

    //Close document 
    doc.close(); 
} 
+0

* "pdf 파일 [...]에 속한 메타 데이터는 실제로 pdf 당 하나의 인스턴스로 제한됩니다."* - 그게 뭡니까? ISO 32000-1 *에 따르면 모든 PDF 스트림이나 사전에 메타 데이터가 첨부되어있을 수 있습니다 (14.3.2 절). ISO 19005-3에서이 제한 사항을 찾지 못했습니다. 반대로 모든 메타 데이터가 필요합니다 PDF에있는 스트림은 여러 메타 데이터 스트림이있을 수 있음을 의미하는 XMP 사양 * (섹션 6.6.2.1)을 준수해야합니다. 아니면 전체적으로 문서를 참조하는 메타 데이터 인스턴스가 하나만있을 수 있다는 뜻입니까? 그렇다면 당신 말이 맞습니다. – mkl

+0

@mkl 후자의 경우 전체 문서에 속한 메타 데이터 인스턴스는 하나뿐입니다.문구가 실제로는 모호하기 때문에 나는 대답을 편집 할 것이다. –