HTML JPG PDF XML DOCX
  Product Family
PDF

Convert MD to PDF in Java SDK

Export MD documents to multiple formats including PDF with Aspose.PDF Cloud Java SDK

Get Started

How to Convert MD to PDF Using SDK for Java

In order to convert MD to PDF, we’ll use Aspose.PDF Cloud Java SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in Java language for various cloud platforms. Open Repository package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console for install it using Maven.

Add Aspose Cloud repository to your application pom.xml

Add Aspose Cloud repository


    <repositories>
        <repository>
            <id>aspose-cloud</id>
            <name>Aspose Cloud Repository</name>
            <url>https://releases.aspose.cloud/java/repo/</url>
        </repository>
    </repositories>

To install the API client library to your local Maven repository, simply execute:

Installation from Github


    mvn clean install

Steps to Convert MD to PDF via Java SDK

Aspose.PDF Cloud developers can easily load & convert MD files to PDF in just a few lines of code.

  1. Create a new Configuration object with your Application Secret and Key
  2. Create an object to connect to the Cloud API
  3. Upload your document file
  4. Perform the conversion
  5. Download the result
 

This sample code shows MD to PDF Cloud Java SDK Conversion


    package com.aspose.asposecloudpdfusecases.conversions;

    import java.io.File;
    import java.nio.file.Path;
    import java.nio.file.StandardCopyOption;
    import com.aspose.asposecloudpdf.api.PdfApi;
    import com.aspose.asposecloudpdf.model.AsposeResponse;

    public class ConvertMdToPdf {
        public static void Convert() {
            String REMOTE_FOLDER   = "Your_Temp_Pdf_Cloud";
            String LOCAL_FOLDER    = "c:\\Samples";

            String MD_FILE_NAME  = "sample.md";
            String PDF_MD_OUTPUT = "convert_md_pdf_output.pdf";
        
            try {
                PdfApi pdfApi = new PdfApi(API_KEY, API_SECRET);

                // upload local PDF file to remote storage
                File file = new File(Path.of(LOCAL_FOLDER, MD_FILE_NAME).toString());
                String srcPath = Path.of(REMOTE_FOLDER, MD_FILE_NAME).toString();
                pdfApi.uploadFile(srcPath, file, null);
                System.out.println(String.format("Files %s successfully uploaded!", MD_FILE_NAME));

            // convert Md to PDF
                AsposeResponse response = pdfApi.putMarkdownInStorageToPdf(PDF_MD_OUTPUT, srcPath, null, REMOTE_FOLDER);

                if (response.getCode() != 200)
                    System.err.println("Error: unexpected error when converting Markdown to PDF! '" + response.getStatus() + "'");
                else{
                    // download changed PDF file from remote folder...
                    File f = pdfApi.downloadFile(Path.of(REMOTE_FOLDER, PDF_MD_OUTPUT).toString(), null, null);
                    java.nio.file.Files.copy(Path.of(f.getPath()), Path.of(LOCAL_FOLDER, PDF_MD_OUTPUT), StandardCopyOption.REPLACE_EXISTING);
                    System.out.println(String.format("File '%s' successfully dowloaded!", Path.of(LOCAL_FOLDER, PDF_MD_OUTPUT).toString()));
                    System.out.println("Successfully converted markdown to PDF document ! '" + PDF_MD_OUTPUT + "'");
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
  • Other Supported Conversions

    You can also convert many other file formats

    BMP TO PDF (Bitmap Image)
    EMF TO PDF (Enhanced Metafile Format)
    EPUB TO PDF (E-book Format)
    GIF TO PDF (Graphical Interchange Format)
    HTML-TO-PDF (Hyper Text Markup Language)
    JPEG TO PDF (JPEG Image)
    MD TO PDF (Markdown)
    PCL TO PDF (Printer Command Language)
    PDF TO BMP (Bitmap Image)
    PDF TO DOCX (Office 2007+ Words Document)
    PDF TO EMF (Enhanced Metafile Format)
    PDF TO EPUB (E-book Format)
    PDF TO GIF (Graphical Interchange Forma)
    PDF TO HTML (Hyper Text Markup Language)
    PDF TO JPEG (JPEG Image)
    PDF TO PDF/A (Portable Document Format/A)
    PDF TO PNG (Portable Network Graphics)
    PDF TO PPTX (Open XML presentation Format)
    PDF TO SVG (Scalable Vector Graphics)
    PDF TO TEX (LaTeX Output Text)
    PDF TO TIFF (Tagged Image Format)
    PDF TO TXT (Text Document)
    PDF TO XLSX (OOXML Excel File)
    PDF TO XPS (XML Paper Specifications)
    PDF TO PPTX (Open XML presentation Format)
    PNG TO PDF (Portable Network Graphics)
    SVG TO PDF (Scalable Vector Graphics)
    TEX TO PDF (LaTeX Output Text)
    TEXT TO PDF (Text Document)
    TIFF TO PDF (Tagged Image Format)
    XPS TO PDF (XML Paper Specifications)