Rhino Common Create pdf from Layout (PageView)

Hi there,

I want to export pdfs of a layout automatically.
Therefore I have been reading a lot in the forum:

So far, so good. I got some good results and I am happy.
But there remains 1 problem.

Page is my PageView, btw.
When I run the code below Page.PageWidth and Page.PageHeigth I get the the correct values from the layout:
210 x 297 (which is A4 Portrait)

When I take a look at the pdf then it tells me:
203.2 x 304.8 mm

Any idea how to solve this?

Thanks,
T.

Rhino.FileIO.FilePdf pdf = Rhino.FileIO.FilePdf.Create();

// Convert millimeters to inch, because DPI is "DotsPerInch"
// 1 dot/inch [dpi] = 0.0393700787401575 dot/millimeter [dot/mm]
double inch = 25.4;
int dpi = 600;

// Create size from pageWidth / height, our factor and dpi
double width = Page.PageWidth / inch;
double height = Page.PageHeight / inch;

int sizeWidth = Convert.ToInt32(width) * dpi;
int sizeHeight = Convert.ToInt32(height) * dpi;

System.Drawing.Size size = new System.Drawing.Size(sizeWidth, sizeHeight);
Rhino.Display.ViewCaptureSettings settings = new Rhino.Display.ViewCaptureSettings(Page, size, dpi);

pdf.AddPage(settings);
pdf.Write(filename);

try something like this and see if you have better luck. Modify to suite your needs.

  var unit_scale = RhinoMath.UnitScale(PaperUnits, UnitSystem.Inches);
  var scaled_width = PaperSize.Width * unit_scale;
  var scaled_height = PaperSize.Height * unit_scale;
  var scaled_size = new Size((int)(scaled_width * vcs_resolution), (int)(scaled_height * vcs_resolution));
1 Like

Hi @Trav,

thanks for the help.

It works!
I checked it with 4 PDF-viewers and they all indicate the correct paper-size!
One problem might have been that I opened the pdfs with Edge by accident (don’t ask why) and there for sure it is wrong!

But all the other viewers indicate it correctly! So this is fine.
Thanks a lot!

1 Like