private void OnLoaded(Wrapper.PdfState state) { LoadComplete = (state.Type == Wrapper.PdfStateType.Opened); if (LoadComplete) { CheckHR(Native.GetPageCount(instanceId, ref pageCount)); if (pageCount > 0) { CheckHR(Native.SelectPage(instanceId, 0)); } } }
private void OnPageSelected(Wrapper.PdfState pageState) { if (pageState.Width > 0 && pageState.Height > 0 && pageState.TexturePtr != IntPtr.Zero) { currentPage = pageState.PageNumber; pageTexture = Texture2D.CreateExternalTexture(pageState.Width, pageState.Height, TextureFormat.BGRA32, false, false, pageState.TexturePtr); pageTexture.filterMode = FilterMode.Bilinear; pageTexture.wrapMode = TextureWrapMode.Clamp; } if (canvas == null) { return; } Vector3 scale = defaultScale; if (pageTexture.height > pageTexture.width) { scale.x *= (float)pageTexture.width / pageTexture.height; scale.y *= 1.0f; } else { scale.x *= 1.0f; scale.x *= (float)pageTexture.height / pageTexture.width; } var trans = canvas.GetComponent <RectTransform>(); if (trans != null) { trans.transform.localScale = scale; } if (image != null) { Sprite sprite = Sprite.Create(pageTexture, new Rect(0, 0, pageTexture.width, pageTexture.height), new Vector2(0.5f, 0.0f), 1.0f); image.sprite = sprite; } if (pageinfo != null) { pageinfo.text = currentPage + " / " + (pageCount - 1); } }