Hi-
Does Aspose Slides provide a way to iterate over all the objects in a presentation in order to get access to the fonts objects are using?
My goal is to change a font in the presentation to a supported font if a unsupported font is found.
Thanks!
I tried the following w/o success.
Presentation pptPresentation = new Presentation(in);
Fonts f = pptPresentation.getFonts();
for (int i = 0; i
FontEntity fe = f.get(i);
String fontName = fe.getFontName();
fe.setFontName(“Wingdings”);
}
pptPresentation.save(out, com.aspose.slides.export.SaveFormat.PPT, pdfOptions);
Hi,
I tred the code and was able to iterate over the elements, but setting the font didn’t work. My code:
if (paras != null) {
int parasCount = paras.size();
for (int paraIdx = 0; paraIdx
Paragraph para = paras.get(paraIdx);
// print the text on console
Portions p = para.getPortions();
// added this code to set font to index 4, which is arial
for (Portion portion : p) {
portion.setFontIndex(4);
}
}
Thanks,
Dave
pptPresentation.save(out, com.aspose.slides.export.SaveFormat.PDF, pdfOptions);
Hi Dave,
Code below & ppt attached. Note the fonts in the pdf end up being Times. None are Arial.
com.aspose.slides.export.PdfOptions pdfOptions = new com.aspose.slides.export.PdfOptions();
// Set Jpeg Quality
pdfOptions.setJpegQuality(60);
// Define behavior for metafiles
pdfOptions.setSaveMetafilesAsPng(true);
// Set Text Compression level
pdfOptions.setTextCompression(com.aspose.slides.export.PdfTextCompression.FLATE);
// Define the PDF standard
pdfOptions.setCompliance(com.aspose.slides.export.PdfCompliance.PDF_15);
File thingFolder = LC3Environment.getThingDirectory(thingID, domain);
out = new FileOutputStream(new File(thingFolder, thingFile.getName() + “.pdf”));
// Instantiate a Presentation object that represents a PPT file
if (thingFile.getName().toLowerCase().endsWith(“ppt”)) {
Presentation pptPresentation = new Presentation(in);
Fonts f = pptPresentation.getFonts();
int arial = -1;
for (int i = 0; i
FontEntity fe = f.get(i);
String fontName = fe.getFontName();
if (fe.getFontName().equalsIgnoreCase(“arial”)) {
arial = i;
// break;
}
}
int lastSlidePosition = pptPresentation.getSlides().getLastSlidePosition();
for (int pos = 1; pos <= lastSlidePosition; pos++) {
Slide sld = pptPresentation.getSlideByPosition(pos);
// iterate all shapes
int shapesCount = sld.getShapes().size();
for (int shpIdx = 0; shpIdx < shapesCount; shpIdx++) {
com.aspose.slides.Shape shp = sld.getShapes().get(shpIdx);
// Get the paragraphs from textholder or textframe
Paragraphs paras = null;
// Check if shape holds a textholder
if (shp.getPlaceholder() != null && shp.isTextHolder() == true) {
// Get the place holder as an Object instance
Object obj = shp.getPlaceholder();
// First type of place holder. It is TextHolder
if (obj instanceof TextHolder) {
// Cast object into TextHolder object
TextHolder txtHolder = (TextHolder) obj;
paras = txtHolder.getParagraphs();
// iterateParagraphs(paras, portionList);
} else if (obj instanceof Placeholder) // Second type of place holder(Shape)
{
// Cast the object into Placeholder object
Placeholder placeHolder = (Placeholder) obj;
// getShapeRef() returns the Shape object which contains real properties of a Placeholder.
paras = placeHolder.getShapeRef().getTextFrame().getParagraphs();
// iterateParagraphs(paras, portionList);
}
} else {
if (shp.getTextFrame() != null) {
paras = shp.getTextFrame().getParagraphs();
}// if
}// else
// Print the text on Console
if (paras != null) {
int parasCount = paras.size();
for (int paraIdx = 0; paraIdx < parasCount; paraIdx++) {
Paragraph para = paras.get(paraIdx);
// print the text on console
Portions p = para.getPortions();
for (Portion portion : p) {
portion.setFontIndex(4);
}
}
}// end if
}// end for
}// end for
pptPresentation.save(out, com.aspose.slides.export.SaveFormat.PDF, pdfOptions);
Hi Dave,
public static void ChangeFont()throws Exception{com.aspose.slides.export.PdfOptions pdfOptions = new com.aspose.slides.export.PdfOptions();// Set Jpeg QualitypdfOptions.setJpegQuality(60);// Define behavior for metafilespdfOptions.setSaveMetafilesAsPng(true);// Set Text Compression levelpdfOptions.setTextCompression(com.aspose.slides.export.PdfTextCompression.FLATE);// Define the PDF standardpdfOptions.setCompliance(com.aspose.slides.export.PdfCompliance.PDF_15);//File thingFolder = LC3Environment.getThingDirectory(thingID, domain);//out = new FileOutputStream(new File(thingFolder, thingFile.getName() + “.pdf”));// Instantiate a Presentation object that represents a PPT file//if (thingFile.getName().toLowerCase().endsWith(“ppt”))//{String path=“C:/Users/Mudassir/Downloads/demo.ppt/”;//Presentation pptPresentation = new Presentation(in);com.aspose.slides.Presentation pptPresentation = new Presentation(path+“demo.ppt”);Fonts f = pptPresentation.getFonts();int arial = -1;for (int i = 0; i<f.size();i++){com.aspose.slides.FontEntity fe = f.get(i);String fontName = fe.getFontName();if (fe.getFontName().equalsIgnoreCase(“arial”)){arial = i;// break;}//}}int lastSlidePosition = pptPresentation.getSlides().getLastSlidePosition();for (int pos = 1; pos <= lastSlidePosition; pos++){Slide sld = pptPresentation.getSlideByPosition(pos);// iterate all shapesint shapesCount = sld.getShapes().size();for (int shpIdx = 0; shpIdx < shapesCount; shpIdx++){com.aspose.slides.Shape shp = sld.getShapes().get(shpIdx);// Get the paragraphs from textholder or textframeParagraphs paras = null;// Check if shape holds a textholderif (shp.getPlaceholder() != null && shp.isTextHolder() == true){// Get the place holder as an Object instanceObject obj = shp.getPlaceholder();// First type of place holder. It is TextHolderif (obj instanceof TextHolder){// Cast object into TextHolder objectTextHolder txtHolder = (TextHolder) obj;paras = txtHolder.getParagraphs();// iterateParagraphs(paras, portionList);}else if (obj instanceof Placeholder) // Second type of place holder(Shape){// Cast the object into Placeholder objectPlaceholder placeHolder = (Placeholder) obj;// getShapeRef() returns the Shape object which contains real properties of a Placeholder.paras = placeHolder.getShapeRef().getTextFrame().getParagraphs();// iterateParagraphs(paras, portionList);}}else{if (shp.getTextFrame() != null){paras = shp.getTextFrame().getParagraphs();}// if}// else// Print the text on Consoleif (paras != null){int parasCount = paras.size();for (int paraIdx = 0; paraIdx < parasCount; paraIdx++){Paragraph para = paras.get(paraIdx);// print the text on consolePortions p = para.getPortions();for (Portion portion : p){portion.setFontIndex(arial);// portion.setFontIndex(0);}}}// end if}// end for}// end forpptPresentation.save(path+“ArialPdf.pdf”, com.aspose.slides.export.SaveFormat.PDF, pdfOptions);}
Hi -
Where can I get slides 2.8, doesn’t seem to have been released.
I’m using 2.7.0.
–
Dave
Hi Dave,
I have already shared the link to Aspose.Slides for Java 2.8.0 in my provious post. Please download Aspose.Slides for Java 2.8.0 in Jar File.rar shared here.
Many Thanks,
I tried 2.8 without success. All the fonts are Times. Note, I’m running on a Mac.
Hi Dave,
I’d like to get a clarification on how the slides code flows.
I’ve seen two use cases.
1. I’ve seen fonts replaced with Times New Roman in the backend slides code. This is without using the test font replacement code.
2. I’ve seen an exception when a font is missing.
Question - What case does aspose replace a font and in what case is an exception thrown?
Thanks!
Hi,
The last reply to this was not definitive. Can I get a reply as to exactly how it works?
Thanks!
Hi,
Thanks for the reply. We have installed the fonts.
Our observations have been that if a font is missing we get Times New Roman.
One more question. Is there a way to prevent the substitution and get the exception thrown if a font is missing?
–
Dave
Hi Dave,
The issues you have found earlier (filed as SLIDESJAVA-33172) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
One of these articles will be helpful:
Default Fonts
Font Replacement
Font Substitution
Fallback Font
Please, check the following article:
Getting Warning Callbacks for Fonts Substitution in Aspose.Slides