diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj b/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj index a7b97d0f..4a64e070 100644 --- a/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj +++ b/rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj @@ -47,6 +47,10 @@ + + C:\Program Files\Rhino 6\Plug-ins\Xfinium.Pdf.Win.dll + False + @@ -200,6 +204,7 @@ + diff --git a/rhinocommon/cs/SampleCsCommands/SampleCsWritePdf.cs b/rhinocommon/cs/SampleCsCommands/SampleCsWritePdf.cs new file mode 100644 index 00000000..049682d8 --- /dev/null +++ b/rhinocommon/cs/SampleCsCommands/SampleCsWritePdf.cs @@ -0,0 +1,83 @@ +using System; +using Rhino; +using Rhino.Commands; +using Rhino.FileIO; + +namespace SampleCsCommands +{ + public class SampleCsWritePdf : Command + { + public override string EnglishName => "SampleCsWritePdf"; + + protected override Result RunCommand(RhinoDoc doc, RunMode mode) + { + var pdf = FilePdf.Create(); + + var pdf_doc = pdf.PdfDocumentImplementation() as Xfinium.Pdf.PdfFixedDocument; + if (null == pdf_doc) + return Result.Failure; + + var cover_page = pdf_doc.Pages.Add(); + + using (var font = new System.Drawing.Font("Arial", 30)) + { + var pdf_font = new Xfinium.Pdf.Graphics.PdfUnicodeTrueTypeFont(font, false) { Underline = true }; + var color = new Xfinium.Pdf.Graphics.PdfRgbColor(0, 0, 0); + var appearance = new Xfinium.Pdf.Graphics.PdfStringAppearanceOptions(pdf_font, null, new Xfinium.Pdf.Graphics.PdfBrush(color)); + var layout = new Xfinium.Pdf.Graphics.PdfStringLayoutOptions + { + HorizontalAlign = Xfinium.Pdf.Graphics.PdfStringHorizontalAlign.Center, + X = cover_page.Width / 2, + Y = cover_page.Height / 2 + }; + cover_page.Graphics.DrawString(EnglishName, appearance, layout); + } + + const int w = (int)(8.5 * 300); + const int h = 11 * 300; + + var views = doc.Views.GetViewList(true, false); + for (var i = 0; i < views.Length; i++) + { + var view = views[i]; + var viewcapture = new Rhino.Display.ViewCaptureSettings(view, new System.Drawing.Size(w, h), 300); + var page_index = pdf.AddPage(viewcapture) - 1; + using (var font = new System.Drawing.Font("Arial", 80)) + { + var pdf_font = new Xfinium.Pdf.Graphics.PdfUnicodeTrueTypeFont(font, false); + var color = new Xfinium.Pdf.Graphics.PdfRgbColor(40, 40, 40); + var pen = new Xfinium.Pdf.Graphics.PdfPen(color, 3); + var appearance = new Xfinium.Pdf.Graphics.PdfStringAppearanceOptions(pdf_font, pen, null); + var layout = new Xfinium.Pdf.Graphics.PdfStringLayoutOptions + { + HorizontalAlign = Xfinium.Pdf.Graphics.PdfStringHorizontalAlign.Center, + Rotation = 45, + X = cover_page.Width / 2, + Y = cover_page.Height / 2 + }; + pdf_doc.Pages[page_index].Graphics.DrawString("Top Secret", appearance, layout); + } + + using (var font = new System.Drawing.Font("Arial", 20)) + { + var pdf_font = new Xfinium.Pdf.Graphics.PdfUnicodeTrueTypeFont(font, false); + var color = new Xfinium.Pdf.Graphics.PdfRgbColor(0, 0, 0); + var appearance = new Xfinium.Pdf.Graphics.PdfStringAppearanceOptions(pdf_font, null, new Xfinium.Pdf.Graphics.PdfBrush(color)); + var layout = new Xfinium.Pdf.Graphics.PdfStringLayoutOptions + { + HorizontalAlign = Xfinium.Pdf.Graphics.PdfStringHorizontalAlign.Right, + X = cover_page.Width * 0.9, + Y = cover_page.Height * 0.9 + }; + pdf_doc.Pages[page_index].Graphics.DrawString($"Page {i + 1} of {views.Length}", appearance, layout); + } + } + + var path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); + path = System.IO.Path.Combine(path, EnglishName + ".pdf"); + pdf.Write(path); + + return Result.Success; + } + } +} \ No newline at end of file