使用Android打印PDF
我正在尝试从android应用程序中打印PDF。但每次我尝试打印打印页面时,都会包含一些奇怪的数据,如:使用Android打印PDF,android,pdf,printing,Android,Pdf,Printing,我正在尝试从android应用程序中打印PDF。但每次我尝试打印打印页面时,都会包含一些奇怪的数据,如: java.io.FileInputStream@418479b0 我假设我的pdf没有以正确的方式呈现。。。 现在有人知道我如何正确地将pdf转换为outputstream吗 我已经尝试了此问题()中的代码,但在打印的页面上得到以下输出: Filter/FlateDecode/Length 69 >>stream 有人能帮我吗?:) 这是我的代码: Sock
java.io.FileInputStream@418479b0
我假设我的pdf没有以正确的方式呈现。。。
现在有人知道我如何正确地将pdf转换为outputstream吗
我已经尝试了此问题()中的代码,但在打印的页面上得到以下输出:
Filter/FlateDecode/Length 69 >>stream
有人能帮我吗?:)
这是我的代码:
Socket socket = new Socket();
String sIP = "192.168.0.250";
String sPort = "9100";
InetSocketAddress socketAddress = new InetSocketAddress(sIP, Integer.parseInt(sPort));
DataOutputStream outputStream;
try{
//file init
File pdfFile = new File(file);
byte[] byteArray=null;
InputStream inputStream = new FileInputStream(pdfFile);
String inputStreamToString = inputStream.toString();
byteArray = inputStreamToString.getBytes();
inputStream.close();
//Socket init
socket.connect(socketAddress, 3000);
outputStream = new DataOutputStream(socket.getOutputStream());
outputStream.write(byteArray);
outputStream.close();
socket.close();
}catch(Exception e){
e.printStackTrace();
}
您可以尝试以下方法来获取byteArray:
//file init
File pdfFile = new File(file);
byte[] byteArray = new byte[(int) pdfFile.length()];
FileInputStream fis = new FileInputStream(pdfFile);
fis.read(byteArray);
fis.close();
如果我尝试这个,我的打印机不想打印,但我也没有得到一个错误或什么。。。