xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jfrm.maurel@gmail.com" <jfrm.mau...@gmail.com>
Subject u3d pdf file
Date Wed, 23 Sep 2020 14:54:11 GMT
Hi,

I am trying to include a pdf file containing a 3d drawing inside a pdf 
file using fop 2.3 and fop-images-pdf 2.3. However the graphic included 
is outside of the bound of the containing block (see result.pdf page 4).
Could you please tell what is wrong here ?

For information everything is fine if I incorporate a 'normal' pdf 
without 3d model.

The process I used is the following:

- including the pdf with
   <fo:block border="1pt solid black" text-align="center">
    <fo:external-graphic src="u3d.pdf" border="1pt solid red" 
block-progression-dimension="100mm" content-width="scale-to-fit" 
scaling="uniform" />
   </fo:block>
- for information the u3d.pdf file containing a u3d graphic is build 
from a u3d file using the following java code with itext 5.5
     public static void writePdf(String u3dFileUri, OutputStream out) {
         Dimension dimension = new Dimension(100,100);
         Rectangle pageSize = new Rectangle(dimension.width, 
dimension.height);
         Document doc = new Document();
         try {
             PdfWriter wr = PdfWriter.getInstance(doc, out);
             doc.open();
             String script = getScript();
             PdfStream oni = new 
PdfStream(PdfEncodings.convertToBytes(script, null));
             oni.flateCompress();
             PdfIndirectReference initScriptRef = 
wr.addToBody(oni).getIndirectReference();
             ArrayList<PdfIndirectReference> viewList = new 
ArrayList<PdfIndirectReference>(1);
             PdfDictionary viewDict = new PdfDictionary(new 
PdfName(PDF_NAME_3DVIEW));
             viewDict.put(new PdfName(PDF_NAME_MS), new PdfString("M"));
             float[] T1 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0 };
             viewDict.put(new PdfName("C2W"), new PdfArray(T1));
             String cameraName = "Test Camera";
             viewDict.put(new PdfName(PDF_NAME_XN), new 
PdfString(cameraName));
             PdfIndirectReference ref = 
wr.addToBody(viewDict).getIndirectReference();
             viewList.add(ref);
             File u3d = FileProc.newFile(u3dFileUri);
             PdfStream stream = new PdfStream(new FileInputStream(u3d), wr);
             stream.put(new PdfName("OnInstantiate"), initScriptRef);
             stream.put(PdfName.TYPE, new PdfName(PDF_NAME_3D));
             stream.put(PdfName.SUBTYPE, new PdfName(PDF_NAME_U3D));
             stream.flateCompress();
             PdfIndirectReference u3dStreamRef = 
wr.addToBody(stream).getIndirectReference();
             stream.writeLength();
             PdfDictionary activationDict = new PdfDictionary();
             activationDict.put(PdfName.A, new PdfName("PO"));
             activationDict.put(new PdfName("DIS"), PdfName.I);
             float scale = 0.5f;
             float width = scale * (pageSize.getRight() - 
pageSize.getLeft());
             float height = scale * (pageSize.getTop() - 
pageSize.getBottom());
             PdfAppearance ap = PdfAppearance.createAppearance(wr, 
width, height);
             ap.setBoundingBox(pageSize);
             PdfAnnotation annot = new PdfAnnotation(wr, pageSize);
             annot.put(PdfName.CONTENTS, new PdfString("3D Model"));
             annot.put(PdfName.SUBTYPE, new PdfName(PDF_NAME_3D));
             annot.put(PdfName.TYPE, PdfName.ANNOT);
             annot.put(new PdfName(PDF_NAME_3DD), u3dStreamRef);
             PdfBoolean value3DI = showInventory ? PDFTRUE : PDFFALSE;
             annot.put(new PdfName("3DI"), value3DI);
             annot.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
             annot.put(new PdfName("3DA"), activationDict);
             annot.setPage(1);
             wr.addAnnotation(annot);
             doc.close();
         } catch (IOException e) {
             e.printStackTrace();
         } catch (DocumentException de) {
             de.printStackTrace();
         }
     }



pdf files :
u3d.pdf <https://we.tl/t-5fBBo0McMz>(7,0 
Ko)WeTransferhttps://we.tl/t-5fBBo0McMz <https://we.tl/t-5fBBo0McMz>
result.pdf <https://we.tl/t-kp7wlyiptl>(4,1 
Mo)WeTransferhttps://we.tl/t-kp7wlyiptl <https://we.tl/t-kp7wlyiptl>
Mozilla Thunderbird <https://www.thunderbird.net> permet de partager 
facilement des fichiers volumineux.

Regards

-- 
Jean-François MAUREL
PIMECA
http://www.pimeca.com


Mime
View raw message