PageInfo.Landscape Property not working

Hi team,

I am trying to add a image stamp at every corners using below code. but the pdfDocument.Pages[Page_counter].PageInfo.IsLandscape is always returns false. I do attach both the affected and images used for stamp.

Aspose_tst_Source.zip (166.5 KB)

I do also tried solution in the below link, but the document has both landscape and portrait pages, it dose not gives the exact solution we expect.

                        var path = directoryName.Replace("file:\\", "");
                        string chartLoc = path + "\\left.jpg";
                        string chartLoc1 = path + "\\right.jpg";
                        string chartLoc2 = path + "\\top.jpg";
                        string chartLoc3 = path + "\\bottom.jpg";

                        ImageStamp imgStamp_left = new ImageStamp(chartLoc);
                        ImageStamp imgStamp_right = new ImageStamp(chartLoc1);
                        ImageStamp imgStamp_top = new ImageStamp(chartLoc2);
                        ImageStamp imgStamp_bottom = new ImageStamp(chartLoc3);

                        imgStamp_bottom.Background = false;
                        imgStamp_top.Background = false;
                        imgStamp_right.Background = false;
                        imgStamp_left.Background = false;

                        for (int Page_counter = 1; Page_counter <= pdfDocument.Pages.Count; Page_counter++)
                        {
                            // adding Image watermark to all pages of PDF file

                            if (pdfDocument.Pages[Page_counter].PageInfo.IsLandscape)
                            {
                                imgStamp_bottom.Height = 30;
                                imgStamp_bottom.XIndent = 0;
                                imgStamp_bottom.VerticalAlignment = VerticalAlignment.Bottom;

                                imgStamp_top.Height = 30;
                                imgStamp_top.XIndent = 0;
                                imgStamp_top.VerticalAlignment = VerticalAlignment.Top;

                                imgStamp_left.Width = 40;
                                imgStamp_left.XIndent = 0;
                                imgStamp_left.YIndent = 30;
                                imgStamp_left.VerticalAlignment = VerticalAlignment.Top;

                                imgStamp_right.Width = 40;
                                imgStamp_right.XIndent = 800;
                                imgStamp_right.YIndent = 30;
                                imgStamp_right.VerticalAlignment = VerticalAlignment.Top;
                            }
                            else
                            {
                                imgStamp_bottom.Height = 30;
                                imgStamp_bottom.XIndent = 0;
                                imgStamp_bottom.VerticalAlignment = VerticalAlignment.Bottom;

                                imgStamp_top.Height = 30;
                                imgStamp_top.XIndent = 0;
                                imgStamp_top.VerticalAlignment = VerticalAlignment.Top;

                                imgStamp_left.Width = 40;
                                imgStamp_left.XIndent = 0;
                                imgStamp_left.VerticalAlignment = VerticalAlignment.Top;

                                imgStamp_right.XIndent = 573;
                                imgStamp_right.Width = 40;
                                imgStamp_right.VerticalAlignment = VerticalAlignment.Top;
                            }

                            pdfDocument.Pages[Page_counter].AddStamp(imgStamp_bottom);
                            pdfDocument.Pages[Page_counter].AddStamp(imgStamp_top);
                            pdfDocument.Pages[Page_counter].AddStamp(imgStamp_right);
                            pdfDocument.Pages[Page_counter].AddStamp(imgStamp_left);
                        }
                        pdfDocument.Save(outputFile);

Kindly, help this issues as soon as possible.

Thanks,
Riyas

@mohamedriyas

We were able to reproduce the issue using Aspose.PDF for .NET 20.9 in our environment that API was not reading Landscape orientation correctly. Hence, we have logged an issue as PDFNET-48822 in our issue tracking system for the sake of correction. We will further look into its details and keep you informed about its rectification status. Please give us some time.

As an alternative approach, you can specify horizontal alignment of the image stamp in order to render it at right corner regardless page orientation. Please check below code snippet and attached output:

Document pdfDocument = new Document(dataDir + "Aspose_tst_Source.pdf");

ImageStamp imgStamp_left = new ImageStamp(dataDir + "left.jpg");
ImageStamp imgStamp_right = new ImageStamp(dataDir + "right.jpg");
ImageStamp imgStamp_top = new ImageStamp(dataDir + "Top.jpg");
ImageStamp imgStamp_bottom = new ImageStamp(dataDir + "bottom.jpg");

imgStamp_bottom.Background = false;
imgStamp_top.Background = false;
imgStamp_right.Background = false;
imgStamp_left.Background = false;

