Page 1 of 1 1
Topic Options
#165551 - 2006-08-07 07:17 PM Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The printing itself is working, see: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=165333&an=0&page=0&vc=1

However an extra issue came up.
We have a .pdf file that has lets say 75 pages and we only want one or more specific pages to be printed (eg 3, 6, 12 and 54) and not the entire document.
Have any of you come across this before? If so how did you solve it? Can it even be done?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165552 - 2006-08-07 07:22 PM Re: Print one or more specific pages
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
it sounds like an advanced settings issue to the printer
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#165553 - 2006-08-07 07:45 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yeah, looks like it indeed.
It should all be done automatically if possible but I have no idea how.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165554 - 2006-08-07 08:16 PM Re: Print one or more specific pages
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Actually I've been looking for the same / similar thing Mart.

I downloaded the SDK and it has some commandline stuff but so far have not found anything to allow me to select specific pages from the commanline.

Will update if I find a method, you do the same

Top
#165555 - 2006-08-07 08:16 PM Re: Print one or more specific pages
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Some of my printers have separate advanced settings on the printers them selves, and if that is not it, it might be a driver issue, where are the drivers located, are they on the local machines or is this a TS or Citrix environment? I use Citrix and have had to go to a Bata driver and even that has not solved all the problems I am having. With one of my printers, I was using a jet direct to put it on the network but had to go to an internal network card to solve some communication problems, don’t ask me why that worked but it did.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#165556 - 2006-08-07 08:33 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Benny,

The drivers are installed locally. The printer is a network printer.
We have sort of a hot folder structure setup on a dedicated machine that does all kind of maintenance and other sort of tasks using kix scripts. One of the jobs (still in development) is printing an x amount of pages from one or several pdf files once a week. This should be fully automated and should not require any user actions besides putting the files to process in the right place.

Doc,

For pdf files one could use a pdf splitter like the one in the link below to split the pdf into separate pages and then print the page you want/need and delete the separate files when you are done. I suddenly remembered something about splitting and merging pdf’s so did some googling and several came up.
http://www.adultpdf.com/products/pdfsplitmerge/index.html

It has a command line version so it should be possible to use it from a script.
It's not totaly free and the trial version adds a bright red "watermark" at the bottom of each page saying it was done with a trail version and the url of the makers (www.adultpdf.com). It is only 27,90 US$ so if it does what we do and we like it the costs are not an issue.

Will do some more googling and see what comes up. Also will do some testing and post the results.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165557 - 2006-08-07 09:01 PM Re: Print one or more specific pages
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Yeah the money portion is not a big deal. For our needs though I suppose I could setup the machines with individual pages myself probably just as fast as using that tool.

From PlanetPDF
Quote:

[From the DEVFAQ]
AcroRd32.exe filename - Executes the Reader and displays a file..
AcroRd32.exe /p filename - Executes the Reader and prints a file..
AcroRd32.exe /t path printername drivername portname - Initiates Acrobat
Reader,,
prints a file while suppressing the Acrobat print dialog box,then terminates
Reader.
The four parameters of the /t option evaluate to
path,printername,drivername,and
portname (all strings).
printername - The name of your printer..
drivername - Your printer driver 's name.Whatever appears in the Driver Used
box
when you view your printer 's properties.
portname - The printer 's port.portname cannot contain any "/"characters;if
it does,
output is routed to the default port for that printer.
If using Acrobat,substitute Acrobat.exe in place of AcroRd32.exe in the
command lines.

These command lines are not supported, but seem to be quite stable.




