[Gambas-user] Poppler PDF fitting in DocumentView

Rolf-Werner Eilert rwe-sse at osnanet.de
Wed Jan 12 08:55:16 CET 2022

I have questions about the poppler library way of doing things.

Some time ago I got some code examples from Gianluigi, and now I tried 
one of them which seemed to be practical for me.

In a DocumentView a PDF shall be shown.

I think the answer lies in this SUB:

Public Sub DocumentView1_Draw(Page As Integer, Width As Integer, Height 
As Integer)

  Dim fRes As Float
  Dim himg As Image

  fRes = $hPdf.Resolution / 72
  himg = $hPdf[Page].Render(0, 0, Width / fRes, Height / fRes, 0, 
$hPdf.Resolution / fRes)
  Draw.Image(himg, 0, 0, Width, Height)


Where do I have to tweak these lines to fit the pages into the area of 
the DocumentView?

Another trial was tweaking the Zoom function:

Public Sub btnZoomIn_Click()

  Dim f As Float = DocumentView1.Zoom

  f = f / 2
  'f += 0.05
  'If f > 1.5 Then f = 1
  DocumentView1.Zoom = f
  DocumentView1.Count = $hPdf.Count


But this will just cut the areo on which the PDF is shown by half, the 
document is shown by half and becomes unsharp. Ok, now it fits, but this 
is not really the desired effect.

I add the code archive for those who want to test it.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: testPopplerPDF-0.0.1.tar.gz
Type: application/gzip
Size: 12920 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220112/734e2478/attachment-0001.gz>

More information about the User mailing list