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

Free Support Forum - aspose.com

setUnderline() is not working properly

Hi
We are using aspose PDF JAVA, we recently moved from aspose.pdf-17.1.0 to aspose.pdf-18.9.
On the new version when using setUnderline() - the line appears on top of the text instead of under it .
example.png (21.1 KB)

we are using the following code

		com.aspose.pdf.facades.PdfContentEditor tmpDoc = new com.aspose.pdf.facades.PdfContentEditor();
		com.aspose.pdf.HtmlLoadOptions options = new com.aspose.pdf.HtmlLoadOptions();
		com.aspose.pdf.PageInfo info = new com.aspose.pdf.PageInfo();
		com.aspose.pdf.MarginInfo marginInfo = new com.aspose.pdf.MarginInfo();
		marginInfo.setTop(0);
		marginInfo.setRight(0);
		marginInfo.setLeft(0);
		info.setMargin(marginInfo);
		info.setLandscape(isLandscape);
		info.setWidth(inpuFileWidth);
		info.setHeight(inpuFileHeight);
		options.setPageInfo(info);
		options.setInputEncoding("UTF-8");

		com.aspose.pdf.Document pdfDoc = stripMode ? new com.aspose.pdf.Document(fwdir+"/conf/scrub_watermark/scrub_stripped_template.tmp.html",options) : 
			new com.aspose.pdf.Document(fwdir+"/conf/scrub_watermark/scrub_watermark_template.tmp.html",options);
		pdfDoc.save(temp_filepath);
		pdfDoc.close();
		
		if(stripMode){
			printLog("scrub_stripped_template was created: " + temp_filepath);
		}else{
			printLog("scrub_watermark_template was created: " + temp_filepath);
		}
		
		//adding uc link color and underline
		tmpDoc.bindPdf(temp_filepath);	
		for (TextFragment outDocFragmentItem:getUcLinkTextFragmentCollectionFromPDF(tmpDoc,get_original_str)) {
			outDocFragmentItem.getTextState().setUnderline(true);
			outDocFragmentItem.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlue());
			templateUcLinksLocation.put(temp_filepath, new java.awt.Rectangle((int)outDocFragmentItem.getRectangle().getLLX(),(int)outDocFragmentItem.getRectangle().getLLY()-1,(int)outDocFragmentItem.getRectangle().getWidth(),(int)outDocFragmentItem.getRectangle().getHeight()));
		}
		tmpDoc.save(temp_filepath);
		tmpDoc.close();

The following code worked properly on the older aspose pdf version

@yaird

Thank you for contacting support.

Would you please share source and generated files along with self-dependent code snippet because shared code includes some undefined methods and variables. We will try to reproduce and investigate it in our environment. Moreover, please ensure using Aspose.PDF for Java 18.10 before sharing requested data.

It looks like version 18.10 is java-8 based, we can’t use it since our environment is running JRE 1.7.

		com.aspose.pdf.facades.PdfContentEditor tmpDoc = new com.aspose.pdf.facades.PdfContentEditor();
		com.aspose.pdf.HtmlLoadOptions options = new com.aspose.pdf.HtmlLoadOptions();
		com.aspose.pdf.PageInfo info = new com.aspose.pdf.PageInfo();
		com.aspose.pdf.MarginInfo marginInfo = new com.aspose.pdf.MarginInfo();
		marginInfo.setTop(0);
		marginInfo.setRight(0);
		marginInfo.setLeft(0);
		info.setMargin(marginInfo);
		info.setLandscape(isLandscape);
		info.setWidth(inpuFileWidth);
		info.setHeight(inpuFileHeight);
		options.setPageInfo(info);
		options.setInputEncoding("UTF-8");

		com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document(fwdir+"/conf/scrub_watermark/scrub_watermark_template.tmp.html",options);
		pdfDoc.save(temp_filepath);
		pdfDoc.close();
		
		//adding uc link color and underline
		tmpDoc.bindPdf(temp_filepath);

	TextFragmentAbsorber outDocAbsorber = new TextFragmentAbsorber("Get Original");
	doc.getDocument().getPages().get_Item(1).accept(outDocAbsorber);
	//get the extracted text fragments
	TextFragmentCollection outDocCollection = outDocAbsorber.getTextFragments();

		for (TextFragment outDocFragmentItem:outDocCollection) {
                        outDocFragmentItem.getTextState().setUnderline(true);
                        outDocFragmentItem.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlue());
		}
		tmpDoc.save(temp_filepath);
		tmpDoc.close();

I’ve uploaded the html - just move the .pdf extension from its name
scrub_watermark_template.tmp.html.pdf (4.3 KB)

@yaird

Thanks for sharing requested data.

Please note that latest versions of Aspose.PDF for Java API supports 1.7 and 1.8 java version alike. Moreover, attached file is downloaded as PDF type and renaming does not work as expected, so kindly share a ZIP directory containing the HTML file. Also, shared code snippet still includes undeclared or undefined variables including isLandscape, inpuFileWidth, doc etc. so we can not compile it to reproduce the scenario exactly. Please share SSCCE code so that we may proceed to help you out.

	String temp_filepath = "YOUR OWN PATH";
	com.aspose.pdf.facades.PdfContentEditor tmpDoc = new com.aspose.pdf.facades.PdfContentEditor();
	com.aspose.pdf.HtmlLoadOptions options = new com.aspose.pdf.HtmlLoadOptions();
	com.aspose.pdf.PageInfo info = new com.aspose.pdf.PageInfo();
	com.aspose.pdf.MarginInfo marginInfo = new com.aspose.pdf.MarginInfo();
	marginInfo.setTop(0);
	marginInfo.setRight(0);
	marginInfo.setLeft(0);
	info.setMargin(marginInfo);
	info.setLandscape(false);
	info.setWidth(612);
	info.setHeight(792);
	options.setPageInfo(info);
	options.setInputEncoding("UTF-8");

	com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document("scrub_watermark_template.tmp.html",options);
	pdfDoc.save(temp_filepath);
	pdfDoc.close();
	
	//adding uc link color and underline
	tmpDoc.bindPdf(temp_filepath);

	TextFragmentAbsorber outDocAbsorber = new TextFragmentAbsorber("Get Original");
	tmpDoc.getDocument().getPages().get_Item(1).accept(outDocAbsorber);
	//get the extracted text fragments
	TextFragmentCollection outDocCollection = outDocAbsorber.getTextFragments();

	for (TextFragment outDocFragmentItem:outDocCollection) {
                    outDocFragmentItem.getTextState().setUnderline(true);
                    outDocFragmentItem.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlue());
	}
	tmpDoc.save(temp_filepath);
	tmpDoc.close();

scrub_watermark_template.tmp.html.zip (2.4 KB)

Also this is what i get when i’m trying to compile aspose.pdf-18.10 with the newest java 7 jdk - "aspose.pdf-18.10.jar(com/aspose/pdf/facades/PdfContentEditor.class): major version 52 is newer than 51, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
"

@yaird

Thank you for sharing requested data.

We have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-38148 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

Regarding the JDK, this does not appear to be an issue with Aspose.PDF for Java API but some problem with your environment variables. The API is compatible with both of the Java versions.

We are sorry for the inconvenience.

is there an update about this one?

@texaspose

Regretfully, the ticket is not yet resolved as it requires more time to get fully investigated and resolved. We will let you know as soon as we have some certain updates regarding ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFJAVA-38148) have been fixed in Aspose.PDF for Java 20.9.