Header with underline

We are evaluating your product -- html to pdf conversion and we have the following problems

1) creating header followed by line( I am able to create text header but not what we are looking for).

Ex: Header

____________________________________________________________________________

The above line should be just below the text with 0 margin(horizontal gap).

2) If you could provide me with a Footnotes example in java api that would be great. Also how to make sure

that the footnote pointers and actual footnote text appear on the same page.

Regards,

Raghavendra

Hi Raghavendra,

Thanks for your inquiry.

raghureddyd:

We are evaluating your product -- html to pdf conversion and we have the following problems

1) creating header followed by line( I am able to create text header but not what we are looking for).

Ex: Header

____________________________________________________________________________

The above line should be just below the text with 0 margin(horizontal gap).

Document doc = new Document();

com.aspose.pdf.Page page = doc.getPages().add();

com.aspose.pdf.HeaderFooter header = new com.aspose.pdf.HeaderFooter();

TextFragment text = new TextFragment("test text with line");

com.aspose.pdf.drawing.Graph graph1 = new com.aspose.pdf.drawing.Graph((float)page.getRect().getWidth(), 2);

// Add the line to paraphraphs collection of section object

//specify the coordinates for the line

float[] posArr = new float[] { 0, 2, (float)page.getRect().getWidth(), 2 };

com.aspose.pdf.drawing.Line l1 = new com.aspose.pdf.drawing.Line(posArr);

graph1.getShapes().add(l1);

header.getMargin().setLeft(0);

header.getMargin().setRight(0);

header.getParagraphs().add(text);

header.getParagraphs().add(graph1);

page.setHeader(header);

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


Please feel free to contact us for any further assistance.


Best Regards,

raghureddyd:


2) If you could provide me with a Footnotes example in java api that would be great. Also how to make sure

that the footnote pointers and actual footnote text appear on the same page.



Hi Raghavendra,

Please check following sample code for adding FootNotes. Moreover, FootNotes will appear on the page you linked to.

// create Document instance<o:p></o:p>

Document doc = new Document();

// add page to pages collection of PDF

Page page = doc.getPages().add();

// create GraphInfo object

com.aspose.pdf.GraphInfo graph = new com.aspose.pdf.GraphInfo();

// set line width as 2

graph.setLineWidth(2);

// set the color for graph object

graph.setColor(com.aspose.pdf.Color.getRed());

// set dash array value as 3

graph.setDashArray(new int[] { 3 });

// set dash phase value as 1

graph.setDashPhase(1);

// set footnote line style for page as graph

page.setNoteLineStyle(graph);

// create TextFragment instance

TextFragment text = new TextFragment("Hello World");

// set FootNote value for TextFragment

text.setFootNote(new com.aspose.pdf.Note("foot note for test text 1"));

// add TextFragment to paragraphs collection of first page of document

page.getParagraphs().add(text);

// create second TextFragment

text = new TextFragment("Aspose.Pdf for .NET");

// set FootNote for second text fragment

text.setFootNote(new com.aspose.pdf.Note("foot note for test text 2"));

// add second text fragment to paragraphs collection of PDF file

page.getParagraphs().add(text);

// save the PDF file

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


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,

Thank you for your response! The examples are working but I would like to know if there is anyway to mention the header with underline in html file so that it appears on all pages by default. As our aim is to generate pdf from html file which is generated after applying transformation on xml response.

The same goes with Foot Notes. Because we would have no idea about the location(page and position) to place them(foot notes) from java code after the pdf is generated from html file as mentioned above.

Regards,

Raghavendra

Hi Raghavendra,


Thanks for your feedback.

raghureddyd:

Thank you for your response! The examples are working but I would like to know if there is anyway to mention the header with underline in html file so that it appears on all pages by default. As our aim is to generate pdf from html file which is generated after applying transformation on xml response.


I am afraid there is no option to set Header for all pages at once. you can save resultant document of HTML to PDF conversion into stream and then iterate through the pages and set required header as following.

ByteArrayOutputStream output = new
ByteArrayOutputStream();
<o:p></o:p>

Document doc = new Document("input.html", new HtmlLoadOptions());

doc.save(output);

doc= new Document(new ByteArrayInputStream(output.toByteArray()));

com.aspose.pdf.Page page = doc.getPages().add();

com.aspose.pdf.HeaderFooter header = new com.aspose.pdf.HeaderFooter();

TextFragment text = new TextFragment("test text with line");

com.aspose.pdf.drawing.Graph graph1 = new com.aspose.pdf.drawing.Graph((float)page.getRect().getWidth(), 2);

// Add the line to paraphraphs collection of section object

//specify the coordinates for the line

float[] posArr = new float[] { 0, 2, (float)page.getRect().getWidth(), 2 };

com.aspose.pdf.drawing.Line l1 = new com.aspose.pdf.drawing.Line(posArr);

graph1.getShapes().add(l1);

header.getMargin().setLeft(0);

header.getMargin().setRight(0);

header.getParagraphs().add(text);

header.getParagraphs().add(graph1);

for (int pageCount = 1; pageCount <= doc.getPages().size(); pageCount++)

{

doc.getPages().get_Item(pageCount).setHeader(header);

}

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



raghureddyd:

The same goes with Foot Notes. Because we would have no idea about the location(page and position) to place them(foot notes) from java code after the pdf is generated from html file as mentioned above.


You can find text using TextFragmentAbsorber and get TextFragmet page number to create footnote on respective page.

Best Regards,