移除圖片我讀Create a tiff with only text and no images from a postscript file with ghostscript並嘗試使用KenS`s答案。 但是這種方法只刪除「黑色」圖像 - 圖像僅包含黑色通道中的數據(PDF具有色彩空間CMYK)。我如何刪除我的情況下的所有圖像?從PDF
從PDF
回答
這沒有一個更好的工作,但它的不完整的。例如,它不處理使用多個數據源的圖像。它基本上沒有經過測試,除了我通過使用ps2write轉換爲PostScript,然後轉換爲下面的PostScript程序以及使用pdfwrite設備轉換回PDF格式來測試較小的文件(pages.pdf)。
一個你會注意到的第一件事情是,幾乎所有的文本已經從文檔中消失了。這是因爲您使用的字體是位圖字體,程序無法區分表示字符的位圖和任何其他類型的位圖。對於這個文件,你可以通過刪除imagemask的定義來解決這個問題,因爲所有的字符都使用imagemask,而其他圖像使用'image'。
我有一個鬼鬼祟祟的懷疑節目的格式會爲你解答到這裏搞砸了:-(
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
該技術應該在任何彩色圖像的工作,因爲圖像運算符用於彩色和單色圖像。除非你的文件使用obselete level 1.5'colorimage'操作符。我不記得在這個例子中是否重新定義了這個操作符,如果沒有,那麼你可以用類似的方式重新定義它。
其實我看到,我提出的重新定義圖像,colorimage和imagemask,所以所有的圖像類型應該被省略。也許你可以分享一個例子?
感謝 文件進行測試: http://array02.letmeprint.ru /noimages/cover.pdf(26M) http://array02.letmeprint.ru/noimages/pages.pdf(140K) http://array02.letmeprint.ru/noimages/noimage.ps 試着切斷在這個文件中的圖像... – WebRacer
這些是PDF文件,你在你的問題'一個PostScript文件'中說過。正如我在原始發佈中提到的那樣,PDF解釋器有效地使用了我們這些操作符的'系統'版本,所以這種技術將無法工作。相反,首先使用ps2write設備將PDF轉換爲PostScript,然後使用此序言將PostScript轉換爲TIFF,並且應該可以。 – KenS
事實上,該代碼中存在一個小錯誤,它不喜歡'內聯'圖像。我應該解決這個問題。我會稍後嘗試發佈一段更好的代碼。 – KenS
- 1. 從Pdf
- 2. 從pdf
- 3. 從PDF鉻
- 4. 如何從PDF
- 5. 從pdf中獲取pdf文件嵌入
- 6. 從Word打印到PDF中的PDF
- 7. umbraco 7:從pdf下載附件pdf
- 8. 從其他PDF創建多頁PDF
- 9. 從Pdf標題重命名.pdf
- 10. 從pdf markdown中旋轉表格pdf
- 11. Aspose PDF合併PDF從字節[] []
- 12. iphone從pdf頁面創建PDF文件
- 13. 從python創建PDF
- 14. 從ODT生成PDF
- 15. 從PDF提取圖
- 16. 從latex生成PDF
- 17. 顯示PDF從base64url
- 18. 從itext讀取pdf
- 19. 從cloudinary顯示PDF
- 20. 顯示PDF從arraybuffer
- 21. 從UITextView創建PDF
- 22. 從FLEX打印PDF
- 23. 從OpenXml生成PDF
- 24. 從SAP保存PDF
- 25. 使用PDFBOX從PDF
- 26. 從outputStream合併PDF
- 27. 從javascript打印PDF
- 28. 從Laravel導出PDF
- 29. 反覆 - 獲取發票PDF(pdf從pdf字符串)
- 30. 如何下載pdf時創建smarty從pdf創建的pdf
非常感謝你的工作!不幸的是,我不使用它沒有格式,因爲我不知道如何格式化它... – WebRacer
對不起,這裏試試這個pastebin http://pastebin.com/j8fTWTVh – KenS
它仍然不會工作,被調用的文件只能工作對於PS-文件而不圖片:/ – Joe