2024年最新用java五分钟 pdf转word 轻松搞定,java商城项目面试

总结

对于面试,一定要有良好的心态,这位小伙伴面试美团的时候没有被前面阿里的面试影响到,发挥也很正常,也就能顺利拿下美团的offer。
小编还整理了大厂java程序员面试涉及到的绝大部分面试题及答案,希望能帮助到大家,

在这里插入图片描述

在这里插入图片描述

最后感谢大家的支持,希望小编整理的资料能够帮助到大家!也祝愿大家都能够升职加薪!

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

org.apache.poi

poi

3.9

org.apache.poi

poi-ooxml

3.9

然后贴一下代码:

public class Pdf2word {

public static void main(String[] args) throws InvalidFormatException {

try {

String pdfFileName = “H:\xuweichao.pdf”;

PDDocument pdf = PDDocument.load(new File(pdfFileName));

int pageNumber = pdf.getNumberOfPages();

String docFileName = pdfFileName.substring(0, pdfFileName.lastIndexOf(“.”)) + “.doc”;

File file = new File(docFileName);

if (!file.exists()) {

file.createNewFile();

}

CustomXWPFDocument document = new CustomXWPFDocument();

FileOutputStream fos = new FileOutputStream(docFileName);

//提取每一页的图片和文字,添加到 word 中

for (int i = 0; i < pageNumber; i++) {

PDPage page = pdf.getPage(i);

PDResources resources = page.getResources();

Iterable names = resources.getXObjectNames();

Iterator iterator = names.iterator();

while (iterator.hasNext()) {

COSName cosName = iterator.next();

if (resources.isImageXObject(cosName)) {

PDImageXObject imageXObject = (PDImageXObject) resources.getXObject(cosName);

File outImgFile = new File(“H:\img\” + System.currentTimeMillis() + “.jpg”);

Thumbnails.of(imageXObject.getImage()).scale(0.9).rotate(0).toFile(outImgFile);

BufferedImage bufferedImage = ImageIO.read(outImgFile);

int width = bufferedImage.getWidth();

int height = bufferedImage.getHeight();

if (width > 600) {

double ratio = Math.round((double) width / 550.0);

System.out.println(“缩放比ratio:”+ratio);

width = (int) (width / ratio);

height = (int) (height / ratio);

}

System.out.println("width: " + width + ", height: " + height);

FileInputStream in = new FileInputStream(outImgFile);

byte[] ba = new byte[in.available()];

in.read(ba);

ByteArrayInputStream byteInputStream = new ByteArrayInputStream(ba);

XWPFParagraph picture = document.createParagraph();

//添加图片

document.addPictureData(byteInputStream, CustomXWPFDocument.PICTURE_TYPE_JPEG);

//图片大小、位置

document.createPicture(document.getAllPictures().size() - 1, width, height, picture);

}

}

PDFTextStripper stripper = new PDFTextStripper();

stripper.setSortByPosition(true);

stripper.setStartPage(i);

stripper.setEndPage(i);

//当前页中的文字

String text = stripper.getText(pdf);

XWPFParagraph textParagraph = document.createParagraph();

XWPFRun textRun = textParagraph.createRun();

textRun.setText(text);

textRun.setFontFamily(“仿宋”);

textRun.setFontSize(11);

//换行

textParagraph.setWordWrap(true);

}

document.write(fos);

fos.close();

pdf.close();

System.out.println(“pdf转换解析结束!!----”);

} catch (IOException e) {

e.printStackTrace();

}

}

}

自定义文档类:

public class CustomXWPFDocument extends XWPFDocument {

public CustomXWPFDocument(InputStream in) throws IOException {

super(in);

}

public CustomXWPFDocument() {

super();

}

public CustomXWPFDocument(OPCPackage pkg) throws IOException {

super(pkg);

}

/**

  • @param id

  • @param width

  • @param height

  • @param paragraph

  •        段落
    

*/

public void createPicture(int id, int width, int height,

最后

针对最近很多人都在面试,我这边也整理了相当多的面试专题资料,也有其他大厂的面经。希望可以帮助到大家。

image

上述的面试题答案都整理成文档笔记。 也还整理了一些面试资料&最新2021收集的一些大厂的面试真题(都整理成文档,小部分截图)

image

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

.(img-YXHj88ka-1715252411399)]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值