private PdfSharp.Drawing.XSize GetImageSize(System.Drawing.Bitmap bitmap) { float resolution = 72; PdfSharp.Drawing.XUnit imgWidthPt = PdfSharp.Drawing.XUnit.FromPoint(((float)bitmap.Width) * resolution / bitmap.HorizontalResolution); PdfSharp.Drawing.XUnit imgHeightPt = PdfSharp.Drawing.XUnit.FromPoint(((float)bitmap.Height) * resolution / bitmap.VerticalResolution); return(new PdfSharp.Drawing.XSize(imgWidthPt, imgHeightPt)); }
/// <summary>Set page size in millimeter</summary> /// <param name="width_mm"></param> /// <param name="heigth_mm"></param> public void setPageSize(int width_mm, int heigth_mm) { PdfSharp.Drawing.XUnit width = PdfSharp.Drawing.XUnit.FromMillimeter(width_mm); PdfSharp.Drawing.XUnit heigth = PdfSharp.Drawing.XUnit.FromMillimeter(heigth_mm); _page.Width = width; _page.Height = heigth; _size.Width = width; _size.Height = heigth; _area.Width = _area.Width + (width - _page.Width); _area.Height = _area.Height + (heigth - _page.Height); _verticalPosition = _verticalPosition + heigth - _page.Height; }
/// <summary>Set page margins in millimeter</summary> /// <param name="left_mm">Left margin in millimetter</param> /// <param name="rigth_mm">Rigth margin in millimetter</param> /// <param name="top_mm">Top margin in millimetter</param> /// <param name="bottom_mm">Bottom margin in millimetter</param> public void setMargins(int left_mm, int rigth_mm, int top_mm, int bottom_mm) { PdfSharp.Drawing.XUnit left = PdfSharp.Drawing.XUnit.FromMillimeter(left_mm); PdfSharp.Drawing.XUnit top = PdfSharp.Drawing.XUnit.FromMillimeter(top_mm); _horizontalePosition = _horizontalePosition + left - _area.X; _verticalPosition = _verticalPosition + top - _area.Y; _area = new PdfSharp.Drawing.XRect { X = left, Y = top, Width = _page.Width - PdfSharp.Drawing.XUnit.FromMillimeter(left_mm + rigth_mm), Height = _page.Height - PdfSharp.Drawing.XUnit.FromMillimeter(top_mm + bottom_mm) }; }