Solved

Print only selected pages of a PDF document (coldfusion)

Posted on 2010-09-16
11
549 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

15 Experts available now in Live!

Get 1:1 Help Now