Free Support Forum - aspose.com

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)