제 PDF 변환기 프로그램에 대한 약간의 도움이 필요합니다.Java : PDF 변환기는 Mac에서 작동하지만 Windows에서는 빈 PDF 파일을 생성합니다.
그래서 저는 JADE 프레임 워크를 사용하여이 모바일 에이전트 PDF 변환기를 만들고 있습니다. 그러나 필자가 직면하고있는 문제는 텍스트 파일을 PDF로 변환하고 네트워크를 통해 이진 파일로 보내고 PDF 파일을 다시 복원하는 방식과 관련이 있습니다.
필자가 작성한 프로그램은 MacBook에서 제대로 작동합니다. 그러나 Windows에서는 내 PDF 파일을 빈 PDF로 복원합니다.
다음은 PDF 파일을 보내는 데 사용하는 코드입니다.
private void sendPDF(File f, String recipient) {
String content = "";
if(f != null) {
try {
FileInputStream fis = new FileInputStream(f);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int noBytesRead = 0;
byte[] buffer = new byte[1024];
while((noBytesRead = fis.read(buffer)) != -1) {
baos.write(buffer, 0, noBytesRead);
}
content = baos.toString();
fis.close();
baos.close();
System.out.println("Successful PDF-to-byte conversion.");
} catch (Exception e) {
System.out.println("Exception while converting PDF-to-byte.");
content = "failed";
e.printStackTrace();
}
} else {
System.out.println("PDF-to-file conversion failed.");
content = "failed";
}
ACLMessage message = new ACLMessage(ACLMessage.INFORM);
message.addReceiver(new AID(recipient, AID.ISLOCALNAME));
message.setContent(content);
myAgent.send(message);
System.out.println("PDF document has been sent to requesting client.");
}
그리고 여기에 PDF를 복원하는 데 사용하는 코드가 있습니다.
private File restorePDF(String content) {
String dirPDF = dirBuffer + "/" + new Date().getTime() + ".pdf";
File f = new File(dirPDF);
try {
if(!f.exists()) f.createNewFile();
byte[] buffer = new byte[1024];
ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes());
FileOutputStream fos = new FileOutputStream(f);
int noBytesRead = 0;
while((noBytesRead = bais.read(buffer)) != -1) {
fos.write(buffer, 0, noBytesRead);
}
fos.flush();
fos.close();
bais.close();
} catch (Exception e) {
e.printStackTrace();
f = null;
}
return f;
}
이 문제에 대한 도움을 주시면 감사하겠습니다. :)
모든 로그? 예외? 추적? – Snicolas