Could you kindly help me on how to add a thick black line(thick black bar) in the footer of the particular page in the PDF document?
Hi Anand,
Thanks for contacting support.
In order to add a line in an existing PDF file, please try using the createLine(..)
method of the PdfContentEditor
class. You can specify any location over the PDF file where you need to draw it.
Java:
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf("example1.pdf");
Rectangle rect = new Rectangle(50, 50, 200, 200);
Color c = new Color(255, 125, 125);
int[] dashArray = { };
String[] LEArray = { };
editor.createLine(rect, "", 100, 100, 400, 100, 1, 5, "s", dashArray, LEArray, c);
editor.save("example1_Line.pdf");
Hi ,
It would be very helpful if you share exactly how to add the
line at the bottom of the page(Page end) .The line should start from
left end and ends at right most of the page .It should not start from
center or somewhere.Also if you could share the details of what are all
the various fonts that we can display to line that will also be very helpful.
Thanks
Anand
Hi Anand,
In order to add a line 20 points up from the bottom of the page, please try using the following code snippet.
com.aspose.pdf.kit.PdfContentEditor editor = new com.aspose.pdf.kit.PdfContentEditor();
editor.bindPdf("c:/pdftest/AnnotationFile.pdf");
Rectangle rect = new Rectangle(1, 20, (int)new com.aspose.pdf.kit.PdfFileInfo("c:/pdftest/AnnotationFile.pdf").getPageWidth(1), 1);
Color c = new Color(255, 125, 125);
int[] dashArray = {};
String[] LEArray = {};
// create a line starting at (X,Y) where X=1 and Y=20
editor.createLine(rect, "", 1, 20, (int)new com.aspose.pdf.kit.PdfFileInfo("c:/pdftest/AnnotationFile.pdf").getPageWidth(1), 20, 1, 1, "s", dashArray, LEArray, c);
editor.save("c:/pdftest/Line_At_Bottom.pdf");
Now concerning your requirement:
“Also if you could share the details of what are all the various fonts that we can display to line that will also be very helpful.” Can you please share some details regarding this requirement?
Please note that Aspose.Pdf.Kit for Java supports the feature to add Formatted text string with specific font. You may try using any value from FontStyle enumeration. Please take a look over the following code line.
com.aspose.pdf.kit.FormattedText logo2 = new com.aspose.pdf.kit.FormattedText("Aspose.Pdf.Kit", new Color(10, 30, 100), com.aspose.pdf.kit.FontStyle.HelveticaOblique, com.aspose.pdf.kit.EncodingType.Winansi, false, 20);
Thank you for your help on this issue.
I treid your code and it works fine.But I have some content near the footer of the PDF.Is it possible to shift the contents slightly up and add the line after that.In the screen shot attached you could see the line is merged with contents.Kindly help.
Thanks
Anand
Hi Anand,
Hi Anand,
Hi,
1. Please let me know how to increase the height of the PDF existing PDF
2. Also please let me know how to switch existing PDF from Landscape mode to ordinary mode.
Regards,
Anand
Anandkln:
- Please let me know how to increase the height of the existing PDF
Thanks for your inquiry. You can use the resizeContents
method for this purpose. The resizeContent
method of the PdfFileEditor
class allows you to resize the page contents in a PDF file. The ContentsResizeParameters
class is used to specify the parameters to be used to resize the page(s), e.g., margins in percentage or units, etc. You can resize all the pages or specify an array of pages to be resized using the resizeContents
method.
//Create PdfFileEditor Object
PdfFileEditor fileEditor = new PdfFileEditor();
//Open PDF Document
Document doc = new Document("d:\\input.pdf");
//Specify Parameter to be used for resizing
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
//left margin = 10% of page width
PdfFileEditor.ContentsResizeValue.percents(10),
//new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
null,
//right margin is 10% of page
PdfFileEditor.ContentsResizeValue.percents(10),
//top margin = 10% of height
PdfFileEditor.ContentsResizeValue.percents(10),
//new contents height is calculated automatically (similar to width)
null,
//bottom margin is 10%
PdfFileEditor.ContentsResizeValue.percents(10)
);
//Resize Page Contents
fileEditor.resizeContents(doc, new int[] { 1, 2, 3 }, parameters);
//save document into new location.
doc.save("d:\\output.pdf");
Anandkln:
2. Also please let me know how to switch existing PDF from Landscape mode to ordinary mode.
I’m afraid this feature is not supported at the moment, as rotating Page rotates contents as well. We’ve logged an enhancement request as PDFNEWNET-36011 in our issue tracking system for further investigation and resolution. We will update you as soon as it’s resolved.
Best Regards,