We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue with getCharacterSpacing() and getLineSpacing() in Aspose.pdf for Java

Hi,


I am using the below code to validate pdfs if the character spacing and line spacing are different. I have used multiple pdfs but getCharacterSpacing() and getLineSpacing() always return 0.0 as the result.

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(“test.pdf”);
com.aspose.pdf.TextFragmentAbsorber textAbsorber = new com.aspose.pdf.TextFragmentAbsorber("[\S]+");
// Set text search option to specify regular expression usage
com.aspose.pdf.TextSearchOptions textSearchOptions = new com.aspose.pdf.TextSearchOptions(true);
textAbsorber.setTextSearchOptions(textSearchOptions);

pdfDocument.getPages().accept(textAbsorber);

// Loop through the Text fragments
for (com.aspose.pdf.TextFragment textFragment : (Iterable<com.aspose.pdf.TextFragment>) textAbsorber.getTextFragments()) {
System.out.println("Character Spacing :- " + textFragment.getTextState().getCharacterSpacing());
System.out.println("Line Spacing :- " + textFragment.getTextState().getLineSpacing());
System.out.println("Font - Name :- " + textFragment.getTextState().getFont().getFontName());
System.out.println("Font Size :- " + textFragment.getTextState().getFontSize());

}

Can you please let me know if there is a way in aspose.pdf for java to validate a pdf file for its character and line spacing.

Regards,

Hi Rajeev,


Thanks for contacting support.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWJAVA-35024 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.

Hi Rajeev,


Thanks for your patience. We have investigated the issue and found it is not bug. Please note the text in this document is positioned by coordinates of TextFragment so LineSpacing and CharacterSpacing are really empty. If you need to get spacing between lines for this document you should to analyse positions of text fragments by using methods textFragment.getPosition().getXIndent() and textFragment.getPosition().getYIndent(). Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Hi,


Can you please provide a pdf document where line spacing and character spacing is retrieved by aspose. I have attached two pdf files which I generated from word document by setting the Line spacing in word document and in both the case aspose does not retrieve any line spacing or character spacing.

The pdf files I need to validate are provided by the user so I might not be setting the line spacing or character spacing using aspose but I will need to retrieve it for a pdf.

Regards,

Hi there,


Thanks for your inquiry. I have created a sample PDF document with line spacing and character spacing and tested the scenario again, Aspose.Pdf for Java is recognizing character spacing but line spacing. So I have logged an investigation ticket PDFNEWJAVA-35282 for further investigation and will update you our finding asap.

We are sorry for the inconvenience caused.

Best Regards,

Hi Tilal,

I think you might have created the pdf using aspose and therefore it is able to read the character spacing. If I set character spacing in word document and save it as a pdf and then read the character spacing it does not work.
Our users can create pdf using any tool word, adobe etc. so we need to support for all of them.
Regards,
Rajeev

Hi Rajeev,


Thanks for your feedback. Please note your above shared PDF documents generated by word have zero character spacing, so Aspose.Pdf is returning zero. However please share the document that has some valid character spacing value and Aspose.Pdf is not recognizing it, we will investigate it further.

Moreover, I have tested the scenario with sample PDF documents generated via Aspose.Pdf and Adobe Acrobat.

We are sorry for the inconvenience caused.

Best Regards,

Hi,


Thanks for your response. I am able to retrieve the character spacing but can you help me in understanding how can I use the getCharacterSpacing to validate that there are only certain number of characters in a given inch.

Regards,

Hi,


Thanks for contacting support.

The above query has been answered in your other forum thread. In case we can be of any further assistance, please feel free to contact