Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5946489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:49:49+00:00 2026-05-22T16:49:49+00:00

I have some PDF files that I need to modify using a PHP script.

  • 0

I have some PDF files that I need to modify using a PHP script. I’m also able to exec() so I can use pretty much anything that runs on CentOS.

The PDF files when opened through Adobe Acrobat Pro X, show 2 layers in the “layers” panel:

  1. Background
  2. Color

When I disable both of these layers I end up with a black & white text & images (the text is not vector tho, it’s a scanned document).

I want to disable these layers and any other similar layer found in the PDFs using PHP and/or C# or any command-line tool.

Other useful information:

When I run pdfimages (provided with XPDF) on my PDFs, it extracts exactly what I actually need removed from each page…

Additional Information Update:
I modified the PDFSharp example here: http://www.pdfsharp.net/wiki/ExportImages-sample.ashx :

Modified:
Line 28: ExportImage(xObject, ref imageCount);

To:
PdfObject obj = xObject.Elements.GetObject("/OC");
Console.WriteLine(obj);

I got the following output in the console for each image:
<< /Name Background /Type /OCG >>
<< /OCGs [ 2234 0 R ] /P /AllOff /Type /OCMD >>
<< /Name Text Color /Type /OCG >>

Which is actually the layer information, and the PDFSharp Documentation for the /OC key:

Before the image is processed, its
visibility is determined based on this
entry. If it is determined to be
invisible, the entire image is
skipped, as if there were no Do
operator to invoke it.

So now, how do I modify the /OC value to something that will make these layers invisible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:49:49+00:00Added an answer on May 22, 2026 at 4:49 pm

    After long hours of experimenting, I found the way! I’m posting the code so someone may find it helpful in the future:

    using System;
    using System.IO;
    using System.Collections.Generic;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    
    namespace LayerHide {
    
        class MainClass
        {
            public static void Main (string[] args)
            {
    
                PdfReader reader = new PdfReader("test.pdf");
                PdfStamper stamp = new PdfStamper(reader, new FileStream("test2.pdf", FileMode.Create));
                Dictionary<string, PdfLayer> layers = stamp.GetPdfLayers();
    
                foreach(KeyValuePair<string, PdfLayer> entry in layers )
                {
                    PdfLayer layer = (PdfLayer)entry.Value;
                    layer.On = false;
                }
    
                stamp.Close();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download some files. I have written a php script that
On my php webapp i have to generate some pdf files(between 5 and 20).
I have some old files that need to point to new files - the
We have an application that generates pdf files, some times for some unknown reason,
I have some PDF files in a public rails folder. I want to set
I have some pdf files located on a http server: Like: http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf
I have a directory to which a process uploads some .pdf files. This process
Let's say I have a collection of PDF files with the following paths: /some/path/pdfs/birds/duck.pdf
I have several pdf files of some lecture slides. I want to do the
I have a process that's going to initially generate 3-4 million PDF files, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.