for (int Page_counter = 1; Page_counter <= pdfDocument.Pages.Count; Page_counter++)
{
 imgStamp_bottom.Height = 30;
 imgStamp_bottom.XIndent = 0;
 imgStamp_bottom.VerticalAlignment = VerticalAlignment.Bottom;

 imgStamp_top.Height = 30;
 imgStamp_top.XIndent = 0;
 imgStamp_top.VerticalAlignment = VerticalAlignment.Top;

 imgStamp_left.Width = 40;
 imgStamp_left.XIndent = 0;
 imgStamp_left.VerticalAlignment = VerticalAlignment.Top;

 imgStamp_right.Width = 40;
 imgStamp_right.HorizontalAlignment = HorizontalAlignment.Right;
 imgStamp_right.VerticalAlignment = VerticalAlignment.Top;

 pdfDocument.Pages[Page_counter].AddStamp(imgStamp_bottom);
 pdfDocument.Pages[Page_counter].AddStamp(imgStamp_top);
 pdfDocument.Pages[Page_counter].AddStamp(imgStamp_right);
 pdfDocument.Pages[Page_counter].AddStamp(imgStamp_left);
}
pdfDocument.Save(dataDir + "output.pdf");

output.pdf (72.3 KB)

hi @asad.ali,

the above discussed issue occurs in conversion of word to PDF using Aspose.Word.(i.e) While converting a document with different page orientation to PDF, Aspose.Word applies Oreientation as Portrait for all Pages.[section.PageSetup.Orientation is Portrait always]. You can use the same document attached above.

Kindly, do the needful asap and give us the solution.

Regards,
Riyas

@mohamedriyas

We are checking the issue from the perspective of Aspose.Words and will share our feedback with you shortly.

@mohamedriyas

We have tested the scenario using the latest version of Aspose.Words for .NET 20.10 and have not found the shared issue. So, please use Aspose.Words for .NET 20.10. We have attached the output PDF with this post for your kind reference.
20.10.pdf (63.6 KB)

@tahir.manzoor

Can I have the update on the above issue PDFNET-48822?

Regards,
Riyas

@mohamedriyas

We are afraid that earlier logged ticket is not yet resolved. As soon as its investigation is completed and we have some news about its fix ETA, we will share with you in this forum thread. Please spare us some time.

We apologize for the inconvenience.

@asad.ali

Can I have an Exact ETA?

Regards,
Riyas

@mohamedriyas

We regret that we cannot share any reliable ETA at the moment as the ticket is not yet investigated. As soon as the ticket is fully analyzed, we will be in a position to share such updates with you. We have recorded your concerns and will surely consider them during the issue investigation. Please give us some time.

We apologize for the inconvenience.

hi @asad.ali,

Can I have any update?
Regards,
Riyas

@mohamedriyas

We are afraid that the earlier logged ticket could not get resolved due to other issues logged prior to it. However, we will surely inform you as soon as we have certain updates regarding its resoltuion.

We apologize for your inconvenience.

hi @asad.ali,

We do also checked the issue from 12.11 but still the issue exists. When will we expect a permanent solution for this issue?

Regards,
Riyas

@mohamedriyas

At the moment, the ticket resolution is pending due to other issues in the queue logged prior to it. However, we have recorded your concerns and as soon as we have certain news about its fix ETA, we will share with you. We highly appreciate your patience and comprehension in this regard.

We apologize for your inconvenience.

@mohamedriyas

PageInfo.IsLandscape is used when generating (creating) PDF documents and is not filled in when opening a document.

In your case, you should use Page.MediaBox- below is the code:

var pdfDocument = new Document(dataDir + "Aspose_tst_Source.pdf");

var imgStamp_left = new ImageStamp(dataDir + "left.jpg");
var imgStamp_right = new ImageStamp(dataDir + "right.jpg");
var imgStamp_top = new ImageStamp(dataDir + "Top.jpg");
var imgStamp_bottom = new ImageStamp(dataDir + "bottom.jpg");

imgStamp_bottom.Background = false;
imgStamp_top.Background = false;
imgStamp_right.Background = false;
imgStamp_left.Background = false;

for (int Page_counter = 1; Page_counter <= pdfDocument.Pages.Count; Page_counter++)
{
    // adding Image watermark to all pages of PDF file

    Rectangle pageMediaBox = pdfDocument.Pages[Page_counter].MediaBox;

    imgStamp_bottom.Height = 30;
    imgStamp_bottom.XIndent = 0;
    imgStamp_bottom.VerticalAlignment = VerticalAlignment.Bottom;

    imgStamp_top.Height = 30;
    imgStamp_top.XIndent = 0;
    imgStamp_top.VerticalAlignment = VerticalAlignment.Top;

    imgStamp_left.Width = 40;
    imgStamp_left.XIndent = 0;
    imgStamp_left.YIndent = 30;
    imgStamp_left.VerticalAlignment = VerticalAlignment.Top;

    imgStamp_right.Width = 40;
    imgStamp_right.XIndent = pageMediaBox.URX - imgStamp_right.Width; // Pay attention to this line.
    imgStamp_right.YIndent = 30;
    imgStamp_right.VerticalAlignment = VerticalAlignment.Top;

    pdfDocument.Pages[Page_counter].AddStamp(imgStamp_bottom);
    pdfDocument.Pages[Page_counter].AddStamp(imgStamp_top);
    pdfDocument.Pages[Page_counter].AddStamp(imgStamp_right);
    pdfDocument.Pages[Page_counter].AddStamp(imgStamp_left);
}
pdfDocument.Save(dataDir + "output.pdf");