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

  • SEARCH
  • Home
  • 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 382515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:11:24+00:00 2026-05-12T15:11:24+00:00

I have a PDF with a black background and white/yellow text. How can I

  • 0

I have a PDF with a black background and white/yellow text.

How can I remove the black background before printing and invert the color of the text?

  • 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-12T15:11:25+00:00Added an answer on May 12, 2026 at 3:11 pm

    This is likely to be non-trivial to solve in general, but if you have a predictable collections of PDFs (say, all from the same source) then you may be able to hack together a quick solution like so:

    • install CAM::PDF from CPAN
    • run “getpdfpage.pl my.pdf 1 > page1.txt” to get the graphic codes for page 1
    • search for ” rg” to find where the RGB text color is changed (or “RG” for background, or maybe “g” or “G” for grayscale or “k” or “K” for CMYK colors “sc” or “SC” for special colorspaces)
    • edit page1.txt to set the colors you like
    • run “setpdfpage.pl my.pdf 1 page1.txt out.pdf”

    All of this can be done programmatically instead of via command line tools too. getpdfpage.pl and setpdfpage.pl are simple little wrappers around the CAM::PDF API.

    A general solution would be to use getPageContentTree() to parse the PDF page syntax and search for the color changing operators and alter them. But if your PDF uses a custom color space (“sc”) this can be tricky. And searching for the operator that does the full-page black fill could be hard too, depending on the geometry.

    If you provide an URL for a sample PDF, I could provide some more specific advice.

    UPDATE: on a whim, I wrote a rudimentary color changer script that may work for some PDFs. To use it, run like this example which turns any red element green instead:

    perl recolor.pl input.pdf '1 0 0 rg' '0 1 0 rg' out.pdf
    

    This requires you to know the PDF syntax of the color directives you’re trying to change, so it may still require something like the getpdfpage.pl steps recommended above.

    And the source code:

    #!/usr/bin/perl -w                      
    
    use strict;
    use CAM::PDF;
    use CAM::PDF::Content;
    
    my %COLOROPS = map {$_ => 1} qw(rg RG g G k K sc SC);
    
    my $pdf = CAM::PDF->new(shift) || die $CAM::PDF::errstr;
    my @oldcolors;
    my @newcolors;
    while (@ARGV >= 2) {
       push @oldcolors, parseColor(shift);
       push @newcolors, parseColor(shift);
    }
    my $out = shift || '-';
    
    for my $p (1 .. $pdf->numPages) {
       my $page = $pdf->getPageContentTree($p);
       traverse($page->{blocks});
       $pdf->setPageContent($p, $page->toString());
    }
    $pdf->cleanoutput($out);
    
    sub parseColor {
       my ($in) = @_;
       my $ops = CAM::PDF::Content->new($in);
       die 'Invalid color syntax in ' . $in if !$ops->validate();
       my @blocks = @{$ops->{blocks}};
       die 'Expected one color operator in ' . $in if @blocks != 1;
       my $color = $blocks[0];
       die 'Not a color operator in ' . $in if !exists $COLOROPS{$color->{name}};
       return $color;
    }
    
    sub traverse {
       my ($blocks) = @_;
       for my $op (@{$blocks}) {
          if ($op->{type} eq 'block') {
             traverse($op->{value});
          } elsif (exists $COLOROPS{$op->{name}}) {
           COLOR:
             for (my $i=0; $i < @oldcolors; ++$i) {
                my $old = $oldcolors[$i];
                if ($old->{name} eq $op->{name} && @{$old->{args}} == @{$op->{args}}) {
                   for (my $v=0; $v < @{$op->{args}}; ++$v) {
                      next COLOR if $old->{args}->[$v]->{value} != $op->{args}->[$v]->{value};
                   }
                   # match! so we will replace                                                                                  
                   $op->{name} = $newcolors[$i]->{name};
                   @{$op->{args}} = @{$newcolors[$i]->{args}};
                   last COLOR;
                }
             }
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with color and black & white images, when I use
I have a project that has to export images to PDF. Images and text
Background: I have a website where people can store transactions. As part of this
Some background to this question can be found at Check printing with Java/JSP and
I have an Oracle Report that must be in pure Black and White. It
I have pdf document, for example 25 pages. How to add one blank page
I have open pdf file through my application.when click on device back button it
in my application, I have pdf files. I want to save those pdf files
I have multiple pdf files. Based on user input i am loading the pdf
I have several PDF templates that I would like to load and modify 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.