By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

How to print the pdf file using binarywrite method in asp?

P: n/a
how can i print the pdf file using binarywrite method in asp.i can print the text file using Response.binarywrite method but i cnat print the pdf files
Nov 3 '10 #1
Share this Question
Share on Google+
2 Replies


jhardman
Expert 2.5K+
P: 3,405
in the asp insights section there is an article on saving files from uploads, that has everything you will need.

Jared
Nov 3 '10 #2

P: 1
You'll need to set Response.ContentType to "application/pdf".

You may also need to supply a dummy filename and set the "content-disposition" header to "attachment", or "inline", depending on the desired behavior...

Expand|Select|Wrap|Line Numbers
  1. <%@ Import Namespace="WebSupergoo.ABCpdf7" %>
  2. <%
  3. Doc theDoc = new Doc();
  4. theDoc.FontSize = 96;
  5. theDoc.AddText("Hello World");
  6. byte[] theData = theDoc.GetData();
  7. theDoc.Clear();
  8.  
  9. Response.ContentType = "application/pdf";
  10. Response.AddHeader("content-length", theData.Length.ToString());
  11. Response.AddHeader("content-disposition", "attachment; filename=ExampleSite.pdf");
  12. Response.BinaryWrite(theData);
  13. Response.End();
  14. %>
  15.  
The above ASP example is written in CSharp and makes use of the ABCpdf.NET component. I've done this to show how easy it can be to generate a PDF dynamically from within ASP (although any other PDF component should do). Otherwise, trying to manually construct a PDF from scratch is really hard work.

A few PDF components...
Nov 11 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.