Convert pptx to pdf

Jessy Ping <[email protected]>
Newsgroups gmane.comp.jakarta.poi.user
Message-ID <pony-433ea8aa1df6d1d10142ee75f4048bdd7666da13-1c7e62c0cfcedfe68ee34b709dd0e44dd62e6083@user.poi.apache.org>
I am trying to convert a pptx to pdf using the below command. i have custom background design or image in my pptx along with two text fields. The problem is i am not able to convert the ppt to pdf correctly, the image and text box are scattered around in different sizes. Any insights will be helpful.Code below


static void convertToPdf(String fileName) throws IOException, DocumentException {
        FileInputStream inputStream = new FileInputStream(pptLocation + fileName + PPT);
        double zoom = 2;
        AffineTransform at = new AffineTransform();
        at.setToScale(zoom, zoom);
        Document pdfDocument = new Document();
        PdfWriter pdfWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(pdfLocation + fileName + PDF));
        PdfPTable table = new PdfPTable(1);
        pdfWriter.open();
        pdfDocument.open();
        Dimension pgsize = null;
        Image slideImage = null;
        BufferedImage img = null;
 XMLSlideShow ppt = new XMLSlideShow(inputStream);
        pgsize = ppt.getPageSize();
        List<XSLFSlide> slides = ppt.getSlides();
        pdfDocument.setPageSize(new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight()));
        pdfWriter.open();
        pdfDocument.open();
        for (int i = 0; i < slides.size(); i++) {
            img = new BufferedImage((int) Math.ceil(pgsize.width * zoom), (int) Math.ceil(pgsize.height * zoom), BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            graphics.setTransform(at);

            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
            /*for(XSLFShape shape : slides.get(i))
            {
                shape.draw(graphics, new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
            }*/
            slides.get(i).draw(graphics);
            graphics.getPaint();
            slideImage = Image.getInstance(img, null);
            table.addCell(new PdfPCell(slideImage, false));
 }
        pdfDocument.add(table);
        pdfDocument.close();
        pdfWriter.close();
		}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.