How to know given PDF file is color pdf or graypdf

Jan 30, 2014 at 7:37 AM
Hi
Is it possible to know given PDF is color pdf or gray pdf using Ghostscript.NET?
Is it possible to extract information form /colorSpace object using Ghostscript.NET?

Thanks in Advanced
Coordinator
Jan 31, 2014 at 2:22 PM
Edited Jan 31, 2014 at 2:27 PM
Hi,

Ghostscript device called inkcov can detect whether a PDF page uses color or not. It displays the ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally).

I wrote you a small routine that will return you ink coverage for each page:
    /// <summary>
    /// Supported only in Ghostscript v9.05 or newer.
    /// </summary>
    public static string GetInkCoverage(string file)
    {
        GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
        string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");

        List<string> switches = new List<string>();
        switches.Add("-empty");
        switches.Add("-q");
        switches.Add("-o" + outputPipeHandle);
        switches.Add("-sDEVICE=inkcov");
        switches.Add(file);

        GhostscriptProcessor proc = new GhostscriptProcessor();
        proc.StartProcessing(switches.ToArray(), null);

        byte[] data = gsPipedOutput.Data;

        return System.Text.Encoding.ASCII.GetString(data);
    }

So, for PDF with 6 pages you will get the output similar to this one:

C (cyan) M (magenta) Y (yellow) K (black)

0.00000 0.00000 0.00000 0.01721 CMYK OK
0.00000 0.00000 0.00000 0.03788 CMYK OK
0.00000 0.00000 0.00000 0.04137 CMYK OK
0.00000 0.00000 0.00000 0.00621 CMYK OK
0.00000 0.00000 0.00000 0.01462 CMYK OK
0.00000 0.00000 0.00000 0.01103 CMYK OK

Where a value of 1.00000 maps to 100% ink coverage for the respective color channel. So 0.01721 in the first line of the result means 1.72 % of the first page area is covered by black ink.

I hope this helps.

Cheers,
Josip
Feb 5, 2014 at 3:31 AM
Hi
Thanks for Reply.When I execute these code then given error. PPP() is not fond from assembly .I am using Ghostscript.NET.v.1.1.2.dll. Again as your instruction I inserted code 'proc.StartProcessing(switches.ToArray(), null);' instead of 'proc.StartProcessing(switches.ToArray(), new PPP());'.
But It not work properly. I attached error snapsot

Thanks in advanced



Coordinator
Feb 5, 2014 at 10:06 AM
What happens when you execute this line:
proc.StartProcessing(switches.ToArray(), null);
?
Coordinator
Feb 5, 2014 at 5:15 PM
I made GhostscriptPdfInfo.GetInkCoverage function as part of Ghostscript.NET v.1.1.3.

Take a look at this sample: https://ghostscriptnet.codeplex.com/SourceControl/latest#Ghostscript.NET/Ghostscript.NET.Samples/Samples/GetInkCoverageSample.cs

This should work for you.

Cheers,
Josip
Feb 7, 2014 at 11:23 AM
Hi
Thanks it work fine but I am not get font color of pdf file.attached the pdf below.
Is there any procedure to get font color?

Thanks in advanced
:)



Coordinator
Feb 7, 2014 at 11:27 AM
Edited Feb 7, 2014 at 11:27 AM
Hi,

I don't see the pdf you attached. Can you please email it to me at: habjan@gmail.com

Cheers,
Josip
Apr 24, 2014 at 6:03 PM
I'm so sorry, but I'm newby and dont know how this work.

Can you please help me to put this script working? step by step?
I just need to get pdf cmyk coverage.

Thanks in advance
Luis Cortes
Coordinator
Apr 24, 2014 at 6:16 PM
Edited Apr 24, 2014 at 6:19 PM
Hi,

Can you please post a code that you have at the moment? What exactly are you trying to do?

This sample is pretty simple and it does exactly what you need:
https://ghostscriptnet.codeplex.com/SourceControl/latest#Ghostscript.NET/Ghostscript.NET.Samples/Samples/GetInkCoverageSample.cs

Cheers,
Josip
Apr 24, 2014 at 6:21 PM
Dear Josip

Thank you very much for your answer.
That's the code that I need, but how can I put it working?

Sorry, but I'm really newby...
Coordinator
Apr 25, 2014 at 10:50 AM
Edited Apr 25, 2014 at 10:51 AM
Hi,

It depends what actually are you trying to do?

Easiest way is:
  1. Create new Project in Visual Studio (for instance Console project or Windows Forms project).
  2. Add reference to Ghostscript.NET.dll (manually or via NuGet)
  3. In your code file (class) add this namespace: using System.Collections.Generic;
  4. When you want to get ink coverage, simply call GetInkCoverage like this:
    Dictionary<int, GhostscriptPageInkCoverage> pages = GhostscriptPdfInfo.GetInkCoverage("testfile.pdf");
  5. The result will be a Dictionary which contains CMYK ink coverage for each page.
