MAUI: iOS: Image alignment issue in pdfwebviewer

Sreenivasan, Sreejith 1,020 Reputation points
2026-07-27T11:19:02.32+00:00

I have a custom pdfwebviewer like below where I viewing both pdf and images.

<ctrl:PdfWebViewer Grid.Row="2" Uri="{Binding SelectedArticleUrl}"
                   HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                   AutomationProperties.IsInAccessibleTree="False"/>

My problem is with the image alignment and pdf works fine. It is currently vertically on start but I need it on the center. I tried updating the handler codes, but nothing works as expected. The issue is on the maui ios platform and android part working fine. I can share the handler code one to one since it is very lengthy.

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author
Nancy Vo (WICLOUD CORPORATION) 8,075 Reputation points Microsoft External Staff Moderator
2026-07-28T03:26:22.9633333+00:00

Hello @Sreenivasan, Sreejith ,

Thanks for your question.

This behavior is often related to how iOS WKWebView renders a standalone image. When an image URL is loaded directly, iOS treats it as a raw image document without a real <body> element, so alignment changes applied through the handler or injected CSS may have no effect. This could be the reason your handler updates are not producing the expected result.

I recommend loading the image through a small HTML wrapper on iOS, rather than loading the image URL directly. The HTML provides a container that can be centered with CSS:

string imageHtml = $@"
<html>
  <head>
    <style>
      html, body {{ margin:0; padding:0; height:100%; }}
      body {{ display:flex; justify-content:center; align-items:center; }}
      img  {{ max-width:100%; max-height:100%; object-fit:contain; }}
    </style>
  </head>
  <body><img src='{imageUrl}' /></body>
</html>";

wkWebView.LoadHtmlString(new NSString(imageHtml), baseUrl: null);

The PDF loading path can be left unchanged, and this branch would only run when the URL points to an image.

I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback. Thank you.

Was this answer helpful?

2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 84,951 Reputation points
    2026-07-27T15:49:51.2566667+00:00

    unlike android, IOS and IOS web view have a build-in pdf viewer. android typically uses a web view with a javascript library to view pdf's. using the IOS native pdf viewer (pdfkit) may give you the control you want.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.