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

Free Support Forum - aspose.com

Add headers and footers in the document

Hi,

How can we add custom headers and footers to the pdf document?

And how to create a bold text using TextFragment?

Thanks

Mamatha

Hi Mamatha,


Thanks for your inquriy. Please check following code snippet to add header/footer into a PDF document and bold text using TextFragment, it will help you to accomplish the task.

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

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

TextFragment boldtext= new TextFragment("bold text");

boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);

page.getParagraphs().add(boldtext);

com.aspose.pdf.Table table = new com.aspose.pdf.Table();

table.setColumnWidths("50 100");

for (int i = 1; i <= 200; i++)

{

com.aspose.pdf.Row row = table.getRows().add();

row.setFixedRowHeight(15);

com.aspose.pdf.Cell cell1 = row.getCells().add();

cell1.getParagraphs().add(new TextFragment("Content 1 "+i));

com.aspose.pdf.Cell cell2 = row.getCells().add();

cell2.getParagraphs().add(new TextFragment("Content 2 "+i));

}

page.getParagraphs().add(table);

//header table

com.aspose.pdf.Table table1 = new com.aspose.pdf.Table();

table1.setColumnWidths("150 150");

com.aspose.pdf.Row row1 = table1.getRows().add();

//add table cells

row1.getCells().add("Column 1");

row1.getCells().add("Column 2");

row1.setBorder(new com.aspose.pdf.BorderInfo(BorderSide.Bottom, .5f, com.aspose.pdf.Color.getLightGray()));

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

header.getParagraphs().add(table1);

page.setHeader(header);

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


Please feel free to contact us for any further assistance.

Best Regards,

Hi,

Thanks for the sample program. Bold text and header worked. But when I set header top margin or table top margin is set then header is overlapping with the content. Can you please look into this.

header.getMargin().setTop(72);

One more thing, when I tried to add image into table cell Acrobat reader complains.

Image img = new com.aspose.pdf.Image();
img.setFile("d:/pdf/logo.png");
img.setFixHeight(85);
img.setFixWidth(100);
row1.getCells().add().getParagraphs().add(img);

What is the right way for adding image into a table cell?

Thanks

Mamatha

mamatha:
Thanks for the sample program. Bold text and header worked. But when I set header top margin or table top margin is set then header is overlapping with the content. Can you please look into this.

header.getMargin().setTop(72);

Hi Mamatha,

Thanks
for using our API’s.


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-35390 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.

mamatha:

One more thing, when I tried to add image into table cell Acrobat reader complains.

Image img = new com.aspose.pdf.Image();
img.setFile(“d:/pdf/logo.png”);
img.setFixHeight(85);
img.setFixWidth(100);
row1.getCells().add().getParagraphs().add(img);

What is the right way for adding image into a table cell?

Hi Mamatha,


Thanks for your patience.


I have tested the above stated scenario and I am unable to notice any issue. Can you please share which version of API which you are using.

[C#]

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

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

TextFragment boldtext= new TextFragment(“bold
text”
);<o:p></o:p>

boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);<o:p></o:p>

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

com.aspose.pdf.Table table = new
com.aspose.pdf.Table();<o:p></o:p>

table.setColumnWidths(“50 100”);<o:p></o:p>

for (int i = 1; i <= 200;
i++)<o:p></o:p>

{<o:p></o:p>

com.aspose.pdf.Row row =
table.getRows().add();<o:p></o:p>

row.setFixedRowHeight(15);<o:p></o:p>

com.aspose.pdf.Cell cell1 =
row.getCells().add();<o:p></o:p>

cell1.getParagraphs().add(new TextFragment("Content 1
"
+i));<o:p></o:p>

com.aspose.pdf.Cell cell2 =
row.getCells().add();<o:p></o:p>

cell2.getParagraphs().add(new TextFragment("Content 2
"
+i));<o:p></o:p>

}<o:p></o:p>

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

//header table<o:p></o:p>

com.aspose.pdf.Table table1 = new
com.aspose.pdf.Table();<o:p></o:p>

table1.setColumnWidths(“150 150”);<o:p></o:p>

com.aspose.pdf.Row row1 =
table1.getRows().add();<o:p></o:p>

//add table cells<o:p></o:p>

// row1.getCells().add(“Column
1”);
<o:p></o:p>

com.aspose.pdf.Image img = new com.aspose.pdf.Image();<o:p></o:p>

img.setFile(“c:/pdftest/12-15-2015+11-07-36+AM.jpg”);<o:p></o:p>

img.setFixHeight(85);<o:p></o:p>

img.setFixWidth(100);<o:p></o:p>

row1.getCells().add().getParagraphs().add(img);<o:p></o:p>

