我正在为Android应用程序编写Cordova插件。我有一个带有条形码的PDF,可以将其转换为base64。然后,我将该base64字符串转换回PDF,并将该文件保存到downloads文件夹中。 PDF创建良好,但是条形码显示为红色框/矩形,而不像原始PDF。当我通过电子邮件将PDF发送给自己并在Windows上的Adobe上打开时,条形码可以正常显示。
我不知道该怎么办。下面是代码片段:
private void returnDataTest(String message, CallbackContext callbackContext){
requestPermissionTest();
try {
//get the url page from the arguments array
URL url = new URL("http://www.reliablesoftjm.com/samplefilesfortesting/DepartureReceiptBarcodeOnly.pdf");
try {
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[131072];
int n = 0;
while (-1 != (n = in.read(buf))) {
out.write(buf, 0, n);
}
out.close();
in.close();
byte[] response = out.toByteArray();
String filename = "tempreceipt.pdf";
FileOutputStream outputStream;
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(path, filename);
outputStream = new FileOutputStream(file, false);
outputStream.write(response);
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
这是原始pdf的屏幕截图: Screenshot of original PDF
base64的屏幕截图转换为pdf:enter image description here
这也是base64字符串,以防万一:
JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZVsvSW5kZXhlZC9EZXZpY2VSR0IgMjU1KAAAAIAAAACAAICAAAAAgIAAgACAgICAgPwEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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