SheetRender toImage EMF generate text as curves

Hello,
is there a way to generate emf images form a SheetRender toImage without text and relative font-family, but convert the text to curves.

If I have a custom font installed on the machine that generates the emf images, but not on the clients that open the images or word documents containing them, I can’t see them properly.

Thanks,
Federico.

@federico.mameli
We will study and get back to you as soon as possible.

@federico.mameli ,

SheetRender.toImage requires relevant fonts to be installed on the server side only (where the code is processed). Please make sure the underlying fonts (used in the workbook) are installed and are there in your fonts folder on the machine processing sample code (using Aspose.Cells). Also, see the document on how to configure fonts and you should configure/set fonts folder path to render EMF images of the worksheet(s) at the start of your program.

In case, you still find any issue, kindly do share (please zip the files prior attaching) your input Excel file, your output EMF image files and your sample code (runnable) that you are using. We will check your issue soon.

I start by sharing the excel source file, a custom font and word output
aspose.zip (231.4 KB)

In the output file you can find an emf image and a png image, if you open the output file from a computer without the custom font installed you will see the images like this
MicrosoftTeams-image (8).png (102.0 KB)

If you open the output file from a computer with the custom font installed you will see this
image.png (141.8 KB)

I’ll prepare an example with the code example

@federico.mameli ,

I did test your scenario/case after installing the (shared) font on my pc first and then try the following sample code with your template Excel file, it works fine and the output EMF image is fine tuned:
e.g.
Sample code:


       Workbook workbook = new Workbook("f:\\files\\PIANETI-FONT-GOOGLE-PACIFICO.xlsx");
       // Access the first worksheet
       Worksheet worksheet = workbook.getWorksheets().get(0);
       worksheet.autoFitRows(false);

       // Set all margins as 0
       worksheet.getPageSetup().setLeftMargin(0);
       worksheet.getPageSetup().setRightMargin(0);
       worksheet.getPageSetup().setTopMargin(0);
       worksheet.getPageSetup().setBottomMargin(0);

       // Set OnePagePerSheet option as true
       ImageOrPrintOptions options = new ImageOrPrintOptions();
       options.setOnePagePerSheet(true);
       options.setImageType(ImageType.EMF);

       // Take the image of your worksheet
       SheetRender sr = new SheetRender(worksheet, options);
       sr.toImage(0, "f:\\files\\PIANETI-FONT-GOOGLE-PACIFICO.emf");

Please find attached the output EMF image for your reference.
PIANETI-FONT-GOOGLE-PACIFICO.zip (36.5 KB)

I have also discovered that there are two worksheets with similar data, but they use different fonts. Please check if you are converting the second worksheet, which is using the “Calibri” font. Additionally, please note that the fonts required for rendering spreadsheets to images should be installed where the sample code is being processed. If the processing is done on a server, then you only need to install the fonts on the server.

Yes but only one range has a name “PIANETI”
This is my less or more code.
And if I open the emf from a computer without the font installed the result is the one in the picture


      Workbook workbook = new Workbook(AsposeTest.class.getResourceAsStream("input1.xlsx"));
      Range range = workbook.getWorksheets().getRangeByName("PIANETI");
      Worksheet ws = range.getWorksheet();
      PageSetup pageSetup = ws.getPageSetup();
      pageSetup.setPrintArea(range.getAddress());
      pageSetup.setPrintTitleRows("");
      pageSetup.setPrintTitleColumns("");
      pageSetup.setLeftMargin(0.0);
      pageSetup.setRightMargin(0.0);
      pageSetup.setTopMargin(0.0);
      pageSetup.setBottomMargin(0.0);
      List<Integer> section = IntStream.rangeClosed(0, 2).boxed().collect(Collectors.toList());
      section.forEach(s -> {
        pageSetup.setFirstPageHeader(s, "");
        pageSetup.setHeader(s, "");
        pageSetup.setFirstPageFooter(s, "");
        pageSetup.setFooter(s, "");
      });
      ImageOrPrintOptions opts = new ImageOrPrintOptions();
      opts.setImageType(ImageType.PNG);
      opts.setOnePagePerSheet(true);
      opts.setOnlyArea(true);
      opts.setHorizontalResolution(900);
      opts.setVerticalResolution(900);
      SheetRender renderer = new SheetRender(ws, opts);
      FileOutputStream fileOutputStream = new FileOutputStream("out1.png");
      renderer.toImage(0, fileOutputStream);
      fileOutputStream.flush();
      fileOutputStream.close();
      ImageOrPrintOptions opts1 = new ImageOrPrintOptions();
      opts1.setImageType(ImageType.EMF);
      opts1.setOnePagePerSheet(true);
      opts1.setSVGFitToViewPort(true);
      SheetRender renderer1 = new SheetRender(ws, opts1);
      FileOutputStream fileOutputStream1 = new FileOutputStream("out2.emf");
      renderer1.toImage(0, fileOutputStream1);
      fileOutputStream1.flush();
      fileOutputStream1.close();

