Horizontal Line not rendering using java aspose pdf

Hi I am crated pdf using Document object. (using HtmlFragment class).
I want to change horizontal line background color.


but if i give color code in html content also not showing
line color

Hi there,

Thanks for your inquiry. I have tested horizontal scenario with following HTML using Aspose.Pdf for Java 10.4.0 and noticed that JAR does not honor background color. For further investigation, I have logged an issue in our issue tracking system as PDFNEWJAVA-34971 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

However, horizontal line does not disappear. Please share your sample HTML here, so we will test it as well.


HTML text:

hr { background-color: red; height: 1px; border: 0; }

A hr element is displayed like this:


Change the default CSS settings to see the effect.


We are sorry for the inconvenience caused.

Best Regards

Thanks for Reply

    We can render <hr> tag in pdf. But I am not able to change <hr> line color. It's showing default color (black color). I want to give custom color. Please give any other suggestion for line n PDF

Hi there,


Thanks for your feedback. As stated above, we have logged a ticket to fix the color issue in HTML text. However as a workaround you can add a colored horizontal line as following. Hopefully it will help you to accomplish the task.

Document doc = new Document();<o:p></o:p>

com.aspose.pdf.Page page =
doc.getPages().add();<o:p></o:p>

TextFragment text = new TextFragment(“test text
with line”
);<o:p></o:p>

com.aspose.pdf.drawing.Graph graph1 = new
com.aspose.pdf.drawing.Graph((float)page.getRect().getWidth(), 2);<o:p></o:p>

// Add the line to paraphraphs
collection of section object
<o:p></o:p>

//specify the coordinates for the
line
<o:p></o:p>

float[] posArr = new float[] { 0, 2, (float)page.getRect().getWidth(),
2 };<o:p></o:p>

com.aspose.pdf.drawing.Line line = new
com.aspose.pdf.drawing.Line(posArr);<o:p></o:p>

line.getGraphInfo().setColor(com.aspose.pdf.Color.getRed());<o:p></o:p>

graph1.getShapes().add(line);<o:p></o:p>

page.getParagraphs().add(text);<o:p></o:p>

page.getParagraphs().add(graph1);<o:p></o:p>

<o:p></o:p>

doc.save(myDir + "Addline.pdf");

Best Regards,

Thank you very much.
I can able to render the line in pdf.

Hi Karthikeyan,


Thanks for the acknowledgement. We are glad to hear that your problem is resolved. Please continue using our API and in the event of any further query, please feel free to contact.

The issues you have found earlier (filed as PDFNEWJAVA-34971) have been fixed in Aspose.Pdf for Java 11.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.