How to translate correctly an iText5 code piece to an iText7?









up vote
0
down vote

favorite












I am an SQL/ETL(PowerCenter)/bash/Python developer with a very little experience in Java. I have a task - I need to take a .pptx template, customize it and convert to a .pdf file. I've decided to start from the second step, so I took this as an example. I've got latest versions of libraries (iText7 and POI4), so I had to modify this code in order to compile it. I was able to find moved packages in an Import part but then I stuck here:



slideImage = Image.getInstance(img, null);


My new libraries say that getInstance is not supported anymore (cannot find symbol). I'm trying to skip this step and use an analogue of



table.addCell(new PdfPCell(slideImage, true));


which I've changed to



table.addCell(new Cell(img, true));


to add this bufferedImage directly to a cell, it throws conversion errors, like "BufferedImage cannot be converted to int). How can I convert BufferedImage to Image? I read that the 1st is a child of the 2nd, so there's no need to convert it, but it doesn't work. Below I'm providing the code adjusted by me. Thank you in advance!




import java.io.FileOutputStream;
import java.io.*;
import java.io.IOException;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hslf.record.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

import com.itextpdf.layout.Document;

import com.itextpdf.layout.element.Image;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.geom.PageSize;

public void createPdf(String inFileName, String outFileName)
throws IOException

FileInputStream inputStream = new FileInputStream(inFileName);
double zoom = 2;
AffineTransform at = new AffineTransform();
at.setToScale(zoom, zoom);

Table table = new Table(1);
Dimension pgsize = null;
Image slideImage = null;
BufferedImage img = null;

XMLSlideShow ppt = new XMLSlideShow(inputStream);
pgsize = ppt.getPageSize();

// PDF part
// Initialize PDF writer
PdfWriter writer = new PdfWriter(outFileName);
// Initialize PDF document
PdfDocument pdf = new PdfDocument(writer);
// Initialize document
Rectangle srcPageSize = new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight());
Document doc = new Document(pdf, new PageSize(srcPageSize));

List<XSLFSlide> slides = ppt.getSlides();
// writer.open();
// pdfDocument.open();
for (XSLFSlide slide : ppt.getSlides())
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));
slide.draw(graphics);
graphics.getPaint();

// Original start
// slideImage = Image.getInstance(img, null);
// table.addCell(new PdfPCell(slideImage, true));
// Original end


table.addCell(new Cell(img, true));

// pdfDocument.add(table);
// pdfDocument.close();
// pdfWriter.close();
System.out.println("Powerpoint file converted to PDF successfully");

// catch (IOException e)
//
// System.err.println("FileStreamsReadnWrite: " + e);
//










share|improve this question