@federico.mameli ,

I tried the following sample code with your template Excel file and generated the two images (PNG and EMF) on a system (I already installed the font “Pacifico” on it).
e.g.
Sample code:


        Workbook workbook = new Workbook("f:\\files\\PIANETI-FONT-GOOGLE-PACIFICO.xlsx");
        Range range = workbook.getWorksheets().getRangeByName("PIANETI");
        Worksheet ws = range.getWorksheet();
        PageSetup pageSetup = ws.getPageSetup();
        pageSetup.setPrintArea(range.getAddress());
        pageSetup.setPrintTitleRows("");
        pageSetup.setPrintTitleColumns("");
        pageSetup.setLeftMargin(0.0);
        pageSetup.setRightMargin(0.0);
        pageSetup.setTopMargin(0.0);
        pageSetup.setBottomMargin(0.0);
        ImageOrPrintOptions opts = new ImageOrPrintOptions();
        opts.setImageType(ImageType.PNG);
        opts.setOnePagePerSheet(true);
        opts.setOnlyArea(true);
        opts.setHorizontalResolution(900);
        opts.setVerticalResolution(900);
        SheetRender renderer = new SheetRender(ws, opts);
        FileOutputStream fileOutputStream = new FileOutputStream("f:\\files\\out1.png");
        renderer.toImage(0, fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
        ImageOrPrintOptions opts1 = new ImageOrPrintOptions();
        opts1.setImageType(ImageType.EMF);
        opts1.setOnePagePerSheet(true);
        opts1.setSVGFitToViewPort(true);
        SheetRender renderer1 = new SheetRender(ws, opts1);
        FileOutputStream fileOutputStream1 = new FileOutputStream("f:\\files\\out2.emf");
        renderer1.toImage(0, fileOutputStream1);
        fileOutputStream1.flush();
        fileOutputStream1.close();

Please find attached both image files in the zipped archive.
files1.zip (155.3 KB)

On your system (where the font is not installed), please unzip the image files to a drive/folder. Then open both image files directly and provide screenshots to demonstrate how these images are displayed on your end. We will further investigate.

We noticed a strange behaviour:
I inserted the two images in a word document, because it was always my goal.
If I open the document from word desktop in a computer without the font, I see it with another font like this:
MicrosoftTeams-image (9).png (68.1 KB)
but it is the same if I open the emf on thet computer with MS Paint:
MicrosoftTeams-image (11).png (48.9 KB)

When I open the document from word web form anywhere I see it correctly, maybe because word web can retrieve the font online? I don’t know.

I don’t know how are you opening the emf, but consider this behaviour

@federico.mameli ,

We will open the output images (which I shared) onto a machine where the font is not installed. We will get back to you with updates soon.

@federico.mameli ,

We can see the behavior as you screenshot on a manchine where the font is not installed: the text ischanged with another font. It is because that EMF image is vector image and the custom font can’t be emdded into EMF image.

I also tried to embed the font into the output word document, but it only works for the plain text in word document itself, not for the text in the inserted EMF image.

Currently we don’t support to render plain text as curves while genrating EMF image.
Also, rendering text as curves is not a good choice, the file size of generated EMF may be huge.

  1. the text chars may need lots of EMF records to decribe them.
  2. duplicated records may be generated. e.g. the char ‘o’ in text ‘Raggio’ and ‘medio’.

Ok, Thanks,
Federico

@fedotkin.as
You are welcome. If you have any questions, please feel free to contact us.