The printer settings doesn't affected in the Kyocera TASKalfa 2554ci KX printer's output using `PrintDocument`

Raja VIGNESH B 0 Reputation points
2024-08-12T12:26:43.39+00:00

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;
}

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,012 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.