尝试pdf中添加视点
This commit is contained in:
parent
6451f0d13e
commit
00282c60bf
@ -16,26 +16,26 @@ public class Program
|
|||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
GenerateU3D(args[0], args[1]);
|
GeneratePDF(args[0], args[1]);
|
||||||
}
|
}
|
||||||
public static void GenerateU3D(string idtf, string pdf)
|
public static void GenerateU3D(string idtf, string u3d)
|
||||||
{
|
{
|
||||||
var temp = System.IO.Path.GetTempFileName();
|
|
||||||
System.Diagnostics.Process exep = new System.Diagnostics.Process();
|
System.Diagnostics.Process exep = new System.Diagnostics.Process();
|
||||||
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
||||||
startInfo.FileName = IDTFTool;
|
startInfo.FileName = IDTFTool;
|
||||||
startInfo.Arguments = $"-input \"{idtf}\" -output \"{temp}\"";
|
startInfo.Arguments = $"-input \"{idtf}\" -output \"{u3d}\"";
|
||||||
startInfo.CreateNoWindow = true;
|
startInfo.CreateNoWindow = true;
|
||||||
startInfo.UseShellExecute = false;
|
startInfo.UseShellExecute = false;
|
||||||
exep.StartInfo = startInfo;
|
exep.StartInfo = startInfo;
|
||||||
exep.Start();
|
exep.Start();
|
||||||
exep.WaitForExit();
|
exep.WaitForExit();
|
||||||
GeneratePDF(temp, pdf);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GeneratePDF(string u3d, string pdf)
|
public static void GeneratePDF(string idtf, string pdf)
|
||||||
{
|
{
|
||||||
|
var u3d = System.IO.Path.GetTempFileName();
|
||||||
|
GenerateU3D(idtf, u3d);
|
||||||
|
|
||||||
var writer = new PdfWriter(pdf);
|
var writer = new PdfWriter(pdf);
|
||||||
PdfDocument pdfDoc = new PdfDocument(writer);
|
PdfDocument pdfDoc = new PdfDocument(writer);
|
||||||
var size = PageSize.A4;
|
var size = PageSize.A4;
|
||||||
@ -43,23 +43,27 @@ public class Program
|
|||||||
Document doc = new Document(pdfDoc);
|
Document doc = new Document(pdfDoc);
|
||||||
Rectangle rect = new Rectangle(50, 50, size.GetWidth() - 100, size.GetHeight() - 100);
|
Rectangle rect = new Rectangle(50, 50, size.GetWidth() - 100, size.GetHeight() - 100);
|
||||||
|
|
||||||
PdfStream stream3D = new PdfStream(pdfDoc, new FileStream(u3d, FileMode.Open));
|
|
||||||
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();
|
PdfDictionary dict3D = new PdfDictionary();
|
||||||
dict3D.Put(PdfName.Type, new PdfName("3DView"));
|
dict3D.Put(PdfName.Type, new PdfName("3DView"));
|
||||||
dict3D.Put(new PdfName("XN"), new PdfString("Default"));
|
dict3D.Put(new PdfName("XN"), new PdfString("SHITTTTTTT"));
|
||||||
dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
|
//dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
|
||||||
dict3D.Put(new PdfName("MS"), PdfName.M);
|
dict3D.Put(new PdfName("MS"), PdfName.M);
|
||||||
dict3D.Put(new PdfName("C2W"),
|
dict3D.Put(new PdfName("C2W"),
|
||||||
new PdfArray(new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }));
|
new PdfArray(new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }));
|
||||||
dict3D.Put(PdfName.CO, new PdfNumber(235));
|
//dict3D.Put(PdfName.CO, new PdfNumber(235));
|
||||||
|
|
||||||
|
PdfStream stream3D = new PdfStream(pdfDoc, new FileStream(u3d, FileMode.Open));
|
||||||
|
stream3D.Put(PdfName.Type, new PdfName("3D"));
|
||||||
|
stream3D.Put(PdfName.Subtype, new PdfName("U3D"));
|
||||||
|
stream3D.Put(new PdfName("VA"), new PdfArray(new PdfDictionary[] { dict3D }));
|
||||||
|
stream3D.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
|
||||||
|
stream3D.Flush();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
|
Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
|
||||||
annot.SetContents(new PdfString("3D Model"));
|
annot.SetContents(new PdfString("3D Model"));
|
||||||
annot.SetDefaultInitialView(dict3D);
|
annot.SetDefaultInitialView(dict3D);
|
||||||
var page = pdfDoc.AddNewPage(size).SetRotation(90);
|
var page = pdfDoc.AddNewPage(size).SetRotation(90);
|
||||||
page.AddAnnotation(annot);
|
page.AddAnnotation(annot);
|
||||||
|
Loading…
Reference in New Issue
Block a user