从PDF删除图像

扫码查看
本文介绍了从PDF删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了从带有ghostscript的后记文件中创建仅包含文本且没有图像的tiff ,并尝试使用KenS.的答案.但是此方法仅删除黑色"图像-图像仅包含黑色通道中的数据(PDF具有色域CMYK).如何删除我的情况下的所有图像?

I read Create a tiff with only text and no images from a postscript file with ghostscript and try to use KenS`s answer.But this method remove only "black" images - image contain data only in black channel (PDF has colorspace CMYK). How can i remove all images in my case?

推荐答案

这做得更好,但是不完整.例如,它不处理使用多个数据源的图像.它基本上未经测试,只是我通过使用ps2write转换为PostScript,然后使用下面的PostScript程序以及pdfwrite设备转换为PDF来测试您的较小文件(pages.pdf).

This does a better job, but its incomplete. It doesn't deal with images using multiple data sources for example. Its essentially untested, except that I did test your smaller file (pages.pdf) by using ps2write to convert to PostScript and then the PostScript program below, and teh pdfwrite device, to convert back to PDF.

您会注意到的第一件事是几乎所有文本都从您的文档中消失了.这是因为您使用的字体是位图字体,并且程序无法分辨代表字符的位图与任何其他类型的位图之间的区别.对于此文件,您可以通过删除imagemask的定义来解决该问题,因为所有字符均使用imagemask,而其他图像均使用"image".

One of the first things you will notice is that almost all the text has vanished from your document. That's because the fonts you are using are bitmap fonts, and the program can't tell the difference between a bitmap representing a character, and any other kind of bitmap. For this file you can solve that by removing the definition of imagemask because all the characters use imagemask, and the other images use 'image'.

我有一个偷偷摸摸的怀疑,该程序的格式将在这里弄乱:-(

I have a sneaky suspicion the formatting of the program is going to get messed up here :-(

8<------------------------------8<--------------------------8<-------------------------
%!

%
% numbytes -file- ConsumeFileData -
%
/ConsumeFileData {
  userdict begin
  /DataString 256 string def
  /DataFile exch def
  /BytesToRead exch def

%(BytesToRead = ) print BytesToRead ==
  mark
  {
    DataFile DataString readstring {                    % read bytes
      /BytesToRead BytesToRead 256 sub def              % not EOF subtract 256 from required amount.
%(Read 256 bytes) ==
%(BytesToRead now = ) print BytesToRead ==
    } {
      length
%(Read ) print dup 256 string cvs print (bytes) ==
      BytesToRead exch sub /BytesToRead exch def % Reached EOF, subtract length read froom required amount
%(BytesToRead now = ) print BytesToRead ==
      exit                                              % and exit loop
    } ifelse
  } loop

%BytesToRead ==
  BytesToRead 0 gt {
    (Ran out of image data reading from DataSource\n) ==
  } if
  cleartomark
  end
} bind def

%
% numbytes -proc- ConsumeProcData -
%
/ConsumeProcData {
userdict begin
  /DataProc exch def
  /BytesToRead exch def

  {
    DataProc exec                                     % returns a string
    length BytesToRead exch sub                       % subtract # bytes read
    /BytesToRead exch def
    BytesToRead 0 le {
      exit                                            % exit when read enough
    } if
  } loop
end
} bind def

/image {
 (image) ==
 dup type /dicttype eq {
  dup /MultipleDataSources known {
    dup /MultipleDataSources get {
      (Can't handle image with multiple sources!) ==
    } if
  } if
  dup /Width get                 % stack = -dict- width
  exch dup /BitsPerComponent get % stack = width -dict- bpc
  exch dup /Decode get           % stack = width bpc -dict- decode
  length 2 div                   % decode = 2 * num components
  exch 4 1 roll                  % stack = -dict- width bpc ncomps
  mul mul                        % stack = -dict- width*bpc*ncomps
  7 add cvi 8 idiv               % stack = -dict- width(bytes)
  exch dup /Height get           % stack = width -dict- height
  exch /DataSource get           % stack = width height DataSource
  3 1 roll                       % stack = DataSource width height
  mul                            % stack = DataSource widht*height
  exch                           % stack = size DataSource
 } {
  5 -1 roll
  pop                       % throw away matrix
  mul mul                   % bits/sample*width*height
  7 add cvi 8 idiv          % size in bytes of data floor(bits+7 / 8)
  exch                      % stack = size DataSource
 } ifelse

 dup type /filetype eq {
  ConsumeFileData
 } {
   dup type /arraytype eq or
   1 index type /packedarraytype eq or {
    ConsumeProcData
   } {
    pop pop                  % Remove DataSource and size
   } ifelse
 } ifelse
} bind def

/imagemask {
(imagemask)==
 dup type /dicttype eq {
  dup /MultipleDataSources known {
    dup /MultipleDataSources get {
      (Can't handle imagemask with multiple sources!) ==
    } if
  } if
  dup /Width get                 % stack = -dict- width
  7 add cvi 8 idiv             % size in bytes of width floor(bits+7 / 8)
  exch dup /Height get           % stack = width -dict- height
  exch /DataSource get           % stack = width height DataSource
  3 1 roll                       % stack = DataSource width height
  mul                            % stack = DataSource width*height
  exch                           % stack = size DataSource
 } {
  5 -1 roll
  pop                       % throw away matrix
  mul mul                   % bits/sample*width*height
  7 add cvi 8 idiv          % size in bytes of data floor(bits+7 / 8)
  exch                      % stack = size DataSource
 } ifelse

 dup type /filetype eq {
  ConsumeFileData
 } {
   dup type /arraytype eq or
   1 index type /packedarraytype eq or {
    ConsumeProcData
   } {
    pop pop                  % Remove DataSource and size
   } ifelse
 } ifelse
} bind def

/colorimage {
(colorimage)==
  dup 1 ne {
    1 index
    {
      (Can't handle colorimage with multiple sources!) ==
    } if
  } {
    exch pop                   % get rid of 'multi'
                   % stack: w h bpc m d ncomp
    3 -1 roll pop              % stack: w h bpc d ncomp
    exch 5 -1 roll             % stack d w h bpc ncomp
    mul mul mul                % stack: d w*h*bpc*ncomp
    7 add cvi 8 idiv exch      % stack: bytes datasource
  } ifelse

 dup type /filetype eq {
  ConsumeFileData
 } {
   dup type /arraytype eq or
   1 index type /packedarraytype eq or {
    ConsumeProcData
   } {
    pop pop                  % Remove DataSource and size
   } ifelse
 } ifelse
} bind def

这篇关于从PDF删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:37
查看更多