Top
#165558 - 2006-08-07 09:17 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
We have different pdf file each week so this week the stuff to be printed could be on page 4 and next week on page 73. We have an automatically generated file that has the pages to be printed in it. Manually splitting the pdf and then printing a default letter and the wanted pages from the pdf to be sent out to our customers brings us no time saving as this is what we are looking for besides saving on stamps when sending out just two sheets of paper instead of a whole newspaper. This cuts the costs on stamps by 66% (only 0,78 € or 0,94 US$ per envelope but this can really add up when sending big amounts each week) and saves a lot of time. The time is our biggest goal (knowing that 3 out of 4 employees on the specific department will be leaving us soon) the savings on stamps are just a nice side effect.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165559 - 2006-08-07 09:18 PM Re: Print one or more specific pages
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
idk man, i hate messing with printers, it seams that every piece of software (at least some of the older stuff i have to use) talks to the printers differently and can be a pain in the a$$. what brand/model of printer are you useing?
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#165560 - 2006-08-07 09:24 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I got all HP LaserJet printers. For now we will be using the 4050N and the 5000N series. For now I'll just split up the pdf into separate pages and use the PrintTo2() - Print any file to any printer UDF to let the printer spit them out. No messing with the printer setting or anything. I agree with you the one should not mess with the settings of the printer when an other option is available.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165561 - 2006-08-07 09:41 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Ok. Got some code going. It's still in development.
The $page variable is going to be filled by reading from a csv file. This has not been implemented in the script yet.

This does require the dirlist and the printto2 udf's and the pdf split tool mentioned above.

Code:

Break on

$path = "C:\Program Files\AdultPDF\Ap PDF Split-Merge\"
$files = DIRLIST("d:\testpdf\*.pdf",2)

