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

Free Support Forum - aspose.com

Issue With PrintArea For Aspose PDF


I am facing issue with Print Area
Image is not showing in Aspose PDF when we are using the

   worksheet.PageSetup.PrintArea = "A1:K2";

Where as image is printing in the MS Excel
When commenting the code Print area , It’s printing the image in Ms Excel and PDF as well.

Sample code is here.
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

        Bitmap bitmapImage = new Bitmap(@"C:\Users\Ram.Yadav\Pictures\Saved Pictures\xyz.png");
        MemoryStream imageStream = new MemoryStream();
        bitmapImage.Save(imageStream, ImageFormat.Bmp);
        imageStream.Position = 0;

        worksheet.Cells["A1"].PutValue("Beneficial Ownership Report");

        worksheet.Cells["A2"].PutValue("Run On: " + DateTime.Now.ToString("MM/dd/yyyy"));

        worksheet.Shapes.AddPicture(3, 0, imageStream, 40, 40);
        worksheet.PageSetup.PrintArea = "A1:K2";
        var guidId = Guid.NewGuid();
        workbook.Save("C://Users/Ram.Yadav/Downloads/AsposePDF" + guidId + ".pdf");

Using Aspose.PDF version(18.12.0) and Aspose.Cell version(18.12.0).

Please help why Print area is not working for the image in PDF?



Thanks for contacting support.

Can you please share source files along with generated result to further investigate this issue on our end. Also before sharing requested files please try to use Aspose.PDF latest version 20.5 on your end.


I have attached the source file, result pdf (with and without print area).
Generated with Aspose.PDF version 20.5 getting same issue with the latest version.
Sample code is same as above in C#.

AsposePDFa563ea44-3b11-44e5-940b-137b784d4455WithPrintArea.pdf (22.2 KB)
AsposePDF6dd7eb04-5095-429d-95f9-e8894aa65059WithoutPrintArea.pdf (27.9 KB)
xyz.png (3.6 KB)


I have worked with source code and sample file shared by you and I think this issue is related to Aspose.Cells. Can you please confirm how you are using Aspose.PDF in this issue.


Actually i am using both Aspose.Cells and Aspose.PDF. When i was previewing this with MS Excel, it works fine for me that’s why i was thought that problem will be cause of Aspose.PDF.

But, if the issue is related to Aspose.Cells then Please suggest how do i resolved this.

Also tried with the Aspose.Cells version (20.4), But still facing the same issue.

You are setting the print area as A1:K2 but the image is not in this area. So it is expected behavior of the API. If you want to print the image in output PDF and XLSX file then set print area as under:

worksheet.PageSetup.PrintArea = "A1:C8";

Let us know your feedback.

Thanks @ahsaniqbalsidiqui.

In my application the image size is not fixed as in the sample code. So how can i resolves it for a variable size image because the image is dynamically generated in my Real Time Project on the basis of record.


Please note, Aspose.Cells (or even MS Excel itself) does render Excel to PDF file based on what is shown in the print preview (when taking for the worksheet in Ms Excel manually). So, you may save the final Excel file and take the print preview and you will see the image is also not shown in print preview.

For you needs, it is better you do not specify the print area in code. If you still want to specify the printable area (in accordance with image size), you may refer to the following sample code and then add/embed it to your code accordingly for your needs:
Sample code:

Cells cells = worksheet.Cells;

            int maxRow = cells.MaxDataRow;
            int maxColumn = cells.MaxDataColumn;

Aspose.Cells.Drawing.Picture  shape = (Picture)worksheet.Shapes.AddPicture(3, 0, imageStream, 40, 40);
                int endRow = shape.LowerRightRow;
                int endColumn = shape.LowerRightColumn;
                maxRow = endRow;
                maxColumn = endColumn;

            worksheet.PageSetup.PrintArea = "A1:" + CellsHelper.CellIndexToName(maxRow, maxColumn);

Hope, this helps a bit.