Solved

Print only selected pages of a PDF document (coldfusion)

Posted on 2010-09-16
11
547 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

21 Experts available now in Live!

Get 1:1 Help Now