PDF page rotation causes incorrect coordinate positioning

I have a pdf. I used Aspose.PDF to view the page information and found that the pages of the document were rotated. This causes the page I see to be vertical, but the width and height obtained by page.Rect are horizontal.

	Document document = new Document(@"C:\Users\54390\Downloads\91f0e8ebeb4343fe8df7e95718a19cfa.pdf");
	foreach (var page in document.Pages)
	{
		Console.WriteLine($"Rotate:{page.Rotate};Width:{page.Rect.Width};Height:{page.Rect.Height}");
	}

How can I initialize the Rotate property of the page to Rotation.None, but still keep the page in vertical layout and keep the width and height attributes obtained by page.Rect consistent with the actual page width and height?

demo file

11111-91f0e8ebeb4343fe8df7e95718a19cfa.pdf (7.4 KB)

@sullivan

In order to get the true height and width of the Page with respect to the rotation, you need to use page.GetPageRect(true).Width and page.GetPageRect(true).Height properties. Please let us know if it resolves your issue.

@asad.ali
There is another problem. If the page is rotated, when I try to use the WatermarkArtifact class to add a watermark to the page and specify the Position, the watermark position is not as expected.

void Main()
{
	//Page Rotate is Rotation.on270 or Rotation.on90, Position of watermark is abnormal.
	AddWatermark(@"C:\Users\54390\Downloads\RotateNone.pdf", @"C:\Users\54390\Downloads\output_normal.pdf");
	//Page Rotate is Rotation.None,  Position of watermark is abnormal.
	AddWatermark(@"C:\Users\54390\Downloads\Rotate270.pdf", @"C:\Users\54390\Downloads\output1_abnormal.pdf");
}

private static void AddWatermark(string filePath, string savePath)
{
	var doc = new Aspose.Pdf.Document(filePath);
	foreach (var page in doc.Pages)
	{
		page.Rotate.Dump();
		var formatText = new FormattedText("ABCDEFGHIGK", System.Drawing.Color.Red, "Arial", EncodingType.Identity_v, true, 50);
		var artifact = new WatermarkArtifact();
		artifact.SetText(formatText);
		artifact.IsBackground = false;
		// The position here should be near the bottom left of the page.
		artifact.Position = new Aspose.Pdf.Point(50, 50);
		artifact.Rotation = 0;
		page.Artifacts.Add(artifact);
	}
	doc.Save(savePath);
}

demo file

RotateNone.pdf (70.2 KB)
Rotate270.pdf (7.4 KB)

@sullivan

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-56031

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.

The issues you have found earlier (filed as PDFNET-56031) have been fixed in Aspose.PDF for .NET 24.3.

@aspose.notifier @asad.ali

I updated to version 24.3, but found a serious bug.

After adding an Artifact object to the Page and then get the Artifact, I found that its Rectangle property became null.

I tried version 24.2 and there is no such problem.

Sample Code

void Main()
{
	var doc = new Aspose.Pdf.Document();
	doc.Pages.Add();

	var page = doc.Pages[1];
	page.Artifacts.Add(createArtifact());

	var artifact = doc.Pages[1].Artifacts[1];
	//artifact.Rectangle is null
	Console.WriteLine(artifact.Rectangle);
	//throw NullReferenceException
	var watermarkWidth = artifact.Rectangle.Width;
	var watermarkHeight = artifact.Rectangle.Height;
}

private WatermarkArtifact createArtifact()
{
	var formatText = new FormattedText("ABCDEFGHIGK", System.Drawing.Color.Red, "Arial", EncodingType.Identity_v, true, 50);
	var artifact = new WatermarkArtifact();
	artifact.SetText(formatText);
	artifact.Rotation = 0;
	artifact.Opacity = 1;
	artifact.IsBackground = false;
	return artifact;
}

Screenshot

20240316091146.jpg (82.7 KB)

@sullivan

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-56809

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.

@asad.ali
Does this bug need to be handled with the highest priority because it will prevent many users from upgrading to version 24.3?

@sullivan

The ticket is logged with a medium priority because of the free support model. However, we will surely consider your concerns and severity of the ticket during investigation. We will let you know as soon as it is resolved. We apologize for the inconvenience.

The issues you have found earlier (filed as PDFNET-56809) have been fixed in Aspose.PDF for .NET 24.4.