//-------------------------------------------------------------------------------------------------- public PdfDomXObject(PdfDomDocument document, double[] boundingBox) : base(document, "XObject") { Attributes["Subtype"] = "/Form"; Attributes["FormType"] = 1; BoundingBox = boundingBox; }
public PdfDomAnnotation(PdfDomDocument document, string subtype, double[] rect) : base(document, "Annot") { Attributes["Subtype"] = "/" + subtype; Debug.Assert(rect.Length == 4); Attributes["Rect"] = rect.Select(v => v * PdfDomDocument.UserSpaceScale); }
//-------------------------------------------------------------------------------------------------- public PdfDom3DAnnotation(PdfDomDocument document, double[] rect, PdfDomStream stream) : base(document, "3D", rect) { document.Version = PdfVersion.PDF_1_6; _Stream = stream; Attributes["3DD"] = stream; }
//-------------------------------------------------------------------------------------------------- public PdfDomStream(PdfDomDocument document, string type) : base(document, type) { _TargetStream = new(); _Stream = _TargetStream; if (PdfDomDocument.UseCompression) { // ZLib magic header, .Net don't write, but PDF expect them // See https://www.ietf.org/rfc/rfc1950.txt _TargetStream.WriteByte(0x78); _TargetStream.WriteByte(0xDA); _DeflateStream = new (_TargetStream, CompressionLevel.Fastest, true); _Stream = _DeflateStream; Attributes["Filter"] = "/FlateDecode"; } }
//-------------------------------------------------------------------------------------------------- MemoryStream _Export(Drawing drawing) { _Document = new PdfDomDocument(); _Page = _Document.AddPage(); _Content = _Page.AddContent(); _ContentBuilder = new PdfContentBuilder(); var aabb = drawing.GetBoundingBox(); if (!aabb.IsVoid()) { double xmin = 0, xmax = 0, ymin = 0, ymax = 0; aabb.Get(ref xmin, ref ymin, ref xmax, ref ymax); _Page.MediaBox = new[] { xmin, ymin, xmax, ymax }; } // Export drawing.Render(this); var stream = _Document.WriteToStream(); _Document = null; return(stream); }
//-------------------------------------------------------------------------------------------------- public PdfDom3DBackground(PdfDomDocument document) : base(document, "3DBG") { Attributes["Subtype"] = "/SC"; }
//-------------------------------------------------------------------------------------------------- public PdfDomFontDescriptor(PdfDomDocument document) : base(document, "FontDescriptor") { _FontStream = new PdfDomStream(document, ""); }
//-------------------------------------------------------------------------------------------------- MemoryStream _Export(IEnumerable <Body> bodies) { try { var u3dSource = U3dBodyExporter.Export(bodies); if (u3dSource == null) { Messages.Error("Mesh exporting failed, cannot generate 3D PDF."); return(null); } _Document = new PdfDomDocument { Version = PdfVersion.PDF_1_6 }; _Page = _Document.AddPage(); var pageRect = new[] { 0, 0, PaperSizeX, PaperSizeY }; _Page.MediaBox = pageRect; // Create U3D stream var streamObj = new PdfDom3DStream(_Document); streamObj.Add(u3dSource); // Create view var view = streamObj.AddView("Default"); view.U3DPath = "View"; var projection = view.Projection; projection.IsPerspective = false; projection.AutomaticClipping = true; var background = view.Background; background.Color = new Color(0.75f, 0.75f, 0.75f); if (CoreContext.Current?.Viewport != null) { var vp = CoreContext.Current.Viewport; var size = vp.Size; var scale = Math.Min(PaperSizeX / size.Width, PaperSizeY / size.Height); projection.OrthographicScale = scale * PdfDomDocument.UserSpaceScale; view.OrbitCenterDistance = vp.EyePoint.Distance(vp.TargetPoint) * vp.Scale; } // Create annotation var normalAppearenceStream = new PdfDomXObject(_Document, pageRect); normalAppearenceStream.Add(PdfSnippets.NormalAppearenceFor3DAnnot); var annot = new PdfDom3DAnnotation(_Document, new[] { 0, 0, PaperSizeX, PaperSizeY }, streamObj) { IsInteractive = true, IsAutostart = true, NormalAppearence = normalAppearenceStream }; _Page.Annotations.Add(annot); // Finish var stream = _Document.WriteToStream(); _Document = null; return(stream); } catch (Exception e) { Messages.Exception($"Exception occured while exporting to U3D.", e); return(null); } }
//-------------------------------------------------------------------------------------------------- public PdfDom3DStream(PdfDomDocument document) : base(document, "3D") { Attributes["Subtype"] = "/U3D"; }