User Tools

Site Tools


Sidebar

Multimedia

k23:k23.13:start

23.13 DocumentView (gb.form)

This control implements a document viewer.

The class can be created. To create a new DocumentView object:

  Dim hDocumentView As DocumentView
  hDocumentView = New DocumentView ( Parent As Container ) [ As "EventName" ]

23.13.1 Properties

The DocumentView class has these properties

PropertyData typeDescription
ArrangementIntegerReturns or specifies how the different pages are arranged within the view. This property can take one of the following values: Arrange.Vertical, Arrange.Horizontal, Arrange.Row, Arrange.Column or Arrange.Fill.
AutoCenterBooleanReturns or specifies whether the page is centred if only one page is displayed in the width. This is only available for some arrangement modes: Arrange.Vertical, Arrange.Horizontal or Arrange.Fill.
CenterBooleanReturns or defines whether the page is centred in the view or not.
BorderBooleanReturns or specifies whether the document view has a border.
ColumnIntegerThis allows you to specify the number of columns displayed, depending on the selected arrangement mode.
ColumnsIntegerReturns or defines the number of columns used for the layout of the pages. If this value is set to zero (default), the pages are only displayed individually in the preview. Otherwise, all pages are arranged from top to bottom.
CountIntegerReturns or defines the number of pages in the document.
DesaturateBooleanReturns or specifies whether the preview is desaturated automatically.
DirectionIntegerReturns or defines the direction of the text. It can take one of the following values: Direction.Default, Direction.RightToLeft, Direction.LeftToRight.
DocHeightIntegerReturns or sets the default height of a page in millimetres. The default height of the page is 297∙mm (A4 format).
DocWidthIntegerReturns or sets the default width of a page in millimetres. The default width of the page is 210∙mm (A4 format).
FirstVisibleDocumentIntegerReturns the number of the first visible page in the viewer.
LastVisibleDocumentIntegerReturns the number of the last visible page in the viewer.
FirstVisiblePageIntegerReturns the index of the first visible page in the viewer.
LastVisiblePageIntegerReturns the index of the last visible page in the viewer.
Layout_DocumentLayoutReturns a virtual object that is used to define the layout of a specific page. See the 'Layout' event for more details. The _DocumentLayout class has 2 properties: (1) Height: Specifies or sets the height of the page in millimetres and (2) Width: Returns or sets the width of the page in millimetres.
MaxIntegerReturns the number of pages of the document - reduced by 1 - and thus corresponds to the highest page index.
PaddingIntegerReturns or defines the (inner) margin spacing within the view in millimetres. The specification applies to all 4 directions!
PageHeightIntegerReturns or defines the standard height of a page in millimetres. The standard page size is 210∙mm x 297∙mm (A4 format).
PageWidthIntegerReturns or sets the default width of a page in millimetres. The default size of the page is 210∙mm x 297∙mm (A4 format).
ShowPageBooleanReturns or specifies whether the page number should be displayed within the view.
ShowShadowBooleanReturns or specifies whether the pages are to be drawn with a small shadow.
ZoomFloatReturns or sets the zoom factor of the view. 'Zoom' is a synonym for the 'Scale' property.

Table 23.13.1.1 : Properties of the DocumentView class

23.13.2 Methods

The DocumentView class has these essential methods:

MethodDescription
Find ( X As Integer, Y As Integer )Returns the page number under a specific mouse pointer position. X and Y are the positions of the mouse pointer relative to the document view.
Goto ( Page As Integer )Moves the view to a specific page. 'Page' is the page number, starting at zero.
Refresh ( )Refreshes the contents of the view in the viewer
Reset ( )Resets the view.
Show ( )Displays the control.

Table 23.13.2.1 : Methods of the DocumentView class

23.13.3 Events

The DocumentView class has these events:

EventDescription
Draw ( Page As Integer, Width As Integer, Height As Integer )This event is triggered when a specific page preview needs to be drawn: 'Page' is the index of the page to be drawn. 'Width' and 'Height' are the size of the image buffer in which the page is to be drawn.
Finished ( )This event is triggered when all page previews have been drawn.
Layout ( Page As Integer )This event is triggered when the Page parameter changes and therefore each page layout can be defined independently. 'Page' is the index of the page to be designed. Use the Layout property within the handler of this event to define the layout of the *specified* page.
Zoom ( )This event is triggered when the zoom level has changed.

Table 23.13.3.1 : Events of the DocumentView class

23.13.3.1 Possible applications of a DocumentView

