PDF export

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10545
Joined: Fri Feb 19, 2010 10:17 am

PDF export

Post by richmond62 »

I implemented PDF export from a field in my Devawriter Pro about 100 years ago, and that was only possible, then, to Mac.

I hope & suppose that export from a field to Windows (and Linux) is now possible.
Klaus
Posts: 14372
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF export

Post by Klaus »

We only have "open printing to PDF..." in LC right now.
Is that what you mean?
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10545
Joined: Fri Feb 19, 2010 10:17 am

Re: PDF export

Post by richmond62 »

Is that what you mean?
Possibly: I'll go and try. Thanks.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10545
Joined: Fri Feb 19, 2010 10:17 am

Re: PDF export

Post by richmond62 »

No, No, No: that prints an image of a card, when what I am looking for is a PDF of the contents of a field.

https://lessons.livecode.com/a/29177-ho ... g-livecode
Klaus
Posts: 14372
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF export

Post by Klaus »

Mabe there is a macOS SHELL command for this or maybe you used AppleScript?
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10545
Joined: Fri Feb 19, 2010 10:17 am

Re: PDF export

Post by richmond62 »

No: there is a relatively easy way in Mac:

Code: Select all

on mouseUp
   ask file "Save as:" with "Print.pdf"
   put it into tFileName
   if tFileName is empty then exit to top
   set the printerOutput to "file:" & tFileName
   revShowPrintDialog false, false
   revPrintField the long name of fld "GUFF"
end mouseUp
The problem is how to do that with Windows and Linux.
Klaus
Posts: 14372
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF export

Post by Klaus »

Ha, had to look up "printeroutput" :-D
According to the docs that should work on: mac, windows, linux.
But doesn't?
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10545
Joined: Fri Feb 19, 2010 10:17 am

Re: PDF export

Post by richmond62 »

I don't think so, but I have not tested it since 2023.
scott_morrow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Tue Jun 27, 2006 8:35 pm
Contact:

Re: PDF export

Post by scott_morrow »

richmond62 wrote: Wed Dec 02, 2026 1:18 pm No, No, No: that prints an image of a card, when what I am looking for is a PDF of the contents of a field.

https://lessons.livecode.com/a/29177-ho ... g-livecode
open printing to pdf does in fact create normal pdf documents that can include text and images and it is NOT simply rendered as an image of a card. Text and hi-resolution graphics appear in the pdf as expected. There is a bug 22982 with using open printing to pdf which causes it to fail if an emoji is encountered while printing. In bugzilla there was some discussion about a possible workaround... place an effect (like a drop shadow) on the field with an emoji and it will then print. This workaround did allow it to print but was not actually very useful because adding the effect caused open printing to pdf to render the field as a (screen resolution) image. Perhaps you are remembering this conversation.

I use open printing to pdf on Mac, iOS and Android. The docs say it should work on Windows and Linux as well.
Elementary Software
...now with 20% less chalk dust!
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10559
Joined: Wed May 06, 2009 2:28 pm

Re: PDF export

Post by dunbarx »

I use "open to PDF" all the time on Mac without issue. Never tried to include an emoji. The resultant PDF's are ordinary in every way.

Craig
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10545
Joined: Fri Feb 19, 2010 10:17 am

Re: PDF export

Post by richmond62 »

Indeed.

BUT, as I have pointed out several times in this thread, I want to be able to export to PDF on Windows and Linux.
Klaus
Posts: 14372
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF export

Post by Klaus »

Hi Richmond,
richmond62 wrote: Thu Dec 03, 2026 5:25 pmIndeed.
BUT, as I have pointed out several times in this thread, I want to be able to export to PDF on Windows and Linux.
did you NOW test "printeroutput"? And/or "open printing to pdf..."?
Both of them are supposed to work on Mac, Win and Linux!
richmond62 wrote: Wed Dec 02, 2026 3:27 pmI don't think so, but I have not tested it since 2023.
8)
ClipArtGuy
Posts: 280
Joined: Wed Aug 19, 2015 4:29 pm

Re: PDF export

Post by ClipArtGuy »

richmond62 wrote: Thu Dec 03, 2026 5:25 pm Indeed.

BUT, as I have pointed out several times in this thread, I want to be able to export to PDF on Windows and Linux.
See my response "over there". `set the printerOutput to "file:..."` only gives a PDF on a Mac. Windows writes XPS and Linux writes PostScript. `open printing to pdf` is what makes a real PDF everywhere. Additionally, `revPrintField` inside `open printing to pdf` quietly wrote nothing, because its own `close printing` ended the whole job. That's an engine bug.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10559
Joined: Wed May 06, 2009 2:28 pm

Re: PDF export

Post by dunbarx »

Regarding "print to PDF", the Windows standalones I make all the time work just fine, therefore I infer that the command works on Windows in the IDE as well.

Craig
ClipArtGuy
Posts: 280
Joined: Wed Aug 19, 2015 4:29 pm

Re: PDF export

Post by ClipArtGuy »

dunbarx wrote: Thu Dec 03, 2026 8:33 pm Regarding "print to PDF", the Windows standalones I make all the time work just fine, therefore I infer that the command works on Windows in the IDE as well.
Yes, print to PDF works on Windows, for a card. What fails is a field printed with revPrintField inside open printing to pdf. That writes no file at all, and gives no error.
 
revPrintField (really revPrintText) does its own open printing / close printing. The engine treats that inner close printing as the end of the whole PDF job, so it throws the PDF printer away before anything is written. Then your own close printing has nothing left to close. It isn't really a Windows thing: the same engine and library code is in LiveCode's own source (at least as on 9.7-dp1), so I'd expect the same on Mac and Linux. On a Mac, Richmond's old trick of setting the printerOutput to "file:..." happens to produce a PDF, which is why it seemed Mac-only.
 
Workaround: print the field yourself, one page at a time, by its pageHeights, inside a single open/close printing. Or don't nest the call at all. I've fixed it in my fork's engine, so a close inside a PDF job only closes its own level.
Post Reply