Page 1 of 1

Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 4:38 am
by trags3
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

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 5:00 am
by FourthWorld

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 1:37 pm
by Xero
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:

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--
 
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

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 2:52 pm
by trags3
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

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 2:58 pm
by trags3
I do have "end mouseUp" at the end

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 3:19 pm
by bogs
trags3 wrote:
Mon Feb 01, 2021 2:52 pm
put specialFolderPath("Documents") & "/tNewFile.pdf" into tFileToPrint --I think my problem is here.
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...
...and see if that helps

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 3:46 pm
by trags3
Sorry Bogs,
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

Posted: Mon Feb 01, 2021 3:54 pm
by bogs
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 ~

Code: Select all

put (specialFolderPath("Documents") & "/" & tNewFile & ".pdf") into tFileToPrint 
to use your example.

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 4:00 pm
by trags3
Hi Bogs!
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

Posted: Mon Feb 01, 2021 4:14 pm
by bogs
No problems, glad it worked out for you :)

Re: Rename a file to the contents of a field on a card

Posted: Mon Feb 01, 2021 11:33 pm
by bobcole
Tom:
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

Posted: Mon Feb 01, 2021 11:36 pm
by bobcole
Oops. Never mind. You are using that command.
I didn't read the prior messages closely enough.
Sorry, Bob