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


























    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
























      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













      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













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 11:00









      Serge Larionoff

      11




      11
























          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
            Nov 9 at 12:44










          • Oh indeed, just edited with a correction.
            – Arnaud
            Nov 9 at 13:02










          • 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
            Nov 9 at 13:41












          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            Nov 9 at 13:43










          • See : stackoverflow.com/questions/17973970/…
            – Arnaud
            Nov 9 at 14:02











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


          }
          });














          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















          Required, but never shown

























          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
            Nov 9 at 12:44










          • Oh indeed, just edited with a correction.
            – Arnaud
            Nov 9 at 13:02










          • 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
            Nov 9 at 13:41












          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            Nov 9 at 13:43










          • See : stackoverflow.com/questions/17973970/…
            – Arnaud
            Nov 9 at 14:02















          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
            Nov 9 at 12:44










          • Oh indeed, just edited with a correction.
            – Arnaud
            Nov 9 at 13:02










          • 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
            Nov 9 at 13:41












          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            Nov 9 at 13:43










          • See : stackoverflow.com/questions/17973970/…
            – Arnaud
            Nov 9 at 14:02













          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 Nov 9 at 13:01

























          answered Nov 9 at 11:29









          Arnaud

          13.3k21630




          13.3k21630












          • 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
            Nov 9 at 12:44










          • Oh indeed, just edited with a correction.
            – Arnaud
            Nov 9 at 13:02










          • 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
            Nov 9 at 13:41












          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            Nov 9 at 13:43










          • See : stackoverflow.com/questions/17973970/…
            – Arnaud
            Nov 9 at 14:02


















          • 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
            Nov 9 at 12:44










          • Oh indeed, just edited with a correction.
            – Arnaud
            Nov 9 at 13:02










          • 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
            Nov 9 at 13:41












          • It seems that the iText jar that contains this class is not in the classpath at runtime.
            – Arnaud
            Nov 9 at 13:43










          • See : stackoverflow.com/questions/17973970/…
            – Arnaud
            Nov 9 at 14:02
















          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
          Nov 9 at 12:44




          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
          Nov 9 at 12:44












          Oh indeed, just edited with a correction.
          – Arnaud
          Nov 9 at 13:02




          Oh indeed, just edited with a correction.
          – Arnaud
          Nov 9 at 13:02












          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
          Nov 9 at 13:41






          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
          Nov 9 at 13:41














          It seems that the iText jar that contains this class is not in the classpath at runtime.
          – Arnaud
          Nov 9 at 13:43




          It seems that the iText jar that contains this class is not in the classpath at runtime.
          – Arnaud
          Nov 9 at 13:43












          See : stackoverflow.com/questions/17973970/…
          – Arnaud
          Nov 9 at 14:02




          See : stackoverflow.com/questions/17973970/…
          – Arnaud
          Nov 9 at 14:02


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          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















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()