User:Developer j2ee123/sandbox
import com.lowagie.text.Rectangle; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter;
import java.io.File; import java.io.FileOutputStream; /** * * @author Edukondalu Avula */ public class ConvertSlidesIntoImages { /** * This method is used to convert the given file to a PDF format * @param inputFile - Name and the path of the file * @param outputFile - Name and the path where the PDF file to be saved * @param isPictureFile */ private void createPdf(String inputFile, String outputFile, boolean isPictureFile) { /** * Set the page size for the image */ Rectangle pageSize = new Rectangle(1480, 1225); Document pdfDocument = new Document(pageSize); String pdfFilePath = outputFile; try { FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath); PdfWriter writer = null; writer = PdfWriter.getInstance(pdfDocument, fileOutputStream); writer.open(); pdfDocument.open(); /** * Proceed if the file given is a picture file */ if (isPictureFile) { pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile)); } /** * Proceed if the file given is (.txt,.html,.doc etc) */ else { File file = new File(inputFile); //pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file))); }
pdfDocument.close(); writer.close(); } catch (Exception exception) { System.out.println("Document Exception!" + exception); } }
public static void main(String args[]) { ConvertSlidesIntoImages pdfConversion = new ConvertSlidesIntoImages(); pdfConversion.createPdf("C:\\suresh\\power.JPG", "C:\\suresh\\sure.pdf", true);
} }
2nd------------
import java.io.File;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
public class HelloWorldToPDF {
public static void main(String[] args) {
// 1) Start LibreOffice in headless mode.
OfficeManager officeManager = null;
try {
officeManager = new DefaultOfficeManagerConfiguration()
.setOfficeHome(new File("C:/Program Files/LibreOffice 3.5"))
.buildOfficeManager();
officeManager.start();
// 2) Create JODConverter converter
OfficeDocumentConverter converter = new OfficeDocumentConverter(
officeManager);
// 3) Create PDF
createPDF(converter);
createPDF(converter);
} finally {
// 4) Stop LibreOffice in headless mode.
if (officeManager != null) {
officeManager.stop();
}
}
}
private static void createPDF(OfficeDocumentConverter converter) {
try {
long start = System.currentTimeMillis();
converter.convert(new File("docx/HelloWorld.docx"), new File(
"pdf/HelloWorld.pdf"));
System.err.println("Generate pdf/HelloWorld.pdf with "
+ (System.currentTimeMillis() - start) + "ms");
} catch (Throwable e) {
e.printStackTrace();
}
}
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.