The printer settings doesn't affected in the Kyocera TASKalfa 2554ci KX printer's output using `PrintDocument`
Raja VIGNESH B
0
Reputation points
Hi team,
While printing the image using the System.Drawing.Printing.PrintDocument
with printer settings, the color changes was not reflected in this printer(Kyocera TASKalfa 2554ci KX) and it works fine in other printers. Eg., If we set the color of the printer settings as false(greyscale), still the image prints with color in this mentioned printer and it prints in greyscale for other printers. We have used the below code snippet for printing.
private Bitmap image;
private int itr = 0;
private void Print_Click(object sender, EventArgs e)
{
//Load the PDF document as a stream
FileStream inputStream = new FileStream("../../F#.pdf", FileMode.Open, FileAccess.ReadWrite);
image = ConvertStreamsToBitmap(inputStream);
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += PrintDocument_PrintPage;
printDocument.DefaultPageSettings.Color = false;
printDocument.Print();
}
private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int imageWidth = image.Width;
int imageHeight = image.Height;
if (imageWidth > imageHeight)
{
image.RotateFlip(RotateFlipType.Rotate90FlipNone); // Rotate clockwise by 90 degrees
int temp = imageWidth;
imageWidth = imageHeight;
imageHeight = temp;
}
// Calculate the scaling factor to fit the image within the page size
float scaleX = (float)e.PageSettings.PaperSize.Width / imageWidth;
float scaleY = (float)e.PageSettings.PaperSize.Height / imageHeight;
float scaleFactor = Math.Min(scaleX, scaleY);
// Calculate the position to center the image on the page
int posX = (int)((e.PageSettings.PaperSize.Width - (imageWidth * scaleFactor)) / 2);
int posY = (int)((e.PageSettings.PaperSize.Height - (imageHeight * scaleFactor)) / 2);
// Draw the image on the page
e.Graphics.DrawImage(image, posX, posY, imageWidth * scaleFactor, imageHeight * scaleFactor);
}
public static Bitmap ConvertStreamsToBitmap(Stream stream)
{
Bitmap bitmaps = new Bitmap(stream);
return bitmaps;
}
Sign in to answer