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

Free Support Forum - aspose.com

Aspose.pdf.pageInfo incorrect data

I'm trying to retrieve things like height, width, isLandscape, and rotation but it seems that when I load a document all these values are at a set value. No matter what PDF I load, it seems that pageinfo shows the height as 842 and the width as 595. I believe this is in points which would convert to an A4 size piece of paper. isLandscape is always false and rotation is always none.

These data need to add a watermark on the first page to specific coordinates.


Document pdfDocument = new Document(@"D:\PDF's\input.pdf");
Artifact artifact = new Artifact(Artifact.ArtifactType.Pagination, Artifact.ArtifactSubtype.Watermark);
FormattedText ft = new FormattedText("E-2015-001240-DIPON", System.Drawing.Color.LightGray, "Helvetica-Bold", EncodingType.Winansi, false, 16);
artifact.SetText(ft);
artifact.Position = new Aspose.Pdf.Point(40, pdfDocument.PageInfo.Height - 40);
artifact.Rotation = 0;
pdfDocument.Pages[1].Artifacts.Add(artifact);
pdfDocument.Save(@"D:\PDF's\output.pdf");

But since the height values ​​of different PDF are different, the watermark has a variable position in the PDF documents.

Thank you for any help you can provide us.

Jonthan

Hi Jonothan,


Thanks for your inquiry. Please note you PageInfo property is only used for new PDF document. To get the page width and height you need to get Width and Height property of Rect object of Page. To know the orientation you need to get page dimensions and compare width and height. And for rotation you should check Rotate value of Page object. I have amend your code a bit as following code, hopefully it will help you to accomplish the requirements. If issue persist then please share your sample document here, so we will look into it and guide you accordingly.

Document pdfDocument = new Document(@“D:\PDF’s\input.pdf”);<o:p></o:p>

Artifact artifact = new Artifact(Artifact.ArtifactType.Pagination, Artifact.ArtifactSubtype.Watermark);

FormattedText ft = new FormattedText("E-2015-001240-DIPON", System.Drawing.Color.LightGray, "Helvetica-Bold", EncodingType.Winansi, false, 16);

artifact.SetText(ft);

artifact.Position = new Aspose.Pdf.Point(40, pdfDocument.Pages[1].Rect.Height - 40);

artifact.Rotation = 0;

pdfDocument.Pages[1].Artifacts.Add(artifact);

pdfDocument.Save(@"D:\PDF's\output.pdf");

Please feel free to contact us for any further assistance.

Best Regards,