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

Free Support Forum - aspose.com

Returning Magnification as null for some of the PDF files

I am using Aspose pdf dll to get the details of Magnification of a pdf but for some of the pdf it is returning null

Document doc = new Document(“source.pdf”);

doc.OpenAction is null due to this I am not able to get the actual Magnification of a pdf. Tested pdf document has the magnification set to default.

Please do find the attached file.ema-cover.pdf (48.3 KB)

@sidcode

Could you please use the following code example to achieve your requirement? Hope this helps you.

Document doc = new Document(MyDir + "ema-cover.pdf");
double zoom;
GoToAction action;
if (doc.OpenAction == null)
{
    //Document has no action, magnification is null

    //Create new GoToAction
    action = new GoToAction(new XYZExplicitDestination(1, 0, doc.Pages[1].PageInfo.Height, 2));
    doc.OpenAction = action;
    zoom = (action.Destination as XYZExplicitDestination).Zoom;
}
else
{
    action = doc.OpenAction as GoToAction;
    if (action.Destination is XYZExplicitDestination)
    {
        zoom = ((XYZExplicitDestination)action.Destination).Zoom;
    }
}

Hi @tahir.manzoor,
According your solution, you are just creating new object as

action = new GoToAction(new XYZExplicitDestination(1, 0, doc.Pages[1].PageInfo.Height, 2));

in this case what ever values you give on Zoom values at fourth parameter it returns the same. But I want the original zoom value of the document.

Details:
When we try to retrieve document magnification, we first try to get the openAction of a document using below line of code.

GoToAction action = (GoToAction)pdfDoc.OpenAction;

When the action is retrieved then the document magnification value is returned correctly.

When the action returns null then we tried to get action by creating GoToAction using below code snippet.

if (pdfdoc.OpenAction == null)
{
   //Document has no action, magnification is null
   //Create new GoToAction
   action = new GoToAction(new XYZExplicitDestination(1, 0, pdfDoc.Pages[1].PageInfo.Height,3));
}

In the above code snippet.

When we try to create new GoToAction().

The 4th parameter double zoom passed will return same value when we try to extract destination Zoom value.

For example, in the below code snippet we are passing value as 3

//Create new GoToAction
  action = new GoToAction(new XYZExplicitDestination(1, 0, pdfDoc.Pages[1].PageInfo.Height,3));

When we try to get the zoom value using below code snippet

XYZExplicitDestination dest = null;

if ((dest = gotoaction.Destination as XYZExplicitDestination) != null)
{
    double value = dest.Zoom;
}

The dest.zoom returns whatever we have passed as 4th parameter in create GoToAction. We have passed 3 in create GoToAction hence we get dest.zoom value as 3.

If we pass 4 we will get 4 which is incorrectly determining the zoom factor.

The Magnification of a document with action null is incorrectly returning the zoom factor using above code snippet.

@sidcode

We have logged your requirement as PDFNET-52221 in our issue tracking system. We will inform you via this forum thread once this feature is available.

We apologize for your inconvenience.