2013-07-08 1 views
0

나는 (PDResources, PDXObjectForm, PDAppearanceDictionary 등을 사용하여) pdfbox로 pdf를 만들었다. 나는 pdf에 보이는 서명이있다.pdf (pdfbox)의 스트림이 누락 되었습니까?

내가 pdf를 볼 때, 나는 약간 시내를 놓쳤다.

4 0 obj 
<</Type /XObject//Resources <</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/XObject <</n0 9 0 R/n1 10 0 R>>>>/BBox [0 0 100 100]/FormType 1/Length 11 0 R>> 
stream 

endstream 
endobj 

8 0 obj 
<</Type /XObject/Subtype /Form/Resources <</XObject <</FRM0 4 0 R >>/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]>>/BBox [0 0 100 100]/Matrix [1 0 0 1 0 0]/FormType 1/Length 13 0 R>> 
stream 

endstream 
endobj 

PDF 구조 (XObjects)가 잘 작성되었습니다. 그러나 나는 어떤 물줄기가 여기 있어야하는지 모른다. 또는 그것을 만드는 방법? 또는 어떤 흐름이 있어야 하는가?

PDDocument template = new PDDocument(); 



    try { 

      ... 

     PDStream formstream = new PDStream(template); 
     OutputStream os = formstream.createOutputStream(); 

     PDXObjectForm form = new PDXObjectForm(formstream); 
     PDResources res = new PDResources(); 
     form.setResources(res); 
     form.setBBox(formrect); 
     form.setMatrix(transform); 
     form.setFormType(1); 

     PDAppearanceStream dic = new PDAppearanceStream(form.getCOSStream()); 
     PDAppearanceDictionary appearance = new PDAppearanceDictionary(); 
     appearance.setNormalAppearance(dic); 
     appearance.getCOSObject().setDirect(true); 


     PDRectangle innerRect = new PDRectangle(); 
     innerRect.setUpperRightX(100); 
     innerRect.setUpperRightY(100); 
     innerRect.setLowerLeftX(0); 
     innerRect.setLowerLeftY(0); 

     PDStream formStream2 = new PDStream(template); 
     PDXObjectForm innerForm = new PDXObjectForm(formStream2); 


     OutputStream os1 = formStream2.createOutputStream(); 
     PDResources innerResources = new PDResources(); 
     innerForm.setResources(innerResources); 
     innerForm.setBBox(innerRect); 
     innerForm.setFormType(1); 

     innerForm.getResources().getCOSDictionary().setItem(COSName.PROC_SET, defaultRes); 
     res.addXObject(innerForm, "FRM"); 

     PDStream DSStream = new PDStream(template); 
     OutputStream os2 = DSStream.createOutputStream(); 
     PDXObjectForm dsForm = new PDXObjectForm(DSStream); 

     dsForm.setBBox(formrect); 
     dsForm.setMatrix(transform); 

     PDResources dsRes = new PDResources(); 
     dsForm.setResources(dsRes); 
     dsForm.setFormType(1); 


     PDFont firstFont = PDTrueTypeFont.loadTTF(template, new File("/MyFont.ttf")); 
     PDFont secondFont = PDTrueTypeFont.loadTTF(template, new File("/MyFont.TTF")); 
     secondFont.setFontEncoding(new WinAnsiEncoding()); 
     firstFont.setFontEncoding(new WinAnsiEncoding()); 

     Map<String, PDFont> fonts = new HashMap<String, PDFont>(); 

     PDStream imageFormStream = new PDStream(template); 
     OutputStream os3 = imageFormStream.createOutputStream(); 
     PDXObjectForm imageForm = new PDXObjectForm(imageFormStream); 

     imageForm.setBBox(formrect); 
     imageForm.setMatrix(transform); 
     PDResources imgRes = new PDResources(); 
      imgRes.getCOSObject().setDirect(true); 
     imgRes.addFont(firstFont); 
     imageForm.setResources(imgRes); 

     imageForm.setFormType(1); 
     innerResources.addXObject(dsForm, "n"); 
     innerResources.addXObject(imageForm, "n"); 

     imgRes.addXObject(jpeg, "img"); 

     appendRawCommands(os2, "% DSBlank"); 
     appendRawCommands(os3, "q 101 0 0 24.53 2 12.24 cm /img0 Do Q"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "BT"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "1 0 0 1 2 33 Tm"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "101 0 Td"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "-101 0 Td"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "ET"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "BT"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "1 0 0 1 106 37 Tm"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "/F1 12 Tf"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "(TEXT HERE)Tj"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "1 0 0 1 106 25 Tm"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "(10 11:12:13)Tj"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "1 0 0 1 106 13 Tm"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "(GMT+06:00 2013)Tj"); 
     appendRawCommands(os3, "\n"); 
     appendRawCommands(os3, "ET"); 

     os1.close(); 
     os.close(); 
     os3.close(); 
     os2.close(); 

     sigField.getWidget().setAppearance(appearance); 
     COSDictionary widgetDict = sigField.getWidget().getDictionary(); 
     widgetDict.setNeedToBeUpdate(true); 

     defaultRes.setDirect(true); 
     widgetDict.setItem(COSName.DR, res.getCOSObject()); 

     PDResources resSecondForAcro = new PDResources(); 
     resSecondForAcro.addXObject(innerForm, "FRM"); 

     resSecondForAcro.addFont(secondFont);    

     COSBase cosBase=resSecondForAcro.getCOSObject(); 
     cosBase.setDirect(true); 
     acroFormDC.setItem(COSName.DR, cosBase); 

     COSDocument visualSignature = template.getDocument(); 
        ... 

     COSWriter wr = new COSWriter(new FileOutputStream("/new.pdf")); 
     wr.write(visualSignature); 
     wr.close(); 
     template.close(); 

    } finally { 
     template.close(); 
    } 

그건 샘플 :

내가 그 코드에 추가해야하는지

link

? 문제는 사각형에 보이는 이미지가 없음을 나타냅니다.

답변

0

당신은 당신이 사용합니까 이유는 말했다되고

appendRawCommands(os, "q 1 0 0 1 0 0 cm /FRM0 Do Q\n"); 
appendRawCommands(os1, "q 1 0 0 1 0 0 cm /n0 Do Q\n"); 
appendRawCommands(os1, "q 1 0 0 1 0 0 cm /n1 Do Q\n"); 

의 라인을 따라 뭔가를 추가 할 수 있습니다 os로도 os1.

os2os3하지만도에 명령을 추가 이러한 복잡 구조. Adobe에서 사용했던 xobject 이름을 사용한 경우 (예 : /FRM, /n0/n2) Acrobat 6 이전 버전에서만 다른 레이어가 있었지만 도 이해할 수 있지만 다른 이름을 사용합니다. /FRM0/n1, /n0 만 동일합니다. 따라서 대신 이미지 및 텍스트가 포함 된 스트림을 정상적인 모양으로 즉시 사용할 수 있습니다.

오래된 레이어 모양을 지원하려면 Adobe®의 Acrobat® SDK Digital Signature Appearances 용지의 표기법을보다 정확하게 따라야합니다.

PS :PDStream OutputStreams을 동시에 열어서는 안됩니다. 대신에 그러한 출력 스트림을 검색하고 그것에 쓰고 닫은 다음 PDF 객체의 다른 조작을 계속해야합니다.

관련 문제