1

Необходимо скопировать первую страницу pdf файла в word файл(doc,docx) с помощью ЯП Java.

1
  • пожалуйста, не пишите название языка в заголовке вопроса для этого есть метки. 5 янв 2017 в 21:56

1 ответ 1

0

Источник

//Create the word document
XWPFDocument doc = new XWPFDocument();

// Open the pdf file
String pdf = "myfile.pdf";
PdfReader reader = new PdfReader(pdf);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);

// Read the PDF page by page
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
    TextExtractionStrategy strategy = parser.processContent(i, new         SimpleTextExtractionStrategy());
// Extract the text
String text=strategy.getResultantText();
// Create a new paragraph in the word document, adding the extracted text
XWPFParagraph p = doc.createParagraph();
XWPFRun run = p.createRun();
run.setText(text);
// Adding a page break
run.addBreak(BreakType.PAGE);
}
 // Write the word document
 FileOutputStream out = new FileOutputStream("myfile.docx");
 doc.write(out);
 // Close all open files
 out.close();
 reader.close();

В помощь

1
  • Это хороший и скорее всего рабочий метод, но проблема в том что: PdfReaderContentParser parser = new PdfReaderContentParser(reader);данного класса нет в бесплатной версии itext7 что делать? 6 янв 2017 в 9:31

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.