我需要解析包含表格数据的PDF文件.我正在使用PDFBox提取文件文本以便稍后解析结果(String).问题是文本提取不像我预期的表格数据那样工作.例如,我有一个包含这样的表的文件(7列:前两个总是有数据,只有一个Complexity列有数据,只有一个Financing列有数据):
+----------------------------------------------------------------+
| AIH | Value | Complexity | Financing |
| | | Medium | High | Not applicable | MAC/Other | FAE |
+----------------------------------------------------------------+
| xyz | 12.43 | 12.34 | | | 12.34 | |
+----------------------------------------------------------------+
| abc | 1.56 | | 1.56 | | | 1.56|
+----------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
然后我使用PDFBox:
PDDocument document = PDDocument.load(pathToFile);
PDFTextStripper s = new PDFTextStripper();
String content = s.getText(document);
Run Code Online (Sandbox Code Playgroud)
这两行数据将被提取如下:
xyz 12.43 12.4312.43
abc 1.56 1.561.56
Run Code Online (Sandbox Code Playgroud)
最后两个数字之间没有空格,但这不是最大的问题.问题是我不知道最后两个数字是什么意思:中,高,不适用?MAC /其他,FAE?我没有数字和列之间的关系.
我不需要使用PDFBox库,因此使用另一个库的解决方案很好.我想要的是能够解析文件并知道每个解析的数字意味着什么.
我必须在热蓝牙打印机上打印一些数据,我正在这样做:
String message="abcdef any message 12345";
byte[] send;
send = message.getBytes();
mService.write(send);
Run Code Online (Sandbox Code Playgroud)
它适用于文本,但不适用于图像.我想我需要获取byte[]图像数据.我尝试以这种方式获取图像的数据:
Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.qrcode);
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image=stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
不幸的是,打印机会打印出许多奇怪的字符(大约50厘米的纸张).我不知道如何打印图像.
我想尝试获取位图的像素,然后将其转换为a byte[]并发送它,但我不知道该怎么做.
谢谢
更新:
经过这么多时间,我这样做:我有一个名为print_image(String file)的方法,它获取我想要打印的图像的路径:
private void print_image(String file) {
File fl = new File(file);
if (fl.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(file);
convertBitmap(bmp);
mService.write(PrinterCommands.SET_LINE_SPACING_24);
int offset = 0;
while (offset < bmp.getHeight()) {
mService.write(PrinterCommands.SELECT_BIT_IMAGE_MODE);
for (int x = 0; x < bmp.getWidth(); ++x) {
for (int k = 0; k < …Run Code Online (Sandbox Code Playgroud) 所有我需要做的就是把一个(本地保存)PDF-document和转换一个或所有它的网页图像的像JPG或PNG格式.
我已经尝试了许多PDF渲染/查看解决方案,如APV PDF Viewer,APDFViewer,droidreader,android-pdf,MuPdf等等,但到目前为止还无法弄清楚如何将pdf页面转换为图像?.
编辑:此外,我宁愿拥有PDF到图像转换器而不是我需要编辑以将PDF转换为图像的PDF渲染器.