Hi Team,
We are trying to transformation input file with below code.
Document doc = new Document("test.docx");
PdfSaveOptions options = new PdfSaveOptions();
doc.save("output.pdf", options);
Formatting and Alignment of word document content (like Font, Font Size, Line Spacing, Word Spacing, etc.) is not retained exactly in PDF Rendition as shown in image.jpg in files.zip (119.2 KB)
When output file is compared to test file we see in last page the signnature part is not aligned as shown in image.jpg.
To ensure that the formatting and alignment of your Word document are accurately retained when converting to PDF using Aspose.Words, you can utilize various options available in the PdfSaveOptions class. Here are some suggestions to help you achieve better fidelity in your PDF output:
Embed Fonts: Make sure to embed all fonts used in your document. This can be done by setting the EmbedFullFonts property to true. This ensures that the exact font styles and sizes are preserved in the PDF.
PdfSaveOptions options = new PdfSaveOptions();
options.EmbedFullFonts = true;
Use Core Fonts: If your document uses standard fonts, you can set the UseCoreFonts property to true to utilize the built-in fonts available in PDF readers, which can help maintain consistency.
options.UseCoreFonts = true;
Adjust DML Effects Rendering: If your document contains DrawingML elements, consider adjusting the DmlEffectsRenderingMode to DmlEffectsRenderingMode.Fine for better rendering quality.
Set Compliance Level: Depending on your requirements, you might want to set the PDF compliance level. For example, setting it to PdfCompliance.PdfA1b can help ensure that the document adheres to certain standards, which may improve rendering.
options.Compliance = PdfCompliance.PdfA1b;
Handle Warnings: Implement a warning callback to capture any rendering issues that may arise during the conversion process. This can help you identify specific elements that may not be rendered as expected.
HandleDocumentWarnings callback = new HandleDocumentWarnings();
doc.WarningCallback = callback;
Check for Specific Formatting Issues: If certain elements, like signatures, are not aligning correctly, you may need to manually adjust their positioning in the Word document before conversion. Ensure that the layout in Word is as intended.
Here is a complete example of how you might set up your conversion:
By applying these settings, you should see an improvement in how the PDF output matches the original Word document in terms of formatting and alignment. If issues persist, consider reviewing the specific elements in your Word document that may require additional adjustments.
If you continue to experience discrepancies, please provide more details about the specific formatting issues, and I can assist you further.
// Open a document
Document doc = new Document("in.docx");
// When text shaper factory is set, layout starts to use OpenType features.
// An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
// Render the document to PDF format
doc.save("out.pdf");
Hi @alexey.noskov,
We tried installing fonts in the environment and tried rendition, but the issue is still reproducible as we can see arial fonts are used in output file.
Can you suggest how can we simplify rendition only with arabic fonts?
Thanks,
Krishna
@rnara Have you tried implementing IWarningCallback to get a notification when font substitution is performed. As mentioned above, Aspose.Words requires the fonts used in the source document to properly render the document.
Hi @alexey.noskov,
By implentation of IWarningCallback | Aspose.Words for Java , we are getting completely different content attached below. outp.pdf (32.1 KB)
In our case we have arial font installed in our system by default and that is being subsituted.
Can you please tell how we can use simplified Arabic font instead of arial in the document while rendititon
Thanks,
Krishna
@rnara I mean implemention IWarningCallback to get notifications about font substitutions. The document you have attached uses Fanwood font. Most likely the environment does not have available fonts at all, since the last resort font Fanwood is used for rendering the document. This font is embedded into Aspose.Words library and is used if no other fonts are available.
I have tried implementing IWarningCallback | Aspose.Words for Java but still i don’t see any warnings for font substitution.
As in output file I can see Arial font is being substituted but warning is not coming up on console.
I have tried installing Fanwood font also but still the output is not as expected.
Output file shared below : output.pdf (101.7 KB)
@rnara It looks like misunderstood me. I mean that in the PDF you have attached Fanwood font is used instead the font specified in your source document. This occurs when there are no font available in the environment where document is converted to PDF. Aspose.Words uses Fanwood font as the last resort font.
Please try using the following code to check for warnings:
Document doc = new Document("C:\\Temp\\in.docx");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.save("C:\\Temp\\out.pdf");
private static class FontSubstitutionWarningCollector implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION) {
System.out.println(info.getDescription());
}
}
}
@rnara Enabling Open Type Feature does not affect font substitution. Here is the PDF document produced on my side: out.pdf (64.5 KB)
As I can see it looks the same as PDF produced by MS Word.
// Open a document
Document doc = new Document("in.docx");
// When text shaper factory is set, layout starts to use OpenType features.
// An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
// Render the document to PDF format
doc.save("out.pdf");
Hi @alexey.noskov ,
I tried reproducing and now I don’t see any Calibri or other fonts expect arabic.
But the signature part is still not aligned as shown in image below
I have attached both out.pdf and out.xps files below. files.zip (149.6 KB)
Hi @alexey.noskov ,
As we have tried all possibilities suggested but none of them worked.
Can you please provide any solution on how we can move ahead or fix this issue?
Thanks,
Krishna
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.