.NET component for converting color to PDF in grayscale

I am currently using Ghostscript to convert color PDF to black and white PDF . Now I am looking for a reliable .NET commercial or non-commercial component / library to replace ghostscript. I googled and I did not find any component / library that could do this easily or do it at all.

EDIT. # 1:

Why Ghostscript is not working for me:

I have implemented Ghostscript and I am using its native API. The problem is that Ghostscript does not support multiple interpreter instances within the same process. The -dJOBSERVER mode also does not work for me, because I do not collect all the work, and they process them all at once. It happens that Ghostscript processes a lot of work, which takes about 20 minutes, but meanwhile I get a little work that needs to be processed as soon as possible, and cannot wait 20 minutes. Another problem is that the events handled by the Ghostscript page are not easy to catch. I wrote a parser for ghostscript stdout messages, and I can read the processed page number, but not for every page when it is processed, since ghostscript displays a message for a group of processed pages. There are a few more problems with Ghostscript, for example, creating bad pdf files, duplicating font problems .....

You can find another problem I encountered with ghostscript: Ghostscript - PS to PDF - inverted image problem

-

one year after UPDATE:

Until that year, I asked this question. Later I made my own decision using iTextSharp.

You can see the conversion of PDF to grayscale solution:

http://habjan.blogspot.com/2013/09/proof-of-concept-converting-pdf-files.html

or

https://itextsharpextended.codeplex.com/

Works for me in most cases :)

+4
source share
6 answers

After a great investigation, I found out about ABCpdf from Websupergoo . Their component can easily convert any PDF page to grayscale by simply calling the Recolor method. The component is commercial.

0
source

Not quite the answer, but I think you are missing out on Ghostscript too quickly.

Do you know about the GhostScript API (for embedded Ghostscript)? Or in -dJOBSERVER mode, which can take a series of PS commands given to its standard in?

However, you still won't get your callbacks and still not multithreaded.


As already mentioned, iText can do this, but it would be necessary to go through all the content and images that look for color spaces without shades of gray and convert them to a space-specific mode.

You will also have to replace the pixel data with any images you may find.

The good news is that iText [Sharp] is capable of working in multiple threads, provided that each document is used from one thread at a time.

I suspect this also applies to the proposed commercial library, which is not so good.


And then a light came on above my head ... on a gray scale.

Blend Modes and Transparency Groups!

Take all the contents of the current page and paste it into the transparency group, which is blended with a solid black rectangle that covers the page. I think even luminosity in alpha blend mode ... let's see here.

Yes, the links section in PDF 11.6.5.2 "Soft Mask Dictionaries". You will need the luminosity group.

Now, the bad news. If your goal in switching to the gray scale is to save space, this will fail completely. This will actually make each file a little big ... say 100 bytes per page, give or take.

Better PDF software will also be very hot. No need to apply your cousin's rendering project. This is the extended graphic material here, often used by Common PDF Files, so the last kind of thing to be implemented.

So ... For each source page

  • Create a new page.

  • Cover it with a black background.

  • Cover it with a white rectangle (if it was back before) in the transparency group, which uses the soft mask dictionary, which is the luminosity of the original content of the page (now it is placed in the XObject form).

Since this is your own code, you will have ample opportunity to do what you want to do at the beginning or end of each page.

Golly, this is just crazy to work! This requires some PDF-Fu, but not as much as "converting each color space and image differently when I view a document." Deeper knowledge, less code to write.

+3
source

This is not a .net library, but rather a potential work. You can install a virtual printer capable of writing PDF files. I would suggest CutePDF because it is free, easy to use, and does a great job of β€œprinting” a large number of PDF file formats. You can do almost anything with CutePDF, which you can do with a regular printer, including grayscale printing.

After installing the virtual printer, you can use C # to β€œprint” the grayscale version.

Edit: I just remembered that the free version is not quiet. After printing to the CutePDF printer, it will ask you to "Save As." They have an SDK available for purchase, but I could not say if it could help you convert to shades of gray.

+2
source

If a commercial product is your option, let me recommend Amyuni PDF Creator.Net . Using it, you can list all the elements inside the page and accordingly change their colors, images can also be set as shades of gray. Regular disclaimers apply

Sample code using Amyuni PDF Creator ActiveX, .Net version will be similar:

pdfdoc.ReportState = ReportStateConstants.acReportStateDesign; object[] page_items = (object[])pdfdoc.get_ObjectAttribute("Pages[1]", "Objects"); string[] color_attributes = new string[] { "TextColor", "BackColor", "BorderColor", "StrokeColor" }; foreach (acObject page_item in page_items) { object _type = page_item["ObjectType"]; if ((ACPDFCREACTIVEX.ObjectTypeConstants)_type == ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture) { page_item["GrayScale"] = true; } else foreach (string attr_name in color_attributes) { try { Color color = System.Drawing.ColorTranslator.FromWin32((int)page_item[attr_name]); int grayColor = (int)(0.3 * color.R + 0.59 * color.G + 0.11 * color.B); int newColorRef = System.Drawing.ColorTranslator.ToWin32(Color.FromArgb(grayColor, grayColor, grayColor)); page_item[attr_name] = newColorRef; } catch { } //not all items have all kinds of color attributes } } 
+1
source

Until that year, I asked this question. Later I made my own decision using iTextSharp.

You can see converting PDF to grayscale solution: https://itextsharpextended.codeplex.com/

+1
source

iTextPdf is a good product for creating / managing pdf, it has both commercial and free versions.

Take a look at aspose.pdf for .net , it provides below functions and more.

  • Add or remove watermarks from a PDF
  • Set page size, size, orientation, transition type, zoom factor and appearance of the PDF document.
  • ..

And here is a list of open source PDF libraries.

0
source

All Articles