PDF Document conversion for adding pagination in c# is coming at the top of page with inverted one
image.png (6.7 KB)
It seems you are experiencing an issue with pagination when converting PDF documents using C#. If the pagination is appearing at the top of the page and is inverted, there are a few things you can check and adjust in your code.
-
Check the Positioning of the Pagination: Ensure that you are setting the position of the pagination correctly. You may want to specify the coordinates where the pagination should appear. For example, if you want it at the bottom center of the page, you can set the coordinates accordingly.
-
Adjust the Text Direction: If the pagination text is inverted, it might be due to the text direction settings. Make sure that you are using the correct text direction for your pagination. You can set the text direction to be left-to-right if it is currently set to right-to-left.
-
Use the Correct Font and Size: Sometimes, the font or size can affect how the text is rendered. Ensure that you are using a compatible font and an appropriate size for the pagination text.
Here is a simple example of how you might add pagination to a PDF document using Aspose.PDF in C#:
using Aspose.Pdf;
using Aspose.Pdf.Text;
// Load your PDF document
Document pdfDocument = new Document("input.pdf");
// Loop through each page to add pagination
for (int pageIndex = 1; pageIndex <= pdfDocument.Pages.Count; pageIndex++)
{
// Create a TextStamp for the pagination
TextStamp textStamp = new TextStamp($"Page {pageIndex} of {pdfDocument.Pages.Count}")
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
// Set the position as needed
XIndent = 0,
YIndent = 20,
TextState = new TextState
{
Font = FontRepository.FindFont("Arial"),
FontSize = 12,
ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black)
}
};
// Add the stamp to the page
pdfDocument.Pages[pageIndex].AddStamp(textStamp);
}
// Save the updated document
pdfDocument.Save("output.pdf");
Make sure to adjust the XIndent
and YIndent
properties to position the pagination correctly on the page. If you continue to face issues, consider checking the Aspose documentation for more detailed guidance on text positioning and formatting during PDF conversions.
If you need further assistance, feel free to ask!
we are getting the pagination details but it was coming as an inverted one as in image.
image.png (6.7 KB)
So verify the above image and do the needful.
Are you adding the page numbers using TextStamp Class? Please make sure that pages of the PDF are not rotated to certain angles. Please share your sample source PDF and the sample code snippet for our reference so that we can test the scenario in our environment and address it accordingly.
Please find the used code below
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(path);
for (int pageIndex = 1; pageIndex <= doc.Pages.Count; pageIndex++)
{
// Create a TextStamp for the pagination
TextStamp textStamp = new TextStamp("Page " + pageIndex + " of " + doc.Pages.Count)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
// Set the position as needed
XIndent = 0,
YIndent = 20,
ReplacementFont = Aspose.Pdf.Text.FontRepository.FindFont(“Arial”),
TreatYIndentAsBaseLine = true
};
textStamp.TextState.FontSize = 14F;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
textStamp.RotateAngle = 360;
textStamp.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;
doc.Pages[pageIndex].AddStamp(textStamp);
}
// Save the PDF
doc.Save(path);
SamplePDFDocs.pdf (256.1 KB)
Looks like the inverted stamp is already a part of image that is present at the last page of the PDF document. The TextStamp being added by the API is rendering at the bottom of each page normally. Please check the attached screenshot for your kind reference.
image.png (53.7 KB)
Hi Asad,
The inverted stamp is not a part of image that is present at the last page of the PDF document already, we are getting correctly when we use Aspose online pdf tool to add the page number for the above pdf without the pagination which was previously added
The issue was facing while adding using the Textstamp, So help us on this to resolve it ASAP.
Can you please then share source PDF file that has not inverted stamp already? Because the document you shared previously had inverted stamp at the top of the last page in PDF document. While opening it in Adobe Reader and selecting it, it is being selected with the entire image.
Hi Asad Ali,
Please find the attached source PDF file that has no inverted stamp in it.
RTM-ccvscheck-2024-0001.01-1 (19).pdf (31.3 KB)
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-59475
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.