XPDF - where is it?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

XPDF - where is it?

Post by stam » Fri Jun 30, 2023 5:58 pm

Hi all,

Last year I subbed to the new LC "with pro features" but can't find the fabled XPDF external.
There is a PDF external which can display a PDF but seems to lack the XPDF features in the dictionary.

Am I mistaken? is the 'PDF' external what provides XPDF features or is there a different external that I'm missing?

Many thanks
Stam

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: XPDF - where is it?

Post by stam » Fri Jun 30, 2023 6:21 pm

Further to this, I found a comment in the mailing list archive suggesting it's inside the app bundle and did find a folder
/LiveCode.app/Contents/Tools/Ext/XPDF-1.0.45/ that contains what seems to be an external XPDF.bundle and what seems to be an example stack XPDF.livecode

HOWEVER: running the example stack crashes on startup on line 72 of the card script , in the handler private command __initialize, the first line of code

Code: Select all

XPDFViewer_Open kViewer, the windowID of this stack
throws the error 'can't find handler', which makes me think this external may not be loaded.

I have no reference for what the set up should be, only that XPDF was previously sold in the Pro version and I'd expect this to be in the 'Pro features'.

Any suggestions?

--------------
EDIT: I also found a github repo for this which again fails with same errors: https://github.com/macMikey/xpdf

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: XPDF - where is it?

Post by bn » Fri Jun 30, 2023 11:38 pm

Stam,

I have no experience using XPDF. I tried today with a very simple test using LC 9.6.9 and it failed as you noticed.
I am using LC on a M1 MacBook Pro running in native(arm) mode.
Then I switched to "use Rosetta" in Finder Info for LC 9.6.9 and it worked.
Apparently the XPDF external is compiled for "Intel".

If that sounds familiar to you (e.g. because you also run LC on an Arm chip in native mode you could try to switch to "Rosetta Mode"

These are the scripts I used
Create an XPDFViewer

Code: Select all

on mouseUp
   put specialFolderPath("desktop") & "/Sample.pdf" into tPath
   put "document1" into tName
   put the windowID of this stack into tWindID
   XPDFViewer_Open tName, tWindID
   XPDFViewer_Set tName, "rect", (100, 100, 700, 600)
   XPDFViewer_Set tName, "fileName", tPath
end mouseUp
Close XPDFViewer

Code: Select all

on mouseUp
   XPDFViewer_Close "document1"
end mouseUp
Please note that XPDF is case sensitive:

Code: Select all

XPDFViewer_Close "Document1"
does not work because of the uppercase "D" in "Document1"

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: XPDF - where is it?

Post by stam » Sat Jul 01, 2023 2:59 pm

Thanks Bernd, as usual you hit the nail on the head!!!
I had opened a support ticket, will update as this seems like an easily achievable fix for next version.

The reason I was looking into this rather than the PDF external that is in included in my subscription was to get the text of the PDF.
For now, I have reverted to a solution I posted a while back, which uses opensource command-line tools: https://forums.livecode.com/viewtopic.p ... 30#p201036

To be honest this is perfect fine, using the shell I create a text file at the same location as the pdf, importing the text file and then deleting it.
Of course ideally I'd not use shell and command line tool and be fully within LC, but this would mean that I couldn't produce any apps that use Apple Silicon, which is a bit naff... hopefully the team will fix in the future.

For now, this is the function I use to get the text of a pdf; the command line executables reside at same location as the stack, i.e. in specialFolderPath("resources"). These can be downloaded from http://www.xpdfreader.com/download.html

Code: Select all

function getPDFText pPdfPath -- pPdfPath is the full path to the PDF file
    local tExecPath, tFilePath, tText
    put specialFolderPath("resources") & "/pdftotext" into tExecPath
    if the platform is "win32" then put ".exe" after tExecPath
    put quote & tExecPath & quote into tExecPath -- protect against illegal chars in file path
    put quote & pPdfPath & quote into pPdfPath -- protect against illegal chars in file path
    get shell(tExecPath && pPdfPath)
    replace quote with empty in pPdfPath
    set the itemdel to "."
    put "txt" into item 2 of pPdfPath
    put URL ("file:" & pPdfPath) into tText
    delete file pPdfPath
    return tText
end getPDFText

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: XPDF - where is it?

Post by stam » Sat Jul 01, 2023 3:19 pm

Just an addendum - while the XPDF external code works in 9.6.9 launched with Rosetta, opening either the included stack (in app bundle/Contents/Tools/Ext/XPDF-1.0.45) or the repo I linked above, it just generates and endlessly spinning beachball in 10 DP5... so might be more than simple fix needed...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: XPDF - where is it?

Post by bn » Sat Jul 01, 2023 7:13 pm

stam wrote:
Sat Jul 01, 2023 3:19 pm
Just an addendum - while the XPDF external code works in 9.6.9 launched with Rosetta, opening either the included stack (in app bundle/Contents/Tools/Ext/XPDF-1.0.45) or the repo I linked above, it just generates and endlessly spinning beachball in 10 DP5... so might be more than simple fix needed...
Stam,

I just tried above recipe in 10 DP5 _AFTER_ having set 10 PD5 via Finder Info to open in Rosetta and it worked...

Kind regards
Bernd

paul@researchware.com
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 136
Joined: Wed Aug 26, 2009 7:42 pm
Location: Randolph, MA USA
Contact:

Re: XPDF - where is it?

Post by paul@researchware.com » Sun Jul 02, 2023 8:24 pm

stam wrote:
Sat Jul 01, 2023 2:59 pm
Thanks Bernd, as usual you hit the nail on the head!!!
I had opened a support ticket, will update as this seems like an easily achievable fix for next version.
I realy hope that Livecode, Ltd can just compile the XPDF external for the M-series Apple chips to address this in an upcoming maintenance release. the PDF widget is misisng features still present in the XPDF external. I have it on my length to-do list to try to develop a detailed list of what messages, functions, and commands are needed in the Widget to fully replace the external, but simply have not had a chance to get to it yet. So, we (Researchware) still deperately need the XPDF external to continue to function on new Apple systems.

Paul Dupuis
Researchware
Paul Dupuis
Researchware, Inc.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: XPDF - where is it?

Post by stam » Mon Jul 03, 2023 2:32 pm

paul@researchware.com wrote:
Sun Jul 02, 2023 8:24 pm
The PDF widget is misisng features still present in the XPDF external. I have it on my length to-do list to try to develop a detailed list of what messages, functions, and commands are needed in the Widget to fully replace the external
Hi Paul,
I submitted a bug report here : https://quality.livecode.com/show_bug.cgi?id=24254

Confirmed and being looked into by Panos, who is considering if possible adding more functionality to the new PDF external rather than maintaining both (which makes sense). Probably now is a good time to list your requirements in the bug report above!

Stam

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: XPDF - where is it?

Post by stam » Wed Jul 05, 2023 12:30 pm

For others that may have a similar need to mine (ie extract text from pdf), Panos has shared this handler to use the current PDF widget to get its text:

Code: Select all

function getPdfWidgetText
   local tText
   repeat with i = 1 to the numberOfPages of widget "PDF"
      set the currentPage of widget "PDF" to i
      local tRange
      put 0 into tRange["from"]["index"]
      put i into tRange["from"]["page"]
      put 2^31 into tRange["to"]["index"]
      put i into tRange["to"]["page"]
      set the hilitedRange of widget "PDF" to tRange
      get the hilitedRangeText of widget "PDF"
      put it & return after tText
   end repeat 
   set the hilitedRange of widget "PDF" to ""
   return tText
end getPdfWidgetText
works as advertised, no need for shell commands!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”