Convert docx to pdf using Java

I want to convert docx to pdf using groupdocs-conversion-17.12 but not able to do so. can you help me with that. The reason why i am not able to do so is i think i am unable to understand the Utilities.java


This Topic is created by atirtahir3 using the Email to Topic plugin.

@riazahmed450,

Thank you for taking interest in GroupDocs.Conversion for Java and posting your concerns. Can you please tell us where you are facing issue? If you are using our GitHub example, then you need to do following steps in order to do conversion:

  • Uncomment Utilities.applyLicenseFromFile(); and Conversion.convertToPdfAsFilePath(“demo.docx”);
  • Pass the source document to convertToPdfAsFilePath()
  • Copy license file in base directory (\GroupDocs.Conversion-for-Java\Examples\GroupDocs.Conversion.Examples.Java) of the project
  • Run the application

Aside this you can use following code:

    String storagePath = "C:/Storage";
    String outputPath = "C:/ConvertedStorage";
     
    // Setup Conversion configuration
    ConversionConfig conversionConfig = new ConversionConfig();
    conversionConfig.setStoragePath(storagePath);
    conversionConfig.setOutputPath(outputPath);
     
    // Instantiating the conversion handler
    ConversionHandler conversionHandler = new ConversionHandler(conversionConfig);
    PdfSaveOptions saveOption = new PdfSaveOptions(); 
    // Set absolute path to file
    String guid = "C:/Storage/DOCXsample.docx";
    ConvertedDocument convertedDocumentPath = conversionHandler.<String> convert(guid, saveOption);
    convertedDocumentPath.save(fileName + "." + convertedDocumentPath.getFileType());
    System.out.print("Converted file path is: " + convertedDocumentPath);

Hopefully, it will resolve your issue.

1 Like

Thanks i am able to run it

@riazahmed450,

Good to know that you can now run the example project.

We want to use groupdocs viewer component to display ms office files so that no one can save as that file also want to disable print and select option. Is it possible with groupdocs viewer component?

@riazahmed450,

We’ve created a thread regarding your requirements in the relevant category. It’ll be assisted here.

i am also getting the same error. not resolved yet. can anyone help?

@amrit007,

Did you explore our GroupDocs.Conversion for Java example project? What error (specifically) you’re facing. Please share error/exception details and which version (e.g. 17.12, 18.6) of the API you’re evaluating?

null pointer error . its saying error in this line-
in conversion.java-
conversionConfig.setStoragePath(source.getParent().toString());

@amrit007,

Please follow this link. Your query will be assisted there.