使用itext7将u3d添加到pdf时如何设置初始视图属性

时间:2017-07-15 13:14:57

标签: c# .net pdf itext7 u3d

我在pdf中添加了一个u3d图像(根据此example),我发现u3d图像被添加到pdf中,但是当我用Acrobat打开pdf时我无法直接看到它(空白块)但是3D菜单),我必须右键单击空白区块并选择“Part Options - > Fit Visible”才能显示。如果我使用示例teapot.u3d它可以工作(打开然后看)。我的u3d文件太大(3到7 MB)但teapot.u3d只有141KB。

以下是我使用的示例代码:

    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();
}

如果我删除此行:“annot.SetDefaultInitialView(dict3D);”我可以打开并看到图像,但背景是黑色,图像是黑暗的。我想知道示例中的PdfDictionary不适合我的u3d图像。不确定不同的u3d图像是否需要不同的PdfDictionary或初始视图属性? 我们需要打开并查看3D图像,但不知道如何设置视图属性。任何人都可以帮忙吗?

0 个答案:

没有答案