For a curernt application, we have the requirement to convert .docx and .doc files to a *.pdf file and append a page. Can this be done with the DocumentFactory or do we have to implement this by utilizing other tools?

The Aspose API should be able to do that, but I couldn't find an example on the Jira page for the DocumentFactory.

Edit - due to a related question, I could answer it myself. Both scenarios are possible by utilizing Aspose directly.

        Document doc = new Document("C:\\Users\\m.hoffmann\\Documents\\Die Kultur im Sudetenland.docx");
        DocumentBuilder docBuilder = new DocumentBuilder(doc);
        docBuilder.moveToDocumentEnd();
        docBuilder.insertBreak(BreakType.PAGE_BREAK);
        docBuilder.writeln("Dies ist ein Beispielausgabetext, welcher mit Aspose eingefügt wurde");
        docBuilder.getDocument().save("C:\\Users\\m.hoffmann\\Documents\\asposeOutputEdited.pdf", SaveFormat.PDF);
This question is marked "community wiki".

asked 14.08.2019 at 06:13

mhoffmann's gravatar image

mhoffmann
(suspended)
accept rate: 0%

edited 14.08.2019 at 07:00


Hi,

This is pretty simple to convert doc/docx to pdf with the DocFactory, even if it is not its "first" purpose. Just consider the following unit test:

    File docxToBeConverted = new File(TEST_DIRECTORY_RELATIVE_PATH + "/singleAppendedFileContinuous.docx");

    DocumentTemplate docTemplate = DocumentTemplate.withTemplate(docxToBeConverted);
    docTemplate.setOutputFormat(DocFactoryConstants.PDF_EXTENSION);
    docTemplate.setOutputName("docxConvertedToPdf");
    docTemplate.setOutputPath(TEST_DIRECTORY_RELATIVE_PATH);

    FileOperationMessage result = docTemplate.generateDocument();
    File pdfFile = result.getFiles().get(0);

    assertThat(result.isSuccess(), is(true));
    assertThat(result.getFiles(), hasSize(1));
    assertTrue(pdfFile.isFile());

Here we use the ch.ivyteam.ivy.addons.docfactory.DocumentTemplate Object which gets a template for doing the mail merge. As we only give a plain doc or docx without any mergefields and data to fill, the doc or docx remains untouched during the mail merge operation and the result is only saved as PDF.

link

answered 14.08.2019 at 08:41

Emmanuel%20Comba's gravatar image

Emmanuel Comba
(suspended)
accept rate: 50%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×4

Asked: 14.08.2019 at 06:13

Seen: 1,268 times

Last updated: 14.08.2019 at 08:41