通天战队|Word文档转换:如何使用Aspose在Java中将Word和图像转换为PDF( 二 )
// The builder makes it simple to add content to the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Load images from the disk using the appropriate reader.
// The file formats that can be loaded depends on the image readers available on the machine.
ImageInputStream iis = ImageIO.createImageInputStream(new File(inputFileName));
ImageReader reader = ImageIO.getImageReaders(iis).next(); reader.setInput(iis, false);
// Get the number of frames in the image.
int framesCount = reader.getNumImages(true);
// Loop through all frames. for (int frameIdx = 0; frameIdx < framesCount; frameIdx++) {
// Insert a section break before each new page, in case of a multi-frame image.
if (frameIdx != 0)
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
// Select active frame.
BufferedImage image = reader.read(frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.getPageSetup();
ps.setPageWidth(ConvertUtil.pixelToPoint(image.getWidth()));
ps.setPageHeight(ConvertUtil.pixelToPoint(image.getHeight()));
// Insert the image into the document and position it at the top left corner of the page.
builder.insertImage( image, RelativeHorizontalPosition.PAGE, 0,
RelativeVerticalPosition.PAGE, 0, ps.getPageWidth(), ps.getPageHeight(), WrapType.NONE); }
if (iis != null) { iis.close(); reader.dispose(); }
doc.save(outputFileName); }
【通天战队|Word文档转换:如何使用Aspose在Java中将Word和图像转换为PDF】如果您有任何疑问或需求 , 请随时加入Aspose技术交流群(642018183) , 我们很高兴为您提供查询和咨询 。
推荐阅读
- 大河客户端|布局战队,导师各有妙招,《2020中国好声音》收视率蝉联第一
- 周到|“好声音”蝉联省级卫视综艺节目收视第一,首迎抢位战导师布局战队各有妙招
- 通天战队|A股最励志闻泰科技!给华为小米打工到半导体巨头,半年赚17亿
- |《街舞3》火舞台battle开启 钟汉良战队团魂之力势不可挡
- |《这!就是街舞》第三季火舞台热力喷发,队长领衔齐舞大秀燃炸战队之魂
- 巅峰战队|ConcurrentHashMap的部分源码分析
- 巅峰战队|VERTIX户外手表,勇攀新高峰——COROS
- 环球网|美海军陆战队一架CH-53E紧急迫降 未造成人员伤亡
- tes战队|lpl战队成员大更新!RNG崛起!TES在明年无可撼动!
- 碰碰战队|麒麟5nm芯片推迟,消息称华为正力催台积电交付订单
