Solved

Print only selected pages of a PDF document (coldfusion)

Posted on 2010-09-16
11
564 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

705 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