row1.getCells().add(“Column
2”
);<o:p></o:p>

row1.setBorder(new
com.aspose.pdf.BorderInfo(BorderSide.Bottom, .5f, com.aspose.pdf.Color.getLightGray()));<o:p></o:p>

com.aspose.pdf.HeaderFooter header = new
com.aspose.pdf.HeaderFooter();<o:p></o:p>

header.getParagraphs().add(table1);<o:p></o:p>

header.getMargin().setTop(72);<o:p></o:p>

page.setHeader(header);<o:p></o:p>

doc.save(“c:/pdftest/HeaderFooter_with_Margin.pdf”);

Hi,

I am using Aspose-pdf-10.9 version for java. And here is the sample code.

com.aspose.pdf.Table table1 = new com.aspose.pdf.Table();
table1.setColumnWidths("4.0inch 2.5inch");
com.aspose.pdf.Row row1 = table1.getRows().add();
row1.getCells().add("First image);

Image img = new com.aspose.pdf.Image();
img.setFile("d:/pdf/logo.png");
img.setFixHeight(85);
img.setFixWidth(100);
row1.getCells().add(img);

com.aspose.pdf.Row row2 = table1.getRows().add();
row2.getCells().add("Second image);

img = new com.aspose.pdf.Image();
img.setFile("d:/pdf/logo.png");
img.setFixHeight(85);
img.setFixWidth(100);
row2.getCells().add(img);

Thanks

Mamatha

Hi Mamatha,


Thanks for sharing the details.

I have tested the scenario using Aspose.Pdf for Java 11.0.0 in Eclipse Juno project running over Windows 7 (x64) with JDK 1.7 and I am unable to notice any issue when viewing resultant file in Adobe Reader 11.0.2. For your reference, I have also attached the output generated over my end.

[Java]

com.aspose.pdf.Document doc = new
com.aspose.pdf.Document();<o:p></o:p>

doc.getPages().add();

com.aspose.pdf.Table table1 = new com.aspose.pdf.Table();

table1.setColumnWidths("4.0inch 2.5inch");

com.aspose.pdf.Row row1 = table1.getRows().add();

row1.getCells().add("First image");

com.aspose.pdf.Image img = new com.aspose.pdf.Image();

img.setFile("c:/pdftest/logoSpin.png");

img.setFixHeight(85);

img.setFixWidth(100);

row1.getCells().add();

row1.getCells().get_Item(1).getParagraphs().add(img);

com.aspose.pdf.Row row2 = table1.getRows().add();

row2.getCells().add("Second image");

img = new com.aspose.pdf.Image();

img.setFile("c:/pdftest/logoSpin.png");

img.setFixHeight(85);

img.setFixWidth(100);

row2.getCells().add();

row2.getCells().get_Item(1).getParagraphs().add(img);

doc.getPages().get_Item(1).getParagraphs().add(table1);

doc.save(“c:/pdftest/ImageInTableIssue.pdf”);

Nayyer,

Thank you. That did work. Somehow I am still getting error when trying to insert image. I will look into it. I have noticed that free trial version message on the top of the document looks messed up. I have attached screen shot of it. Do you know when do we encounter that issue. I tried generating other reports and they seem to be fine. Is it based on the content of the document?

Thanks

Mamatha

Nayyer,

I was able to reproduce the image issue. I have included image and the sample program. Can you please look into it.

Thanks

Mamatha

Hi Mamatha,


Thanks for sharing the resource files.

We are working on testing the scenario using these documents and will keep you posted with our findings.
mamatha:
I was able to reproduce the image issue. I have included image and the sample program. Can you please look into it.
Hi Mamatha,

I have tested the scenario and have managed to reproduce the problem that when viewing PDF document with image inside table cells is showing an error message. For the sake of correction, I have logged this problem as PDFNEWJAVA-35404. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.
mamatha:
I have noticed that free trial version message on the top of the document looks messed up. I have attached screen shot of it. Do you know when do we encounter that issue. I tried generating other reports and they seem to be fine. Is it based on the content of the document?
Hi Mamatha,

I have tested the scenario using earlier shared code snippet and have observed that evaluation watermark gets corrupted when using API in trial mode. Frankly speaking, I cannot share the explicit scenarios when watermark gets corrupted but for the sake of correction, I have logged this problem as PDFNEWJAVA-35405 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,

Is there any update on this?

Thanks

Mamatha

Hi Mamatha,


Thanks for your patience.

As we recently have noticed these issues, so they are pending for review. However the product team will start investigating these issues as per their schedule and as soon as we have some definite updates, we will let you know.

Please be patient and spare us little time.

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


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

The issues you have found earlier (filed as PDFJAVA-35405) have been fixed in Aspose.Pdf for Java 17.4.


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