import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.List;
public class BrowserPDFDocumentFrame extends JFrame {
JTextPane editTextAndImageArea;
public void appendSomeImageToJTextPane(List<BufferedImage>bufferedImageList){
SimpleAttributeSet documentSimpleAttributeSet = new SimpleAttributeSet();
StyledDocument styledDocumentObject = this.editTextAndImageArea.getStyledDocument();
for (BufferedImage bufferedImage : bufferedImageList) {
this.editTextAndImageArea.setCaretPosition(styledDocumentObject.getLength());
this.editTextAndImageArea.insertIcon(new ImageIcon(bufferedImage));
try {
styledDocumentObject.insertString(styledDocumentObject.getLength(), "\n\r", documentSimpleAttributeSet);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
private void createAndinitJTextPane(String orignalPdfFilename){
this.editTextAndImageArea = new JTextPane();
JScrollPane oneJScrollPane = new JScrollPane(
this.editTextAndImageArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
//editTextAndImageArea.setSize(500,400);
this.getContentPane().add(oneJScrollPane,BorderLayout.CENTER);
//String orignalPdfFilename = "d:/体检注意事项.pdf";
float rotaionAngle = 0.0f; //转动角度,0 不旋转
/*
* pdf放大参数(转成图片后对图片的放大倍数,也就是转换后的图片尺寸为原始pdf页尺寸的倍数,
* 默认1.0,(不放大),放大有可能会影响清晰度
* */
float scaleFactors = 1.2f;//放大1.2倍
//调用转换方法,并获取最终转换后的各个图片的文件名列表信息
PDFDocumentToImageByICEpdf onePDFToJpegImagePictureByICEpdf=
new PDFDocumentToImageByICEpdf();
List<BufferedImage> resultBufferedImageList =
onePDFToJpegImagePictureByICEpdf.pdfToImage_BufferedImageList(
orignalPdfFilename,
rotaionAngle,
scaleFactors
);
appendSomeImageToJTextPane(resultBufferedImageList);
}
private void initThisMainFrame(String frameTitleText,String orignalPdfFilename){
this.setTitle(frameTitleText);
createAndinitJTextPane(orignalPdfFilename);
this.setSize(800,500);
//this.pack();
//this.setExtendedState(JFrame.MAXIMIZED_BOTH);//水平垂直方向都最大化
this.setLocationRelativeTo(null);//居中
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public BrowserPDFDocumentFrame(String frameTileText,String orignalPdfFilename){
super(frameTileText);
initThisMainFrame(frameTileText,orignalPdfFilename);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
pdftest.rar (13个子文件)
pom.xml 1KB
target
classes
PDFDocumentToImageByICEpdf.class 2KB
BrowserPDFDocumentApp.class 1KB
BrowserPDFDocumentFrame.class 3KB
generated-sources
annotations
src
test
java
main
resources
java
BrowserPDFDocumentFrame.java 3KB
PDFDocumentToImageByICEpdf.java 2KB
BrowserPDFDocumentApp.java 500B
.idea
runConfigurations.xml 346B
misc.xml 541B
jarRepositories.xml 880B
compiler.xml 540B
workspace.xml 3KB
.gitignore 50B
共 13 条
- 1
杜红永
- 粉丝: 2
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0