private static void DrawImagesInPage_Postcard(PdfImage img1, PdfImage img2, PdfPageBase page, float w, float h, float distance_btw_images, Globals.AspectRatio aspectRatioImage1, Globals.AspectRatio aspectRatioImage2) { float heightBtwImages = PrintIO.InPoints(distance_btw_images); //PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); DrawImageInFrame_wxh_Postcard(img1, page, 0, w, h, aspectRatioImage1); DrawImageInFrame_wxh_Postcard(img2, page, h + heightBtwImages, w, h, aspectRatioImage2); //if (img2 != null) //{ // if (aspectRatioImage2 == AspectRatio.S4x3) // { }
internal static void SetPageMarginGeneratePDF_ImageRatio4x3_A5(string ImageFileName, PdfImage img1, PdfImage img2, Globals.AspectRatio aspectRatioImage1 = Globals.AspectRatio.S4x3, Globals.AspectRatio aspectRatioImage2 = Globals.AspectRatio.S4x3) { float MARGINTOP_BOTTOM = 0.75f; float MARGINLEFT_RIGHT = 1.25f; float DISTANCE_BTW_IMAGES = 0.5F; ///Create a pdf document Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument(); //Set the margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = PrintIO.InPoints(MARGINTOP_BOTTOM);//unitCvtr.ConvertUnits(MARGINTOP_BOTTOM, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; //TODO: Add margins in global settings xml file. margin.Left = PrintIO.InPoints(MARGINLEFT_RIGHT); //unitCvtr.ConvertUnits(MARGINLEFT_RIGHT, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float A4Height = unitCvtr.ConvertUnits(PdfPageSize.A4.Height, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter); float A4Width = unitCvtr.ConvertUnits(PdfPageSize.A4.Width, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter); //After margin float A4PostMarginWidth = PdfPageSize.A4.Width - (margin.Left * 2); // left,right margins //Adjust width, height with 4:3 ratio in PDF points : float A4PostMarginWidthPts4x3 = PdfPageSize.A4.Width - (margin.Left * 2); // left,right margins float A4PostMarginHeightPts4x3 = A4PostMarginWidthPts4x3 * 0.75f; // height = 3/4 * width //TransformText(page); DrawImagesInPage_A5(img1, img2, page, A4PostMarginWidthPts4x3, A4PostMarginHeightPts4x3, DISTANCE_BTW_IMAGES, aspectRatioImage1, aspectRatioImage2); //TransformImage(page); //Save the document doc.SaveToFile(ImageFileName); doc.Close(); if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic") { PrintIO.PDFDocumentViewer(ImageFileName); } }
private static void DrawImagesInPage_A4(PdfImage img1, PdfPageBase page, float w, float h, float distance_btw_images, Globals.AspectRatio aspectRatioImage1) { DrawImageInFrame_wxh_A4(img1, page, 0, w, h, aspectRatioImage1); }
private static void DrawImageInFrame_wxh_Postcard(PdfImage img, PdfPageBase page, float y, float w, float h, Globals.AspectRatio aspectRatioImage1) { PdfBrush brush = new PdfSolidBrush(Color.Silver); // float heightBtwImages = unitCvtr.ConvertUnits(0.5f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); //Load an image if (img != null) { if (aspectRatioImage1 == Globals.AspectRatio.S6x4) { page.Canvas.DrawImage(img, new System.Drawing.RectangleF(0, y, w, h)); } else { page.Canvas.DrawRectangle(brush, new Rectangle(new Point(0, (int)y), new Size(Convert.ToInt32(w), Convert.ToInt32(h)))); } if (aspectRatioImage1 == Globals.AspectRatio.GreaterThanS6x4) { float new_h = w * img.Height / img.Width; float new_MarginTopBottom = (h - new_h) / 2; page.Canvas.DrawImage(img, new System.Drawing.RectangleF(0, y + new_MarginTopBottom, w, new_h)); //use width of frame, adjust height. } if (aspectRatioImage1 == Globals.AspectRatio.LessThanS6x4) { float new_w = h * img.Width / img.Height; float new_MarginLeftRight = (w - new_w) / 2; page.Canvas.DrawImage(img, new System.Drawing.RectangleF(new_MarginLeftRight, y, new_w, h)); //use width of frame, adjust height. //Graphics.FromImage(img.); } } }