Rename a file to the contents of a field on a card
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Rename a file to the contents of a field on a card
I have a field CaseNumber.
I generate a pdf File and save it in the Documents Folder.
I want to have the name of the PDF be the contents of the CaseNumber Field
I know this is easy but I have been away from LC for about a year.
Help Please!
Tom
I generate a pdf File and save it in the Documents Folder.
I want to have the name of the PDF be the contents of the CaseNumber Field
I know this is easy but I have been away from LC for about a year.
Help Please!
Tom
-
- VIP Livecode Opensource Backer
- Posts: 10048
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Rename a file to the contents of a field on a card
See the rename command:
https://livecode.com/resources/api/#liv ... ipt/rename
https://livecode.com/resources/api/#liv ... ipt/rename
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Rename a file to the contents of a field on a card
If you want to put the newly created file name somewhere on the page when it's printed (like the old fashioned TXT files on windows used to do), you could try something like this:
I haven't tried that, but it should work. It just intercepts the filename you are saving and puts it into a field before you print.
XdM
Code: Select all
on mousedown --or mouseup, whatever you prefer--
ask file "Choose a file for the PDF:"
if it is not empty then
put IT & ".pdf" into tTargetFile
put tTargetFile into field "CaseNumber" --of card CardName, or whatever you need to do to get it to the right place. If you want the whole file path, you'll need to use something like longfilepath--
open printing to pdf tTargetFile
set the printpaperorientation to "landscape" -- or "Portrait", whatever works for your project--
set the printscale to 0.85 --I find I need to tweak this to get it to work for the card and page size discrepancies--
set the printmargins to 10,10,10,10 --Or whatever margins you want/ need to get it to work--
print card CardName --put your card's name here--
close printing
end if
end mousedown --or mouseup--
XdM
Re: Rename a file to the contents of a field on a card
Hi Richard,
Thank You again for your help.
Really I want the name of the file to be the contents of a field on the card.
Here is my code:
on mouseUp
put fld"ClaimNumber" into tNewFIle --in this case the data in field ClaimNumber is TR12345 -- I want the name of the generated PDF to be TR12345.pdf
put specialFolderPath("Documents") & "/tNewFile.pdf" into tFileToPrint --I think my problem is here. I have tried numerous variations to no avail
open printing to pdf tFileToPrint --no matter what I have made the generated PDF is named tNewFile.pdf
print cd"ClaimInfo"
Close printing
Thanks Again,
Tom
Thank You again for your help.
Really I want the name of the file to be the contents of a field on the card.
Here is my code:
on mouseUp
put fld"ClaimNumber" into tNewFIle --in this case the data in field ClaimNumber is TR12345 -- I want the name of the generated PDF to be TR12345.pdf
put specialFolderPath("Documents") & "/tNewFile.pdf" into tFileToPrint --I think my problem is here. I have tried numerous variations to no avail
open printing to pdf tFileToPrint --no matter what I have made the generated PDF is named tNewFile.pdf
print cd"ClaimInfo"
Close printing
Thanks Again,
Tom
Re: Rename a file to the contents of a field on a card
I do have "end mouseUp" at the end
Re: Rename a file to the contents of a field on a card
I think your right

Try changing it to -
Code: Select all
put (specialFolderPath("Desktop") & "/LcForumTests/printTesting/" & tNewFile & ".pdf") into tFileToPrint --tNewFile is a variable, as such, it should be outside of the quoted file name...

Re: Rename a file to the contents of a field on a card
Sorry Bogs,
No file is printed and no folders are generated. It's just like kissing your sister.... Nothing Happens.
Tom
No file is printed and no folders are generated. It's just like kissing your sister.... Nothing Happens.
Tom
Re: Rename a file to the contents of a field on a card
My bad, I realized after re-reading the code after your reply that I still had my folderpath (with folders already made) in place heh. It should have read ~
to use your example.
Code: Select all
put (specialFolderPath("Documents") & "/" & tNewFile & ".pdf") into tFileToPrint

Re: Rename a file to the contents of a field on a card
Hi Bogs!
Oh Happy Day! The PDF generated is correct and named TR12345.PDF Just as I need!
Thanks again for your help!
Tom
Oh Happy Day! The PDF generated is correct and named TR12345.PDF Just as I need!
Thanks again for your help!
Tom
Re: Rename a file to the contents of a field on a card
Tom:
There is also a "open printing to pdf" command in the Dictionary with some sample code.
Maybe that would be useful.
Bob
There is also a "open printing to pdf" command in the Dictionary with some sample code.
Maybe that would be useful.
Bob
Re: Rename a file to the contents of a field on a card
Oops. Never mind. You are using that command.
I didn't read the prior messages closely enough.
Sorry, Bob
I didn't read the prior messages closely enough.
Sorry, Bob