using (var rasterizer = new PdfRasterizer(new Foxit.PDF.Rasterizer.InputPdf(pdfData))) { // Create a JpegImageFormat object. var jpegImageFormat = new JpegImageFormat(100); // Create a FixedImageSize object with required width and height. var imageSize = new PercentageImageSize(400); // Save the image. var imageDataPage1 = rasterizer.Draw(jpegImageFormat, imageSize); using (var pd = new PrintDocument()) { var margins = new Margins(0, 40, 0, 40); pd.DefaultPageSettings.Margins = margins; pd.DefaultPageSettings.Color = true; pd.DefaultPageSettings.Landscape = false; pd.PrintPage += (sender, args) => PrintPage(text1, text2, imageDataPage1, args); pd.Print(); } }
private static int counter = 0; private static void PrintPage(string text1, string text2, byte[][] imageData, PrintPageEventArgs args) { foreach (var b in imageData) { using (var stream = new MemoryStream(b)) { var i = Image.FromStream(stream); CreateNotApprovedWatermark(i, text1, text2); if (args.PageSettings.PrinterSettings.CanDuplex) { args.PageSettings.PrinterSettings.Duplex = Duplex.Horizontal; } var m = args.MarginBounds; if (i.Width / (double)i.Height > m.Width / (double)m.Height) // image is wider { m.Height = (int)(i.Height / (double)i.Width * m.Width); } else { m.Width = (int)(i.Width / (double)i.Height * m.Height); } args.Graphics.DrawImage(i, m); if (counter <= 2) { counter++; args.HasMorePages = true; } else { args.HasMorePages = false; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)