For Each $file in $files
$array = Split($file, "\")
$filename = SubStr($array[Ubound($array)], 1, Len($array[Ubound($array)]) -4)
?$filename
Shell $path + "pdfspme_cmd.exe -spe " + $file + " D:\testpdf\split\" + $filename
PrintTo2("D:\testpdf\split\" + $filename + $page + ".pdf","\\server\printer1")
If @ERROR = 0
Del "D:\testpdf\split\*.pdf"
Else
?@ERROR
?@SERROR
Sleep 5
Exit
EndIf
Next



I'm done with this for the evening and am going to watch some TV. Will test and edit the script some more tomorrow @ work.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165562 - 2006-08-07 10:20 PM Re: Print one or more specific pages
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
let us know how it turns out dude, maybe someone else can benefit from it to, you da man.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#165563 - 2006-08-07 10:56 PM Re: Print one or more specific pages
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Don't know if this will help, but its free...

AccessPDF - PDFtk

{Edit: and here is a GUI for this too...
http://www.paehl.de/pdf/?GUI_for_PDFTK }


Edited by Allen (2006-08-07 11:00 PM)

Top
#165564 - 2006-08-08 11:04 AM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Cool. Thanks Allen.
Will do some testing.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165565 - 2006-08-08 12:48 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Allen's app above works like a charm but has some limitations that make it unusable for us in this project. For example you cannot specify a target folder to extract the file to when using burst mode. Maybe I'm blind but can't find a way in the docs to get it working the way we require.

The script below works great. You need to purchase the pdf splitting app when you do not want the watermark at the bottom of each page but that’s only 28,00 US$. Sadly it is necessary to kill acrobat reader when it is done printing cause it does not exit by itself. Word or notepad do not need to be killed.
In our case the $page variable will eventually be filled by reading from a file that gets exported from our database once a week. For testing it is set to a specific value. Our test.pdf file has 128 pages so the extracted pages have 001, 002, etc… in the filenamens therefore $page should be set to 075 to get page 75, 009 to get page 9, etc….
A check on the amount of extracted pages will show you if and how many leading 0’s should be added.

Code:

Break on

Call @SCRIPTDIR + "\functions\DirList().udf"
Call @SCRIPTDIR + "\functions\EnumProcess().udf"
Call @SCRIPTDIR + "\functions\printTo2().udf"

;Del "c:\pdftest\split\*.pdf"

$path = "C:\pdftest\tools\"
$files = DIRLIST("c:\pdftest\onverwerkt\*.pdf",2)
$page = "075"

For Each $file in $files
$filepath = Split($file, "\")
$filename = SubStr($filepath[Ubound($filepath)], 1, Len($filepath[Ubound($filepath)]) -4)
Shell $path + "pdfspme_cmd.exe -spe " + $file + " c:\pdftest\split\" + $filename
PrintTo2("c:\pdftest\docs\defaultletter.doc","\\server\printer")
PrintTo2("c:\pdftest\split\" + $filename + $page + ".pdf","\\server\printer")
Sleep 5
$kill= EnumProcess("AcroRd32.exe",1)
If @ERROR = 0
Del "c:\pdftest\split\*.pdf"
Else
?@ERROR
?@SERROR
Sleep 5
Exit
EndIf
Next

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165566 - 2006-08-08 04:01 PM Re: Print one or more specific pages
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Hey Mart... try this

Code:
 
pdftk "Your.pdf" burst output "c:\outdir\pg_%04d.pdf"


Top
#165567 - 2006-08-08 04:09 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Allen, You da man! Works like a charm and it's free.
Don’t know why I missed that.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165568 - 2006-08-13 09:42 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Been a while but here is the final code for anyone that is interested.
It requires three UDF's and it requires the PDF app Allen has linked to (command line version not the GUI).
The paths, the server and the printer are all based on my setup for testing this and should be set to your setup when using the script.
The PDF app splits documents into separate pages. In my case the source PDF had 128 pages. As far as I experimented with this the PDF app added zeros until the page number was four characters long. The exported file that has the customer data has just 1, 2 or 3 character for the page numbers so zeros get added until the page number from the file is four characters long. Maybe this can be changed to just the page numbers and no zeros but I’ll have to look into that. For now it works and is going to be used in a live environment this week.
The source CSV file has four columns separated by a comma. The first line has the column names. It has more data then is used in the code below but that data is used elsewhere in the script for the automatic creating and printing of a letter to go with the printed page.
Unfortunately Acrobat reader does not close by itself when printing is done so it gets killed by enunprocess 5 seconds after the print command is given. Acrobat reader is also slow so yes the sleep 5 is necessary or the file will not get printed because Acrobat reader is killed by the script before it can send the page to the printer.
All of this saves +/- € 3700 (+/- US$ 4400) on stamps in a year and several hours of work each week so people are happy (for now)


Code:

Break on
;
Call @SCRIPTDIR + "\functions\Dirlist().udf"
Call @SCRIPTDIR + "\functions\EnuProcess().udf"
Call @SCRIPTDIR + "\functions\PrintTo2().udf"
;
$files = DIRLIST("d:\pdftest\onverwerkt\*.pdf",2)
$path = "d:\pdftest\tools\"
;
For Each $file in $files
$filepath = Split($file, "\")
$filename = SubStr($filepath[Ubound($filepath)], 1, Len($filepath[Ubound($filepath)]) -4)
Shell $path + 'pdftk ' + $file + ' burst output "d:\pdftest\split\' + $filename + '_%04d.pdf"'
;
$rc = Open (1, "d:\pdftest\export\test.csv", 2)
$line = ReadLine (1)
;
While @ERROR = 0
$line = Split($line, ",")
;$line[0] = Client number
;$line[1] = Company name
;$line[2] = Contact
;$line[3] = Adress
;$line[4] = Zip code
;$line[5] = City
;$line[6] = Page(s)
$line[0] = Trim($line[0])
$line[6] = Trim($line[6])
Select
Case Len($line[6]) = "1"
$line[6] = "000" + $line[6]
Case Len($line[6]) = "2"
$line[6] = "00" + $line[6]
Case Len($line[6]) = "3"
$line[6] = "0" + $line[6]
Case 1
$line[6] = $line[6]
EndSelect
If $line[0] <> "clientnumber"
PrintTo2("d:\pdftest\split\" + $filename + "_" + $line[6] + ".pdf","\\voyager\hp6840")
Sleep 5
$kill= EnumProcess("AcroRd32.exe",1)
EndIf
$line = ReadLine (1)
Loop
Next

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165569 - 2006-08-13 09:55 PM Re: Print one or more specific pages
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Thanks for the work Mart and Allen.

Not sure I need the full usage here, but great to have if I do. I need to setup some type of automated PDF printing soon.

Top
#165570 - 2006-08-13 10:17 PM Re: Print one or more specific pages
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Beware that the larger the PDF file the longer the sleep should be. For just one page 3 to 5 seconds is enough.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.101 seconds in which 0.072 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org