简体   繁体   中英

How to create PS file from PDF file using Java?

I wrote an application to create PDF file to PDDocument file it work fine. i use the pdfbox library

PDDocument pdfDoc = PDDocument.load(pdfFile);

Now i want to create PS (Post script) file from PDF file. Is there are any way in java. I can use any free API.

Many thanks.

Adobe seems to have a library. Here are some instructions. Please note, I have not tried this myself: http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm?content=000761.html

This link has a more detailed solution: http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm?content=000074.html

You can use PDFDocument to load your PDF then use PSConverter to convert the PDF document into an OutputStream.

The library I'm using is called ghost4j :

import org.ghost4j.converter.PSConverter; 
import org.ghost4j.document.PDFDocument;

Here's a small snippet:

private ByteArrayOutputStream convertPDFtoPS(){

    ByteArrayOutputStream  outstreamFile = new ByteArrayOutputStream();

    try{            
        PDFDocument document = new PDFDocument();
        //getPDFFile just returns an InputStream of the PDF file
        document.load(getPDFFile());           
        PSConverter converter = new PSConverter();
        converter.convert(document, outstreamFile); 

        outstreamFile.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    return outstreamFile;    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM