1

I added a u3d image to a pdf (according to this example), I found the u3d image is added to the pdf but when I open the pdf with Acrobat I can't see it directly (blank block but the 3D menu), I have to right click the blank block and choose "Part Options -> Fit Visible" to make it appeared. If I am using example teapot.u3d it works (open then see). Is my u3d file too big (3 to 7 MB) but teapot.u3d only 141KB.

Here is the example code I am using:

    public void manipulatePdf(String dest) {
    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));

    Document doc = new Document(pdfDoc);
    Rectangle rect = new Rectangle(100, 400, 400, 400);

    PdfStream stream3D = new PdfStream(pdfDoc, new FileInputStream(RESOURCE));
    stream3D.Put(PdfName.Type, new PdfName("3D"));
    stream3D.Put(PdfName.Subtype, new PdfName("U3D"));
    stream3D.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
    stream3D.Flush();

    PdfDictionary dict3D = new PdfDictionary();
    dict3D.Put(PdfName.Type, new PdfName("3DView"));
    dict3D.Put(new PdfName("XN"), new PdfString("Default"));
    dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
    dict3D.Put(new PdfName("MS"), PdfName.M);
    dict3D.Put(new PdfName("C2W"),
            new PdfArray(new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }));
    dict3D.Put(PdfName.CO, new PdfNumber(235));

    Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
    annot.SetContents(new PdfString("3D Model"));
    annot.SetDefaultInitialView(dict3D);
    pdfDoc.AddNewPage().AddAnnotation(annot);
    doc.Close();
}

If I remove this line: "annot.SetDefaultInitialView(dict3D);" I can open and see the image but the background is black and image is dark. I am wondering the PdfDictionary in the example is not suitable for my u3d image. Not sure if different u3d image requires different PdfDictionary or initial view properties? We need to open and see the 3D image but don't know how to set the view properties. Can anyone help on this?

Michael Zhang
  • 47
  • 2
  • 6
  • The values defined in dict3D specify how the pdf-reader (adobe acrobat in this case) should render the attached 3D image by default. The meaning of those values can be found in the PDF specification, and the values from the example are chosen for the image the example was originally written for. tl;dr: Yes, that dictionary is not suitable for your image, and you should research the actual values you need to put in. – Samuel Huylebroeck Jul 17 '17 at 10:14
  • @SamuelHuylebroeck, thanks a lot for the info. Could you show me where I can find the PDF specification mapping to iText7 PdfDictionary and PdfName. And how do you know what view properties should be used in terms of different u3d image. Or any methods from iText7 to get the u3d image properties before we add it to the pdf? – Michael Zhang Jul 17 '17 at 11:34
  • ISO-32000 is the PDF spec, you can find a copy of 1.7 on Adobe's site, the 3D dictionary values can be found in chapter 9 – Samuel Huylebroeck Jul 17 '17 at 12:25
  • Thanks Samuel for the info. I read it but hard to understand (sorry for my fool). Could you show me a common way (or default way) to render the U3D image in a rectangle if possible no matter how big or small or others the image is. It is so that we don't need to right click to choose "Part Options -> Fit Visible" . Or, actually if we don't use PdfDictionary (comment annot.SetDefaultInitialView(dict3D);) and it shows the image right there but the backgroud is dark and 3D image is black, any method to bring the background white and image the original colour? – Michael Zhang Jul 17 '17 at 13:23
  • Hi @MichaelZhang, you are an iText customer with a support contract and you have created an issue about this in the iText JIRA. My colleagues will continue the conversation there, with higher priority than on SO. When a solution is reached then you are more than welcome to copy/paste that into an answer here on SO. – Amedee Van Gasse Jul 25 '17 at 08:32
  • @AmedeeVanGasse, yes I got contacted from Samuel. Thanks for your response. – Michael Zhang Jul 26 '17 at 12:50

0 Answers0