Hello Bankacount,
Thanks for your message.
Yes, we already added this as a new feature into our upgrade list, but I’m afraid it can’t be finished in a short time. Once it is available, I will let you know. As a workaround way, you can convert color Pdf file to black & white image firstly, and then drawing the image to a new Pdf. Below is the sample code for you reference. If there is any question, just feel free to write back.
- Code: Select all
PdfDocument pdf = new PdfDocument(@"Color.pdf");
PdfDocument newPdf = new PdfDocument();
for (int i = 0; i <pdf.Pages.Count; i++)
{
// Save to GreyScale images
object image = pdf.SaveAsImage(i, 400, 400);
Bitmap bm = image as Bitmap;
for (int x = 0; x <bm.Width; x++)
{
for (int y = 0; y <bm.Height; y++)
{
Color pixel = bm.GetPixel(x, y);
int R = pixel.R;
int G = pixel.G;
int B = pixel.B;
int value = ((R + G + B) / 3);
bm.SetPixel(x, y, Color.FromArgb(value, value, value));
}
}
MemoryStream GreyImgeStream = new MemoryStream();
bm.Save(GreyImgeStream, ImageFormat.Png);
//draw GreyScale images to new pdf
PdfImage pdfimg = PdfImage.FromStream(GreyImgeStream);
PdfPageBase page = newPdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0));
//Set image display location and size
float widthFitRate = pdfimg.PhysicalDimension.Width/(page.Canvas.ClientSize.Width);
float heightFitRate = (pdfimg.PhysicalDimension.Height)/(page.Canvas.ClientSize.Height);
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = (pdfimg.PhysicalDimension.Width / fitRate);
float fitHeight = (pdfimg.PhysicalDimension.Height / fitRate);
PointF position = new PointF(0, 0);
SizeF size = new SizeF(fitWidth, fitHeight);
page.Canvas.DrawImage(pdfimg, position, size);
}
//save
newPdf.SaveToFile("Result.pdf", Spire.Pdf.FileFormat.PDF);
Sincerely,
Lisa
E-iceblue support team