1
A
回答
1
沿着iText的示例的線ExtractImages可以這樣提取的代碼:
PdfReader reader = new PdfReader(resourceStream);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
ImageRenderListener listener = new ImageRenderListener("testpdf");
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
parser.processContent(i, listener);
}
的ImageRenderListener
的定義如下:
class ImageRenderListener implements RenderListener
{
final String name;
int counter = 100000;
public ImageRenderListener(String name)
{
this.name = name;
}
public void beginTextBlock() { }
public void renderText(TextRenderInfo renderInfo) { }
public void endTextBlock() { }
public void renderImage(ImageRenderInfo renderInfo)
{
try
{
PdfImageObject image = renderInfo.getImage();
if (image == null) return;
int number = renderInfo.getRef() != null ? renderInfo.getRef().getNumber() : counter++;
String filename = String.format("%s-%s.%s", name, number, image.getFileType());
FileOutputStream os = new FileOutputStream(filename);
os.write(image.getImageAsBytes());
os.flush();
os.close();
PdfDictionary imageDictionary = image.getDictionary();
PRStream maskStream = (PRStream) imageDictionary.getAsStream(PdfName.SMASK);
if (maskStream != null)
{
PdfImageObject maskImage = new PdfImageObject(maskStream);
filename = String.format("%s-%s-mask.%s", name, number, maskImage.getFileType());
os = new FileOutputStream(filename);
os.write(maskImage.getImageAsBytes());
os.flush();
os.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
正如所看到的ImageRenderListener
方法renderImage
檢索的參數ImageRenderInfo
。這個論點有方法
getStartPoint
給你在用戶空間代表了X對象和getImageCTM
的起點給你向量的座標變換矩陣活躍時,這個圖像呈現。座標位於用戶空間中。
後者爲您提供了1x1用戶空間單位正方形的確切操作用於實際繪製圖像的信息。如您所知,圖像可能會旋轉,拉伸,偏斜和移動(前一種方法實際上是從「移動」信息中的矩陣中提取其結果)。
相關問題
- 1. 使用itext從pdf獲取所選區域的座標
- 2. 從圖像文件中提取座標
- 3. 使用pdfbox從PDF中提取圖像
- 4. 使用C從PDF中提取圖像#
- 5. 使用iText從TIFF圖像創建PDF
- 6. 提取圖像和文字的座標和大小從PDF
- 7. 從PDF中提取圖像
- 8. 從PDF中提取圖像
- 9. 提取X,Y從圖像座標
- 10. Itext從現有的pdf中獲取字段座標
- 11. 如何使用iText以正確的順序從PDF中提取圖像?
- 12. 如何在Android上使用iText從PDF文件中提取圖像和文本
- 13. 圖書館/工具從pdf中提取單詞座標
- 14. 使用iText進行PDF文本提取
- 15. 從asp.net提取pdf圖像
- 16. 使用CAM :: PDF的Perl - 無法從PDF中提取圖像
- 17. 從選定區域或座標中提取PDF文本和圖像
- 18. 使用iText的pdf文件中元素的座標
- 19. 從itext讀取pdf
- 20. 使用iText從pdf文件中提取一個頁面
- 21. 使用IText或ITextSharp或BouncyCastle從pdf文件中提取pkcs7(byte [])
- 22. 使用iText將圖像從drawable中添加到PDF中
- 23. 使用iText在PDF文件中獲取圖像DPI
- 24. 如何使用Java(不使用pdfbox)從pdf中提取圖像
- 25. 使用iText從PDF條形碼圖像中檢索文本
- 26. 整理從PDF中提取的圖像
- 27. MuPDF從pdf頁面獲取每個圖像座標
- 28. 從圖像座標中獲取對象的世界座標
- 29. Matlab:從笛卡爾的極座標表示中提取圖像
- 30. 從PDF中提取標籤
您引用的示例將提取PDF中存在的圖像資源。這些圖像並不是完全需要顯示的圖像,因爲a)可能會有比實際使用的資源更多的資源,b)這種方法會忽略內嵌圖像。因此,你應該使用iText'parser'包中的類。查看iText示例[ExtractImages](http://itextpdf.com/examples/iia.php?id=284)。 ImageRenderInfo對象包含座標信息。 – mkl
謝謝@mkl指出我正確的例子。你能告訴我們如何使用座標來從這個例子中獲取圖像。 – rizzz86