How to Embed Font in Existing PDF Documents inside Android Applications

This technical tip shows how to embed a font in a PDF file inside android applications. PDF readers support a core of 14 fonts so that documents can be displayed the same way regardless of the platform the document is displayed on. When a PDF contains a font that is outside the core fonts, embed the font to avoid font substitution. Aspose.Pdf for Android supports font embedding in existing PDF documents. You can embed a complete font or a subset. A font subset embeds only the characters that are used and is useful where fonts are used for short sentences or slogans, for example where a corporate font is used for a logo, but not for the body text. Using a subset reduces the file size of the output PDF. However if a custom font is used for the body text, embed it in its entirety.
//your code here...The following code snippet shows how to embed a font in a PDF file. //Open the document com.aspose.pdf.Document doc = new com.aspose.pdf.Document("/mnt/sdcard/input.pdf"); //Iterate through all the pages for(com.aspose.pdf.Page page : (Iterable<com.aspose.pdf.Page>)doc.getPages()) { if (page.getResources().getFonts() != null) { for(com.aspose.pdf.Font pageFont : (Iterable<com.aspose.pdf.Font>)page.getResources().getFonts()) { //Check if font is already embedded if (!pageFont.isEmbedded()) pageFont.isEmbedded(true); } } //Check for the Form objects for(com.aspose.pdf.XForm form : (Iterable<com.aspose.pdf.XForm>)page.getResources().getForms()) { if (form.getResources().getFonts() != null) { for(com.aspose.pdf.Font formFont : (Iterable<com.aspose.pdf.Font>)form.getResources().getFonts()) { //Check if the font is embedded if (!formFont.isEmbedded()) formFont.isEmbedded(true); } } } } //Save the document"/mnt/sdcard/FontEmbedded_output.pdf");


Language: Python | User: Sheraz Khan | Created: Dec 24, 2014 | Tags: embed font in PDF file Embed Font Subset in PDF file Open an existing PDF file Use subset in output PDF font embedding in existing PDF read Excel worksheet cells values Android Excel API