[Solved] PDF

Everything else that doesn't fall into one of the other PB categories.
k3pto
User
User
Posts: 87
Joined: Sat Jan 17, 2015 5:24 pm

[Solved] PDF

Post by k3pto »

I would like to show the first page of a few PDF files on screen at one time. So, I have two questions:
1) How can I display a pdf?
2) What type of window should I use: Screen, Canvas, Window? Or is there another?

The solution I chose was to download a program from the Windows store which converts a PDF to jpegs.
Last edited by k3pto on Sat Aug 10, 2024 12:55 am, edited 2 times in total.
loulou2522
Enthusiast
Enthusiast
Posts: 550
Joined: Tue Oct 14, 2014 12:09 pm

Re: PDF

Post by loulou2522 »

For your first question
RunProgram("c:\users\xxx\xxx.pdf" )
RunProgram("c:\users\xxx\yyy.pdf" )
that's open one session of pdf acrobat and you will see the first page of each pdf
For your second question you must have to use comateplus to control acrobat reader

Code: Select all

;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch.
;*===========
;*
;*Acrobat PDF demo - by Stefan Schnell.
;/////////////////////////////////////////////////////////////////////////////////

IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"


Define.COMateObject PDFObject

If OpenWindow(0, 0, 0, 800, 800, "COMate PDF-Demo", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)

  pdfObject = Comate_CreateObject("AcroPDF.PDF.1", WindowID(0)) 
  If pdfObject
    pdfObject\SetProperty("src = 'C:\Users\xxx\Dxx\xx.PDF'") 
    pdfObject\Invoke("setShowToolbar(#True)") 
    pdfObject\Invoke("setView('Fitv')") 
    pdfObject\Invoke("setPageMode('none')") 
       pdfObject\Invoke("setLayoutMode('SinglePage')") 
    Debug pdfObject\Invoke("DESCRIPTION") 
    

    While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend 
    CloseWindow(0)
    pdfObject\Release()
  Else
    MessageRequester("COMate -Acrobat PDF demo", "Couldn't create the ActiveX object!")
  EndIf
EndIf
Axolotl
Addict
Addict
Posts: 835
Joined: Wed Dec 31, 2008 3:36 pm

Re: PDF

Post by Axolotl »

I use the external program SumatraPDF (windows only) to do this.
With a newer version you can control the behavior by DDE commands.

Code: Select all

; example call of the SendDDE command 
  SendDDE("[CmdCloseCurrentDocument]") 
If someone is interested, I can extract some working code from my project. :oops:
The basic command would be like this (not complete code)

Code: Select all

 
; --- usually part of my Module --- 
  #SumatraPDF_Homepage$    = "https://www.sumatrapdfreader.org/free-pdf-reader" 
  #SumatraPDF_Classname$   = "SUMATRA_PDF_FRAME"   ; used in FindWindow() 

  ; set to the latest SumatraPDF.exe on your system 
  ; 
  ; Global m_Executable$ = "SumatraPDF-3.4.6-64.exe" 

  ; window handle of the running SumatraPDF (don't use the New Window parameter!! 
  ; 
  Global m_hwndViewer = 0   ; member of the module, init with ZERO 

  ; coordinates and size of sumatra window 
  ;
  Global m_X = 32, m_Y = 32, m_W = 800, m_H = 1200  

  ; --- internal procedures 

  Procedure SendDDE(Command$)  ; send DDE command(s) to sumatra 
    Protected result, cds.COPYDATASTRUCT 

    If m_hwndViewer = 0  ; look for a running instance 
      m_hwndViewer = FindWindow_(#SumatraPDF_Classname$, 0) 
    EndIf 

  	If m_hwndViewer  ; send message to the running instance 
      cds\dwData = $44646557 ; <------------------------- constant (see Sumatra help file)  
      cds\cbData = StringByteLength(Command$) + 2 ; <---- unicode world (important + 2) 
      cds\lpData = @Command$  ; <------------------------ pointer to string 

      ; If the receiving application processes this message, it should return TRUE; otherwise, it should return FALSE. 
    	result = SendMessage_(m_hwndViewer, #WM_COPYDATA, 0, @cds) 

    	Debug "SendDDE(" + Command$ + ") .. " + StringField("Failed.Ok.", 1+Bool(result), ".") 

    	ProcedureReturn result 
  	Else ; m_hwndViewer not valid (found, running, etc.) 
    	Debug "SendDDE(" + Command$ + ") .. not executed, because cannot find Viewer --> " + m_hwndViewer 
  	EndIf 
    ProcedureReturn #False
  EndProcedure 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PDF

Post by Kwai chang caine »

Yes really interesting :D (In fact all the tip's for remote others programs is interesting for me :mrgreen: )
I have try and that works !!!
Incredible to see this old DDE protocol is always used !!! :shock:
Thanks a lot Axolotl for this tip's 8)
ImageThe happiness is a road...
Not a destination
Post Reply