The developer of the control, Fabien Bodard, described the possible applications of a DocumentView as follows: 'It can display not only PDF documents, but actually anything you want, as long as there is a utility that allows you to render the content. DocumentView provides you with 'canvases' on which you can draw whatever you want. So it can be anything as long as you can draw it with the Paint.DrawImage() function.

23.13.3.2 Example 1

A typical application for the DocumentView control is the display of PDF files:

BILD_PDF

Figure 23.13.3.2.1: Display of a PDF document (excerpt)

Source code:

' Gambas class file
 
Private $PDF_Document As New PdfDocument
 
Public Sub Form_Open()
    btnOpen.SetFocus()
End
 
Public Sub btnOpen_Click()
  Dialog.Filter = ["*.pdf", "PDF-Files"]
  If Not Dialog.OpenFile() Then
     $PDF_Document.Open(Dialog.Path)
 '-- Setup the number of pages shown in the viewer. It enforce the layout event call
     DocumentView1.Count = $PDF_Document.Count
     DocumentView1.Refresh()
     Wait
  Else
     Return
  Endif
End
 
Public Sub DocumentView1_Layout(Page As Integer)
  DocumentView1.Layout.Width = $PDF_Document[Page + 1].Width
  DocumentView1.Layout.Height = $PDF_Document[Page + 1].Height
End
 
Public Sub DocumentView1_Draw(Page As Integer, Width As Integer, Height As Integer)
'-- Draw the pdf image
    Paint.DrawImage($PDF_Document[Page + 1].Image, 0, 0, Paint.Width, Paint.Height)
End
 
Public Sub DocumentView1_Zoom()
    $PDF_Document.Zoom = Last.Zoom
End
 
Public Sub Form_Resize()
    DocumentView1.Column = 1
    DocumentView1.Refresh()
    Wait
End
 
Public Sub btnClose_Click()
    FMain.Close()
End

23.13.3.3 Example 2

In the second project, each image content is drawn on a separate image - as a canvas - and displayed in the size specified by the slider in the range from 0% to 200% for each individual page:

Public Sub DocumentView1_Draw(Page As Integer, Width As Integer, Height As Integer)
    Paint.DrawImage($aImages[Page], 0, 0, Width, Height)
End

The focus is not on the detailed preview of individual images, but on the overview of all images in the selected directory:

BILD-BILD

Figure 23.13.3.3.1: Reduced display of images in a DocumentView

Source code:

' Gambas class file
 
Private $sPath As String
Private $aImages As New Image[]
 
Public Sub Form_Open()
 
    lblMin.Text = sliderZoom.MinValue
    lblMax.Text = Str(sliderZoom.MaxValue) & "%"
 
    DocumentView1.Arrangement = Arrange.None
    DocumentView1.Columns = 0
    DocumentView1.Center = True
    DocumentView1.Spacing = 20
 
    sliderZoom.Value = 30
    DirBox1.Tooltip = "Select an image directory!"
    ChangePath()
 
End
 
Public Sub DirBox1_Change()
    $sPath = Last.Path
    ChangePath()
    sliderZoom.Value = 32
End
 
Public Sub ChangePath()
 
    Dim sFile As String
    Dim hImage As Image
 
    $aImages.Clear()
    For Each sFile In Dir($sPath, Null, gb.File)
        Select Case File.Ext(sFile)
          Case "png", "jpg"
            hImage = Image.Load($sPath &/ sFile)
            $aImages.Add(hImage)
        End Select
    Next
    DocumentView1.Count = $aImages.Count
End
 
Public Sub DocumentView1_Draw(Page As Integer, Width As Integer, Height As Integer)
    Paint.DrawImage($aImages[Page], 0, 0, Width, Height)
End
 
Public Sub DocumentView1_Layout(Page As Integer)
 
'-- Allow to define specific layout for items
'-- It is called before the drawing... so images need to be seen twice in this case
    DocumentView1.Layout.Width = $aImages[Page].W
    DocumentView1.Layout.Height = $aImages[Page].H
End
 
Public Sub DocumentView1_Zoom()
    DocumentView1.Refresh()
End
 
Public Sub sliderZoom_Change()
    DocumentView1.Zoom = sliderZoom.Value / 100
    lblMax.Text = Str(sliderZoom.Value) & "%"
End

You can find the project archives for the two projects presented in the download area.

Download

Chapter & Projects

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.13/start.txt · Last modified: 17.01.2024 by emma

Page Tools