public CardPdfBuilder(PageSize pageSize, double scalingPercent, bool hasCutLines, CutLineSizes cutLineSize, XKnownColor cutLineColor) { PageSize = pageSize; ScalingPercent = scalingPercent; HasCutLines = hasCutLines; CutLineSize = cutLineSize; CutLineColor = cutLineColor; Document = new PdfDocument { Info = { Title = "Card Mimic", Author = "Sean Bodine", CreationDate = DateTime.Now, Creator = "Card Mimic", Subject = "MTG Proxies", } }; var firstPage = new PdfPage { Size = PageSize }; Document.AddPage(firstPage); Pages = new List <CardPage> { new CardPage(firstPage, ScalingPercent, HasCutLines, CutLineSize, CutLineColor) }; }
/// <summary> /// Converts the enum to the actual width of the line. /// </summary> public static double ToPointSize(this CutLineSizes en) { switch (en) { case CutLineSizes.Small: return(0.5); case CutLineSizes.Medium: return(1); case CutLineSizes.QuiteLarge: return(1.5); case CutLineSizes.Colossal: return(8); case CutLineSizes.ALineToSurpassMetalGear: return(16); case CutLineSizes.Chuck: return(32); default: throw new ArgumentOutOfRangeException(nameof(en), en, @"Enum value not handled in switch."); } }
public CardPage(PdfPage page, double scalingPercent, bool hasCutLines, CutLineSizes cutLineSize, XKnownColor cutLineColor) { ScalingPercent = scalingPercent; HasCutLines = hasCutLines; CutLineSize = cutLineSize; CutLineColor = cutLineColor; Gfx = XGraphics.FromPdfPage(page); // Set Gutter GutterThickness = HasCutLines ? CutLineSize.ToPointSize() : 0; // Set some properties other methods will need to use. PointsPerInch = page.Width.Point / page.Width.Inch; Margin = 0.25 * PointsPerInch; UseableX = page.Width - 2 * Margin; UseableY = page.Height - 2 * Margin; // MTG cards are 3.48 x 2.49 inches or 63 x 88 mm, then slightly scaled down to fit better in card sleeves. CardSize = new XSize(2.49 * PointsPerInch * ScalingPercent / 100 * 0.99, 3.48 * PointsPerInch * ScalingPercent / 100 * 0.99); // Predict the number of cards per row and cards per column. Rows = (int)((UseableY - GutterThickness) / (CardSize.Height + GutterThickness)); Columns = (int)((UseableX - GutterThickness) / (CardSize.Width + GutterThickness)); CardsPerPage = Rows * Columns; // Calculate how much to shift all images to center everything on the page. Helps with printers which have trouble printing near the edge. var usedY = GutterThickness + (Rows * (CardSize.Height + GutterThickness)); var usedX = GutterThickness + (Columns * (CardSize.Width + GutterThickness)); // Half of what is not used inside the margins VerticalCenteringOffset = (UseableY - usedY) / 2.0; HorizontalCenteringOffset = (UseableX - usedX) / 2.0; }