Hi,
Hi Zeeshan,
sPDFMessage = sPDFMessage.replace("",“zeeshan”);
HtmlLoadOptions htmloptions = new HtmlLoadOptions("/Users/fahadadeel/Downloads/resources/");
InputStream stream = new ByteArrayInputStream(sPDFMessage.getBytes(StandardCharsets.UTF_8));
Document doc = new Document(stream, htmloptions );
doc.save(dataDir + “output_pdf.pdf”);
Hi
Hi Zeeshan,
Hi Fawad,
Hi Zeeshan,
Thanks for your inquiry. As per my understanding it seems Aspose.Pdf for Java is unable to find fonts on your system. Please note on non-Windows OSs Aspose.Pdf for Java looks fonts in system default font path or specified local font path for custom font directory.
Please note most of the PDF documents that we convert are created by people using Windows or Mac OS operating systems with fonts that are installed with Microsoft Windows or with Microsoft Office. To resolve your issue either you can install Microsoft fonts on your system or copy fonts from your windows OS and paste to your system default font path.
Furthermore, if you want to use custom fonts from other than system default font path then you need to add that folder path into LocalFontPath as following. You can use following methods to get system folder of fonts or set font path to font folders.
- Document.getLocalFontPath () - shows the system folder in which project will look for fonts.
- Document.setLocalFontPath (String) - Setting font path to custom folder
// Set font folder path
String path = “/home/zeeshan/fonts/”;
// Adding a single font directory
// com.aspose.pdf.Document.addLocalFontPath(path);
// setting the user list for standard font directories
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
list.add(path);
com.aspose.pdf.Document.setLocalFontPaths(list);
Please apply the fonts before conversion of HTML to PDF. If you still face any issue, please feel free to contact us.
We are sorry for the inconvenience caused.
Best Regards,
Hi Fahad,
HI Zeeshan.
1. If Java is unable to find fonts on any system, Aspose should not stop creating a PDF but it should show junk in place of those characters in PDF. (Ex:- If word or any other software that needs font encounters a character which is not supported by font they show junk in place of that character.)
I have logged an enhancement ticket as PDFJAVA-36625 in our issue tracking system. We will further look into the details of this enhancement and will keep you posted on the status of its implementation. Please be patient and spare us little time.
2. On upgrading jars from aspose.pdf-11.3.0.jar to aspose.pdf-17.2.0.jar, and using normal english characters, the width of our generated PDF gets increased by about an inch for with every increase in number of lines in paragraph.(Observed about 1inch/line)
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}
I will appreciate if you please share your sample html string along with output file. It will help us to understand your requirement exactly and address it accordingly.
1. Are we authorized to copy window's fonts into linux and use freely? Are window's fonts free (open source) to use any where freely?
Yes, using Microsoft fonts on linux is legal. You can read EULA here: https://www.microsoft.com/typography/fontpack/eula.htm The key parts of the license are, "The SOFTWARE PRODUCT is licensed, not sold." and "You may install and use an unlimited number of copies of the SOFTWARE PRODUCT."
2. I once tried to copy "Arial Unicode MS" font from windows to linux's 'font' directory and it worked for many characters but not for all. Can you please suggest me some font name that support's all characters (Full-Width, Half-Width, CJK, Chinese, Japanese, Korean, German and French characters.) and can be freely used?
you can try some font from the list of all unicode supported fonts https://en.wikipedia.org/wiki/Unicode_font
3. we have jar and license for aspose.pdf-11.3.0.jar. On upgrading jars, do we also need to get new license?
I have created a separate forum thread for this query using email to post feature and you will be notified on your email address. https://www.aspose.com/community/forums/832610/showthread.aspx#832610 is the link for the forum thread.
If you need further assistance, please feel free to contact us.
We are sorry for the inconvenience.
Best Regards,
Hi Fahad,
2. On upgrading jars from aspose.pdf-11.3.0.jar to aspose.pdf-17.2.0.jar, and using normal english characters, the width of our generated PDF gets increased by about an inch for with every increase in number of lines in paragraph.(Observed about 1inch/line)
HI Zeeshan.
Hi Fahad
zeeshan3ds:
Hi FahadThanks for reply.We will be much obliged, if we get both the issue PDFJAVA-36625 and PDFJAVA-36628 resolved as soon as possible.Hi Zeeshan,Thanks for contacting support.The issues as resolved in first come first serve basis and as soon as we have some definite updates regarding their resolution, we will update you within this forum thread.Please visit the following link for required information on Convert PDF to HTML formatzeeshan3ds:
Can you please share us the Aspose documentation for HTML to PDF conversion in java as we are unable to find any documentation for that on Aspose website.
Hi Shahbaz,
Hi Zeeshan,
We want to make sure whether we need to get license for those fonts or not
Whether those fonts get embedded in the PDF
And is it possible to prevent fonts from getting embedded in the generated PDF
dataDir = dataDir + “OptimizeFileSize_out.pdf”;
// Save output document
pdfDocument.Save(dataDir);
Hi Fahad,

