Solved

Print only selected pages of a PDF document (coldfusion)

Posted on 2010-09-16
11
552 Views
Last Modified: 2012-05-10
How can I print only selected pages from a PDF documents using Coldfusion? In other words, after I submit the form with the selected pages (e.g. 5-10, 110-125, 221-222 etc) I get the report on my screen with only the pages I've select to print. I tried with the CFPRINT tag but the output is sent directly to the printer with the Preview option.

Thanks,

Errol
0
Comment
Question by:Errol Farro
  • 6
  • 5
11 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 33692262
>> How can I print only selected pages from a PDF documents using Coldfusion?

Using the "pages" attribute of CFPRINT. It allows you to specify which page or pages will be printed

<cfprint pages="1-3,6,10-20" .... etc.....>
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_12.html

>> the output is sent directly to the printer with the Preview option

Previewing is a client side operation. ie A feature of programs with Adobe Acrobat.  If you're printing on the _server_ there is no preview.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33692284
>>  If you're printing on the _server_ there is no preview.

... which is what CFPRINT does. It uses a printer on the server side.  If you're talking about a user printing something with their local inkjet, that is totally different ...
0
 

Author Comment

by:Errol Farro
ID: 33692535
Thx Agx,

But what exactly should I do to activate previewing on the client side?

This is my test code;
<cfprint
    source = "c:\xxxxxxxx.pdf"
    pages = "22-24,78-78">

but it's sent directly to the server's default printer. Should I use the Printer parameter?

Thx.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 52

Expert Comment

by:_agx_
ID: 33692712
>> what exactly should I do to activate previewing on the client side?

You can't.  You can't control a program on the user's computer from the server.

Either I'm misunderstanding ... or you're trying to do something that's not possible :)  Acrobat's print-preview is for something a user will printing on _their_ printer.  That's not what you're doing. You're printing on the _server_.  There is no preview mechanism when printing on the server.  If you think about it .. it wouldn't make sense to have one.  If it were possible, the preview would pop-up on the _server_  and there'd be nobody there to see it.

0
 

Author Comment

by:Errol Farro
ID: 33692814
ok understood so maybe cfprint is not the tag I should use. Do you have any other suggestion?

I have a form with 4 parameters on it where 4 different from-to pages can be entered. After submitting, the user should see a preview of only the selected pages of the pdf document. So only e.g. pages 10-20, 21, 40-50 and 80-110 are previewed and optionally can be printed.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33693055
There's a lot you're leaving out :)  

>> previewed and optionally can be printed.

1) Printed by the user on their own printer, yes?

2) You originally said

>> I get the report on my screen with only the pages I've select to print.

That implies you've created a new pdf containing ONLY the selected pages eg. 10-20. Then returned that new file to the user.  I don't think that's what's actually happening or we wouldn't be having this conversation.  So can you elaborate ? :)
0
 

Author Comment

by:Errol Farro
ID: 33693967
1) Yes
2) No, I want to print preselected pages from a big PDF file.
But now that you are mentioning this, can I somehow create a new pdf file with only the pages I need from a source pdf file?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 33694652
Sure. You can use <cfpdf> to create a new pdf containing only select pages.  

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=cfpdf_15.html
http://cfpdf.blogspot.com/2007/06/cfpdf-action-merge_27.html

You can save the pages to a new file on the server. Then delete it when it's displayed with CFCONTENT.  Just be sure to use unique files name each time. You can use something like createUUID() to create unique file names.


<!--- extract the selected pages and save them to a file --->
<cfpdf action=merge source="c:\pathTo\sourceFile.pdf" Pages="7, 10, 15, 20, 25, 40" destination="c:\path\to\theNewFile.pdf" overwrite="true">
<!--- return them to the browser and DELETE the file --->
<cfcontent type="application/pdf" file="c:\path\to\theNewFile.pdf" deleteFile = "YES">

.. OR you can save the new file to a variable.  Then return the results with CFCONTENT.  Just keep in mind the variable is stored in RAM.  So choose whichever option is best for your application.

<!--- extract the selected pages --->
<cfpdf action="merge" source="c:\pathTo\sourceFile.pdf" Pages="7, 10, 11" name="newData">
<!--- return them to the browser --->
<cfcontent type="application/pdf" reset="true" variable="#toBinary(newData)#">


BTW: There's an excellent 8 part series on CFPDF here
http://www.coldfusionjedi.com/index.cfm/2007/7/9/ColdFusion-8-Working-with-PDFs-Part-1
0
 

Author Comment

by:Errol Farro
ID: 33694696
Thanks a lot Agx. That's exactly what I need. Thanks for your help.
0
 

Author Closing Comment

by:Errol Farro
ID: 33694698
Thx again.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33697561
Welcome :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now