Scribusoid

Author Topic: Add date and time to PDF when Printed.  (Read 436 times)

Akire87

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
  • Scribus User
Add date and time to PDF when Printed.
« on: September 20, 2016, 02:15:08 pm »
Hi!
I'm trying to add a Date and time to my PDF file, this should only show when I print the document.
I know how to hide the field so that it only shows when I print, but I have some problems with the time.

Now I'm using:

function Print(){
 var oDate = new Date(); // get the current date time object
 var sDate = util.printd("mm/dd/yyyy h:mm t" , oDate); // format date time string
 this.getField("TimePrint").value =  sDate + "m"; // fillin the field value
}
Print();// call my function

But I have some problems with this.. It shows the right date and hour, but never changes the minutes from 09.

I also have a "problem" with my print Button:
var n = app.response("Number of copies: ");

var pp = this.getPrintParams();
if (n > 0) {
pp.interactive = pp.constants.interactionLevel.silent;
pp.NumCopies = eval(n);
this.print(pp);}
this.resetForm() ;

Every time I press this it shows a waring messege, can I take it away in any way? And, can I add that the default number of prints is 1, not 0?

Hope you can help,
Erika

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1061
  • Country: 00
  • Karma: 17
    • the graphics lab
Re: Add date and time to PDF when Printed.
« Reply #1 on: September 20, 2016, 04:10:40 pm »
hi erika

for the future, it would help if you could share a sample .sla
... then we can simply download it and try it out :-)

... anyway, in this case i guess that i don't need to run it, to spot where you can look for the culprit...

your date format string has two times "mm" in there... i guess that "mm" is for the month prefixed by a zero. so you will always get "09"... except if you're tenacious enough and eventually start getting a "10"... :-)

ciao
a.l.e
« Last Edit: September 20, 2016, 04:18:43 pm by a.l.e »

Akire87

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
  • Scribus User
Re: Add date and time to PDF when Printed.
« Reply #2 on: September 20, 2016, 07:25:29 pm »
Thank you! Now I have figured out the time so it works the way I want.

Still have some problems though...

1. When I press the reset button I only want the Test field to be resetet, not my TimePrint field.
*****Edit******
Found a way to Solve this,
Changing
this.resetForm() ;

To:
this.resetForm("Test") ;
***************

2. When I print I want my TimePrint field to update to the current time

3. I want to have a default setting for printing as 1, not sure how to add this though.

4. I get a warning whenever I print, can I choose not to get this?

The more I work with this, the more promblems I seem to get...

Thanks again!
« Last Edit: September 20, 2016, 08:30:07 pm by Akire87 »

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1061
  • Country: 00
  • Karma: 17
    • the graphics lab
Re: Add date and time to PDF when Printed.
« Reply #3 on: September 21, 2016, 11:07:05 am »
4. I get a warning whenever I print, can I choose not to get this?

well, i tried it out: i was lucky that i put 2 as a value in there...

i guess that the warning is there to avoid that funny guys put scripts in the pdf that send 100000000 copies to the printer...

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1061
  • Country: 00
  • Karma: 17
    • the graphics lab
Re: Add date and time to PDF when Printed.
« Reply #4 on: September 21, 2016, 11:26:16 am »
2. When I print I want my TimePrint field to update to the current time

this.getField("TimePrint").value = util.printd("mmm dd, yy h:M", new Date());

... but for some reason, i don't manage it, to get the "TimePrint" field to show in the pdf...
(i tested the above command on a "Test2" field and i've created and it worked correctly!)

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1061
  • Country: 00
  • Karma: 17
    • the graphics lab
Re: Add date and time to PDF when Printed.
« Reply #5 on: September 21, 2016, 12:13:05 pm »
Quote
3. I want to have a default setting for printing as 1, not sure how to add this though.

if the dialog returns an empty string use 1?
« Last Edit: September 21, 2016, 04:07:46 pm by a.l.e »

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1061
  • Country: 00
  • Karma: 17
    • the graphics lab
Re: Add date and time to PDF when Printed.
« Reply #6 on: September 22, 2016, 05:41:10 pm »
Quote
Erika:

Apologies that this thread has been "hijacked" and gone off-topic a bit. This sometimes happens when you get people who have strong views about things. No-one is trying to infer that your inquiries are less important though so please continue to post.

i've moved the meta discussion on the scribus featurs to a new thread:

http://forums.scribus.net/index.php/topic,2198.msg9964.html