Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Print only selected pages of a PDF document (coldfusion)

Posted on 2010-09-16
11
Medium Priority
?
573 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
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

 
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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
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 …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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