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();
                }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to