SWT 이미지가 있습니다. iText API를 사용하여이 이미지를 pdf 파일로 내보내려고합니다. 나는이 이미지를 디스크에 저장 한 다음 이미지의 경로를 사용하여 을 pdf로 내보내려고했지만 PDF 생성에 많은 시간이 걸린다. 또한 SWT 이미지를 AWT 이미지로 변환 한 다음 pdf로 내보내려고 시도했지만이 방법은 pdf를 생성하는 데 더 많은 시간이 걸립니다. 이제Java iText API를 사용하여 SWT 이미지를 PDF로 내보내기
ImageLoader tempLoader = new ImageLoader();
tempLoader.data = new ImageData[] {
image.getImageData()
};
ByteArrayOutputStream bos = new ByteArrayOutputStream();
tempLoader.save(bos, SWT.IMAGE_JPEG);
내가
OutputStream outStream = new FileOutputStream(selectedPathAndName);
Document document = new Document();
document.setMargins(0,0,0,0);
document.setPageSize(new Rectangle(0,0,width,height));
PdfWriter.getInstance(document, outStream);
document.open();
com.itextpdf.text.Image pdfImage = com.itextpdf.text.Image.getInstance(bos.toByteArray());
document.add(pdfImage);
document.close();
이 입력으로이있는 ByteArrayOutputStream을 사용하고 있습니다 : 아래 그림과 같이 내가 시도하고있다 또 다른 방법은하여 ImageLoader 객체를 사용하여 의 jpeg있는 ByteArrayOutputStream에 이미지의 원시 데이터를 변환하는 것입니다 설정 한 너비와 높이로 PDF 파일을 생성하지만 페이지가 비어있는 것 같습니다. 제안이나 다른 방법을 사용하는 것이 가장 좋습니다.
는