Hi Zeeshan,
What do you mean by “document may become unreadable on removing fonts”
2. The code generating Document object (Document doc = new Document(stream, htmloptions)is taking a lot of time. How can we optimize this process ?
3. The size of the generated PDF file just containing 5 pages is too big. How can we minimize the file size ?
Hi Fahad,
Hi Zeeshan,
Hi Zeeshan,
String sPDFMessage = new String(Files.readAllBytes(Paths.get(dataDir+ “test.htm”)));
sPDFMessage = sPDFMessage.replaceAll("", “XYZ”);
sPDFMessage = sPDFMessage.replaceAll("", “Zeeshan”);
sPDFMessage = sPDFMessage.replaceAll("
System.out.println("before: " + sPDFMessage);
String templatePath = dataDir ;
HtmlLoadOptions htmloptions = new HtmlLoadOptions(templatePath);
MarginInfo marginInfo = new MarginInfo(50, 72, 40, 65);
htmloptions.getPageInfo().setMargin(marginInfo);
System.out.println(“Creating Document…”);
InputStream stream = new ByteArrayInputStream(sPDFMessage.getBytes(StandardCharsets.UTF_8));
Document doc = new Document(stream, htmloptions);
for(int counter=1; counter <= doc.getPages().size(); counter++) {
Page pdfPage = doc.getPages().get_Item(counter);
for (Font pageFont : (Iterable) pdfPage.getResources().getFonts()) {
if (pageFont.isEmbedded()) {
pageFont.setEmbedded(false);
}
if (pageFont.isSubset()) {
pageFont.setSubset(false);
}
}
}
// Setting Header
ImageStamp headerImg = new ImageStamp(dataDir + “test.jpg”);
headerImg.setHeight(64);
headerImg.setWidth(595);
headerImg.setTopMargin(0);
headerImg.setVerticalAlignment(VerticalAlignment.Top);
headerImg.setBackground(true);
headerTxt.setTopMargin(20);
headerTxt.setHorizontalAlignment(HorizontalAlignment.Center);
headerTxt.setVerticalAlignment(VerticalAlignment.Top);
//set text properties
Font font = null;
try {
font = FontRepository.findFont(“Sans-Serif”, true);
} catch(Exception e) {
System.out.println(e.getMessage());
}
if(font == null) {
font = headerTxt.getTextState().getFont();
System.out.println(“Font:”+font.getFontName());
}
headerTxt.getTextState().setFont(font);
headerTxt.getTextState().setFontSize(23.0F);
headerTxt.getTextState().setForegroundColor(Color.getWhite());
doc.getPages().get_Item(1).addStamp(headerImg);
doc.getPages().get_Item(1).addStamp(headerTxt);
doc.save(dataDir + “abcTest12.pdf”);
System.out.println(“Done…”);
The issues you have found earlier (filed as PDFJAVA-36628) have been fixed in Aspose.PDF for Java 18.3. This message was posted using BugNotificationTool by @asad.ali