Cheers,
Josip
Apr 28, 2014 at 8:58 AM
Dear Josip.

Thank you very much for your reply.
This is much dificult that I can handle... So sorry, but I cant do this.
I own a copy centre and just wish to know the coverage of a document before I print it, so I can practice lower prices without loosing money.
But I cant promgram myself. I wish I find a software that give me the coverage percentage of a pdf file, but its not easy...

Thanks again
Luis Cortes


2014-04-25 11:50 GMT+01:00 josip <[email removed]>:

From: josip

Hi,

It depends what actually are you trying to do?

Easiest way is:
  1. Create new Project in Visual Studio (for instance Console project or Windows Forms project).
  2. Add reference to Ghostscript.NET.dll. (manually or via NuGet)
  3. In your code file (class) add this namespace: using System.Collections.Generic;
  4. When you want to get ink coverage, simply call GetInkCoverage like this:
    Dictionary<int, GhostscriptPageInkCoverage> pages = GhostscriptPdfInfo.GetInkCoverage("testfile.pdf");
  5. The result will be a Dictionary which contains CMYK ink coverage for each page.
Cheers,
Josip

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
Aviso de Confidencialidade:
Este e-mail e quaisquer ficheiros informáticos com ele transmitidos são confidenciais,
podem conter informação privilegiada e destinam-se ao conhecimento e uso exclusivo da
pessoa ou entidade a quem são dirigidos, não podendo o conteúdo dos mesmos ser alterado,
divulgado, copiado, gravado ou distribuido, nos termos da lei vigente.
Se não é o destinatário da mensagem, ou se ela lhe foi enviada por engano, queira
informar de imediato o remetente e proceder à destruição da mensagem e de eventuais cópias.
Obrigado.
Apr 28, 2014 at 6:08 PM
Dear Josip,

By respect of your wonderful work, and because you lost precious time replying me, I decide to put hands on work, and find a solution.

I download a freeware Xaramin Studio, from Monodevelop and try to compile.

For now, I cant do anything, so if you could help me a bit, I'll apreciate.
Can you send me an example of what you write in Visual Studio, just to give me some guide lines?
Thanks a lot again

Luis Cortes




2014-04-28 9:58 GMT+01:00 Luis Cortes <[email removed]>:
Dear Josip.

Thank you very much for your reply.
This is much dificult that I can handle... So sorry, but I cant do this.
I own a copy centre and just wish to know the coverage of a document before I print it, so I can practice lower prices without loosing money.
But I cant promgram myself. I wish I find a software that give me the coverage percentage of a pdf file, but its not easy...

Thanks again
Luis Cortes


2014-04-25 11:50 GMT+01:00 josip <[email removed]>:

From: josip

Hi,

It depends what actually are you trying to do?

Easiest way is:
  1. Create new Project in Visual Studio (for instance Console project or Windows Forms project).
  2. Add reference to Ghostscript.NET.dll. (manually or via NuGet)
  3. In your code file (class) add this namespace: using System.Collections.Generic;
  4. When you want to get ink coverage, simply call GetInkCoverage like this:
    Dictionary<int, GhostscriptPageInkCoverage> pages = GhostscriptPdfInfo.GetInkCoverage("testfile.pdf");
  5. The result will be a Dictionary which contains CMYK ink coverage for each page.
Cheers,
Josip

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
Aviso de Confidencialidade:
Este e-mail e quaisquer ficheiros informáticos com ele transmitidos são confidenciais,
podem conter informação privilegiada e destinam-se ao conhecimento e uso exclusivo da
pessoa ou entidade a quem são dirigidos, não podendo o conteúdo dos mesmos ser alterado,
divulgado, copiado, gravado ou distribuido, nos termos da lei vigente.
Se não é o destinatário da mensagem, ou se ela lhe foi enviada por engano, queira
informar de imediato o remetente e proceder à destruição da mensagem e de eventuais cópias.
Obrigado.



--
Aviso de Confidencialidade:
Este e-mail e quaisquer ficheiros informáticos com ele transmitidos são confidenciais,
podem conter informação privilegiada e destinam-se ao conhecimento e uso exclusivo da
pessoa ou entidade a quem são dirigidos, não podendo o conteúdo dos mesmos ser alterado,
divulgado, copiado, gravado ou distribuido, nos termos da lei vigente.
Se não é o destinatário da mensagem, ou se ela lhe foi enviada por engano, queira
informar de imediato o remetente e proceder à destruição da mensagem e de eventuais cópias.
Obrigado.