u3d dosya türlerini itextsharp kütüphanesini kullanarak açmamıza yarayan yazmış olduğum bir class güle güle kullanmanız dileğiyle.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
{
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filePath,FileMode.Create));
doc.Open();
Rectangle rect = new Rectangle(100, 400, 500, 800);
rect.Border = Rectangle.BOX;
rect.BorderWidth = 0.5F;
rect.BorderColor = new BaseColor(0xFF, 0x00, 0x00);
doc.Add(rect);
PdfStream stream3D = new PdfStream(new FileStream(Files3D, FileMode.Open), writer);
stream3D.Put(PdfName.TYPE, new PdfName("3D"));
stream3D.Put(PdfName.SUBTYPE, new PdfName("U3D"));
stream3D.FlateCompress();
PdfIndirectObject streamObject = writer.AddToBody(stream3D);
stream3D.WriteLength();
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));
PdfIndirectObject dictObject = writer.AddToBody(dict3D);
PdfAnnotation annot = new PdfAnnotation(writer, rect);
annot.Put(PdfName.CONTENTS, new PdfString("3D Model"));
annot.Put(PdfName.SUBTYPE, new PdfName("3D"));
annot.Put(PdfName.TYPE, PdfName.ANNOT);
annot.Put(new PdfName("3DD"), streamObject.IndirectReference);
annot.Put(new PdfName("3DV"), dictObject.IndirectReference);
PdfAppearance ap = writer.DirectContent.CreateAppearance(rect.Width, rect.Height);
annot.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
annot.SetPage();
writer.AddAnnotation(annot);
// step 5
doc.Close();
}
Kullanımı :
Pdf3D pdf3d = new Pdf3D();pdf3d.ThreeDPdf("C:\\3d.pdf", "c:\\teapot.u3d");
Hiç yorum yok:
Yorum Gönder