New contributor




Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    0
    down vote

    favorite












    I am an SQL/ETL(PowerCenter)/bash/Python developer with a very little experience in Java. I have a task - I need to take a .pptx template, customize it and convert to a .pdf file. I've decided to start from the second step, so I took this as an example. I've got latest versions of libraries (iText7 and POI4), so I had to modify this code in order to compile it. I was able to find moved packages in an Import part but then I stuck here:



    slideImage = Image.getInstance(img, null);


    My new libraries say that getInstance is not supported anymore (cannot find symbol). I'm trying to skip this step and use an analogue of



    table.addCell(new PdfPCell(slideImage, true));


    which I've changed to



    table.addCell(new Cell(img, true));


    to add this bufferedImage directly to a cell, it throws conversion errors, like "BufferedImage cannot be converted to int). How can I convert BufferedImage to Image? I read that the 1st is a child of the 2nd, so there's no need to convert it, but it doesn't work. Below I'm providing the code adjusted by me. Thank you in advance!




    import java.io.FileOutputStream;
    import java.io.*;
    import java.io.IOException;


    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Rectangle2D;
    import java.awt.image.BufferedImage;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    import org.apache.poi.hslf.record.Slide;
    import org.apache.poi.sl.usermodel.SlideShow;
    import org.apache.poi.xslf.usermodel.XMLSlideShow;
    import org.apache.poi.xslf.usermodel.XSLFSlide;

    import com.itextpdf.layout.Document;

    import com.itextpdf.layout.element.Image;
    import com.itextpdf.kernel.geom.Rectangle;
    import com.itextpdf.layout.element.Cell;
    import com.itextpdf.layout.element.Table;
    import com.itextpdf.kernel.pdf.PdfWriter;
    import com.itextpdf.kernel.pdf.PdfDocument;
    import com.itextpdf.kernel.geom.PageSize;

    public void createPdf(String inFileName, String outFileName)
    throws IOException

    FileInputStream inputStream = new FileInputStream(inFileName);
    double zoom = 2;
    AffineTransform at = new AffineTransform();
    at.setToScale(zoom, zoom);

    Table table = new Table(1);
    Dimension pgsize = null;
    Image slideImage = null;
    BufferedImage img = null;

    XMLSlideShow ppt = new XMLSlideShow(inputStream);
    pgsize = ppt.getPageSize();

    // PDF part
    // Initialize PDF writer
    PdfWriter writer = new PdfWriter(outFileName);
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);
    // Initialize document
    Rectangle srcPageSize = new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight());
    Document doc = new Document(pdf, new PageSize(srcPageSize));

    List<XSLFSlide> slides = ppt.getSlides();
    // writer.open();
    // pdfDocument.open();
    for (XSLFSlide slide : ppt.getSlides())
    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));
    slide.draw(graphics);
    graphics.getPaint();

    // Original start
    // slideImage = Image.getInstance(img, null);
    // table.addCell(new PdfPCell(slideImage, true));
    // Original end


    table.addCell(new Cell(img, true));

    // pdfDocument.add(table);
    // pdfDocument.close();
    // pdfWriter.close();
    System.out.println("Powerpoint file converted to PDF successfully");

    // catch (IOException e)
    //
    // System.err.println("FileStreamsReadnWrite: " + e);
    //










    share|improve this question







    New contributor




    Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am an SQL/ETL(PowerCenter)/bash/Python developer with a very little experience in Java. I have a task - I need to take a .pptx template, customize it and convert to a .pdf file. I've decided to start from the second step, so I took this as an example. I've got latest versions of libraries (iText7 and POI4), so I had to modify this code in order to compile it. I was able to find moved packages in an Import part but then I stuck here:



      slideImage = Image.getInstance(img, null);


      My new libraries say that getInstance is not supported anymore (cannot find symbol). I'm trying to skip this step and use an analogue of



      table.addCell(new PdfPCell(slideImage, true));


      which I've changed to



      table.addCell(new Cell(img, true));


      to add this bufferedImage directly to a cell, it throws conversion errors, like "BufferedImage cannot be converted to int). How can I convert BufferedImage to Image? I read that the 1st is a child of the 2nd, so there's no need to convert it, but it doesn't work. Below I'm providing the code adjusted by me. Thank you in advance!




      import java.io.FileOutputStream;
      import java.io.*;
      import java.io.IOException;


      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics2D;
      import java.awt.geom.AffineTransform;
      import java.awt.geom.Rectangle2D;
      import java.awt.image.BufferedImage;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;

      import org.apache.poi.hslf.record.Slide;
      import org.apache.poi.sl.usermodel.SlideShow;
      import org.apache.poi.xslf.usermodel.XMLSlideShow;
      import org.apache.poi.xslf.usermodel.XSLFSlide;

      import com.itextpdf.layout.Document;

      import com.itextpdf.layout.element.Image;
      import com.itextpdf.kernel.geom.Rectangle;
      import com.itextpdf.layout.element.Cell;
      import com.itextpdf.layout.element.Table;
      import com.itextpdf.kernel.pdf.PdfWriter;
      import com.itextpdf.kernel.pdf.PdfDocument;
      import com.itextpdf.kernel.geom.PageSize;

      public void createPdf(String inFileName, String outFileName)
      throws IOException

      FileInputStream inputStream = new FileInputStream(inFileName);
      double zoom = 2;
      AffineTransform at = new AffineTransform();
      at.setToScale(zoom, zoom);

      Table table = new Table(1);
      Dimension pgsize = null;
      Image slideImage = null;
      BufferedImage img = null;

      XMLSlideShow ppt = new XMLSlideShow(inputStream);
      pgsize = ppt.getPageSize();

      // PDF part
      // Initialize PDF writer
      PdfWriter writer = new PdfWriter(outFileName);
      // Initialize PDF document
      PdfDocument pdf = new PdfDocument(writer);
      // Initialize document
      Rectangle srcPageSize = new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight());
      Document doc = new Document(pdf, new PageSize(srcPageSize));

      List<XSLFSlide> slides = ppt.getSlides();
      // writer.open();
      // pdfDocument.open();
      for (XSLFSlide slide : ppt.getSlides())
      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));
      slide.draw(graphics);
      graphics.getPaint();

      // Original start
      // slideImage = Image.getInstance(img, null);
      // table.addCell(new PdfPCell(slideImage, true));
      // Original end


      table.addCell(new Cell(img, true));

      // pdfDocument.add(table);
      // pdfDocument.close();
      // pdfWriter.close();
      System.out.println("Powerpoint file converted to PDF successfully");

      // catch (IOException e)
      //
      // System.err.println("FileStreamsReadnWrite: " + e);
      //










      share|improve this question







      New contributor




      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am an SQL/ETL(PowerCenter)/bash/Python developer with a very little experience in Java. I have a task - I need to take a .pptx template, customize it and convert to a .pdf file. I've decided to start from the second step, so I took this as an example. I've got latest versions of libraries (iText7 and POI4), so I had to modify this code in order to compile it. I was able to find moved packages in an Import part but then I stuck here:



      slideImage = Image.getInstance(img, null);


      My new libraries say that getInstance is not supported anymore (cannot find symbol). I'm trying to skip this step and use an analogue of



      table.addCell(new PdfPCell(slideImage, true));


      which I've changed to



      table.addCell(new Cell(img, true));


      to add this bufferedImage directly to a cell, it throws conversion errors, like "BufferedImage cannot be converted to int). How can I convert BufferedImage to Image? I read that the 1st is a child of the 2nd, so there's no need to convert it, but it doesn't work. Below I'm providing the code adjusted by me. Thank you in advance!




      import java.io.FileOutputStream;
      import java.io.*;
      import java.io.IOException;


      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics2D;
      import java.awt.geom.AffineTransform;
      import java.awt.geom.Rectangle2D;
      import java.awt.image.BufferedImage;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;

      import org.apache.poi.hslf.record.Slide;
      import org.apache.poi.sl.usermodel.SlideShow;
      import org.apache.poi.xslf.usermodel.XMLSlideShow;
      import org.apache.poi.xslf.usermodel.XSLFSlide;

      import com.itextpdf.layout.Document;

      import com.itextpdf.layout.element.Image;
      import com.itextpdf.kernel.geom.Rectangle;
      import com.itextpdf.layout.element.Cell;
      import com.itextpdf.layout.element.Table;
      import com.itextpdf.kernel.pdf.PdfWriter;
      import com.itextpdf.kernel.pdf.PdfDocument;
      import com.itextpdf.kernel.geom.PageSize;

      public void createPdf(String inFileName, String outFileName)
      throws IOException

      FileInputStream inputStream = new FileInputStream(inFileName);
      double zoom = 2;
      AffineTransform at = new AffineTransform();
      at.setToScale(zoom, zoom);

      Table table = new Table(1);
      Dimension pgsize = null;
      Image slideImage = null;
      BufferedImage img = null;

      XMLSlideShow ppt = new XMLSlideShow(inputStream);
      pgsize = ppt.getPageSize();

      // PDF part
      // Initialize PDF writer
      PdfWriter writer = new PdfWriter(outFileName);
      // Initialize PDF document
      PdfDocument pdf = new PdfDocument(writer);
      // Initialize document
      Rectangle srcPageSize = new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight());
      Document doc = new Document(pdf, new PageSize(srcPageSize));

      List<XSLFSlide> slides = ppt.getSlides();
      // writer.open();
      // pdfDocument.open();
      for (XSLFSlide slide : ppt.getSlides())
      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));
      slide.draw(graphics);
      graphics.getPaint();

      // Original start
      // slideImage = Image.getInstance(img, null);
      // table.addCell(new PdfPCell(slideImage, true));
      // Original end


      table.addCell(new Cell(img, true));

      // pdfDocument.add(table);
      // pdfDocument.close();
      // pdfWriter.close();
      System.out.println("Powerpoint file converted to PDF successfully");

      // catch (IOException e)
      //
      // System.err.println("FileStreamsReadnWrite: " + e);
      //







      java itext7






      share|improve this question







      New contributor




      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      Serge Larionoff

      11




      11




      New contributor




      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Serge Larionoff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          You may try the following , which uses the current API :



          // you need to convert the BufferedImage to a byte array
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ImageIO.write(img, "png", baos);

          ImageData image = ImageDataFactory.create(baos.toByteArray());

          table.addCell(new Image(image));


          There are other interesting methods like ImageDataFactory.create(String filename) .






          share|improve this answer






















          • Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
            – Serge Larionoff
            yesterday










          • Oh indeed, just edited with a correction.
            – Arnaud
            yesterday










          • Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
            – Serge Larionoff
            yesterday











          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            yesterday










          • Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
            – Serge Larionoff
            yesterday











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Serge Larionoff is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224457%2fhow-to-translate-correctly-an-itext5-code-piece-to-an-itext7%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          You may try the following , which uses the current API :



          // you need to convert the BufferedImage to a byte array
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ImageIO.write(img, "png", baos);

          ImageData image = ImageDataFactory.create(baos.toByteArray());

          table.addCell(new Image(image));


          There are other interesting methods like ImageDataFactory.create(String filename) .






          share|improve this answer






















          • Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
            – Serge Larionoff
            yesterday










          • Oh indeed, just edited with a correction.
            – Arnaud
            yesterday










          • Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
            – Serge Larionoff
            yesterday











          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            yesterday










          • Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
            – Serge Larionoff
            yesterday















          up vote
          1
          down vote













          You may try the following , which uses the current API :



          // you need to convert the BufferedImage to a byte array
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ImageIO.write(img, "png", baos);

          ImageData image = ImageDataFactory.create(baos.toByteArray());

          table.addCell(new Image(image));


          There are other interesting methods like ImageDataFactory.create(String filename) .






          share|improve this answer






















          • Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
            – Serge Larionoff
            yesterday










          • Oh indeed, just edited with a correction.
            – Arnaud
            yesterday










          • Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
            – Serge Larionoff
            yesterday











          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            yesterday










          • Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
            – Serge Larionoff
            yesterday













          up vote
          1
          down vote










          up vote
          1
          down vote









          You may try the following , which uses the current API :



          // you need to convert the BufferedImage to a byte array
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ImageIO.write(img, "png", baos);

          ImageData image = ImageDataFactory.create(baos.toByteArray());

          table.addCell(new Image(image));


          There are other interesting methods like ImageDataFactory.create(String filename) .






          share|improve this answer














          You may try the following , which uses the current API :



          // you need to convert the BufferedImage to a byte array
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ImageIO.write(img, "png", baos);

          ImageData image = ImageDataFactory.create(baos.toByteArray());

          table.addCell(new Image(image));


          There are other interesting methods like ImageDataFactory.create(String filename) .







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          Arnaud

          13.1k21529




          13.1k21529











          • Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
            – Serge Larionoff
            yesterday










          • Oh indeed, just edited with a correction.
            – Arnaud
            yesterday










          • Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
            – Serge Larionoff
            yesterday











          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            yesterday










          • Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
            – Serge Larionoff
            yesterday

















          • Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
            – Serge Larionoff
            yesterday










          • Oh indeed, just edited with a correction.
            – Arnaud
            yesterday










          • Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
            – Serge Larionoff
            yesterday











          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            yesterday










          • Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
            – Serge Larionoff
            yesterday
















          Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
          – Serge Larionoff
          yesterday




          Hi Arnaud! Thank you for an answer, i got the following compilation time error on the "Image image = ImageDataFactory.create(baos.toByteArray());" line - "incompatible types: ImageData cannot be converted to Image"
          – Serge Larionoff
          yesterday












          Oh indeed, just edited with a correction.
          – Arnaud
          yesterday




          Oh indeed, just edited with a correction.
          – Arnaud
          yesterday












          Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
          – Serge Larionoff
          yesterday





          Super, at least now it compiles successfully! After compilation I've started an execution and I got another error " [ERROR] Failed to load class [com.itextpdf.layout.element.Table] : [com.itextpdf.layout.element.Table]. [ERROR] java.lang.NoClassDefFoundError: com/itextpdf/layout/element/Table" I know that I do have this line in an import section. What could went wrong this time? Does this mean that a file with that class is not accessible on server? But I see that the folder with .jar files is listed in a $CLASSPATH.
          – Serge Larionoff
          yesterday













          It seems that the iText jar that contains this class is not in the classpath at runtime.
          – Arnaud
          yesterday




          It seems that the iText jar that contains this class is not in the classpath at runtime.
          – Arnaud
          yesterday












          Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
          – Serge Larionoff
          yesterday





          Aha, should it contain exact file names or a parent folder name is enough? Because parent folder is already in a CLASSPATH
          – Serge Larionoff
          yesterday











          Serge Larionoff is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Serge Larionoff is a new contributor. Be nice, and check out our Code of Conduct.












          Serge Larionoff is a new contributor. Be nice, and check out our Code of Conduct.











          Serge Larionoff is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224457%2fhow-to-translate-correctly-an-itext5-code-piece-to-an-itext7%23new-answer', 'question_page');

          );

          Post as a guest














































































          Popular posts from this blog

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20