Binary Data to PDF
Dear All,
I need some assistance in here. There is another system that changes the PDF file into Binary format (RAW) into a table in a field called LRAW. How do I convert the Binary Data which is stored in LRAW format back into PDF?
Any clues or hints would be helpful and if you do have some sample codes I could refer to would even be better.
Thank you in advance.
Hi Durairaj,
I have a FM "CVALE_CHECKOUT_TO_TABLE" which returns a table with data type LRAW.
I need to convert this data into PDF.
How will I able to convert this into binary ??
I need a PDF output.
regards,
Vaibhav
Similar Messages
-
Convert TIF Binary data to PDF Binary data
Hi All,
I have uploaded TIF file into table in system in Binary format.
I need to create a spool from this Binary data, the spool should open in TIF format or PDF format.
Can you help me in doing this.
As I knw how to convert PDF to Spool, it would be even helpful, if you tell me how to convert TIF binary data into PDF binay data.
Thanks in advance.
AbhayHi Sandra,
Below is the requirement from Client:
1. PDF and Tif files will be attached to order (transaction CRMD_ORDER).
2. I have to pick the PDF and TIF attachments mentioned above using a batch report.
3. Then this batch report will create a spool for the PDF file and TIF file attachements.
4. Then the spool will be picked by another program and print them together in night.
I hope it is clear now?
Things I have done:
1. Created report ZPDF_TIF which is copy of RSPO0023.
1. Used the report ZPDF_TIF to pick up the PDF and TIF file in binary format from the order (transaction CRMD_ORDER).
2. Able to Convert PDF to spool.
I hve problem for:
1. I want to use the program ZPDF_TIF to work for both PDF and TIF file.
2. I have the TIF data in Binary (1022) into internal table picked using the report ZPDF_TIF.
2. I want to convert TIF to spool which is problem child for me as of now.
I hope the details are clear now. -
How to convert binary data to PDF and attach to the particular po
our client wants to attach the pdf coming from portal as attachment to that particular PO. From portal the pdf will come in binary format. Find how will we convert that binary data back to pdf and attach to the PO in R/3?
Hi,
You can downlaod Binary data into PDF using GUI_DOWNLOAD...pass the binary data and the BINSIZE...
santhosh -
Convert Binary Data into Pdf & send it as attachment in a mail in Workflow
Hi,
Scenario:
The interactive form saved in WebDynpro Application is sent to R/3 in binary format. It has to be converted into pdf and sent it as an attachment in mail to the respective person in workflow.
Kindly help on these issues :
1. How to receive the binary data in R/3 sent by the WebDynpro Application ?
To my knowledge we can receive the binary in XSTRING data type. Plz correct me if am wrong.
2. How do i convert the received binary data into pdf ?
Thanks,
Bharath KaushikHi Bharath,
I think you should try to write dat being sent to R/3 to spool first, as in R/3 there is FM <i>CONVERT_ABAPSPOOLJOB_2_PDF</i> , with the help of which you will be able to convert Binary data to PDF format.
Pls find one of the threads related to this , and see if this is useful to you.
Problem in CONVERT_ABAPSPOOLJOB_2_PDF.
Hope this atleast helps to start off.
Regds,
Akshay Bhagwat
PS: Some points would be nice if it helps:) -
Convert Binary Data into Pdf & send it as attachment in a mail
Hi Friends,
Scenario :
The interactive form saved in WebDynpro Application is sent to R/3 in binary format. It has to be converted into pdf and sent it as an attachment in mail to the respective person.
Kindly help on these issues :
1. How to receive the binary data in R/3 sent by the WebDynpro Application ?
2. How do i convert the received binary data into pdf ?
Regards & Thanks,
Bharath Kaushik KrishnanCheck thread Data Conversion
if it is useful for you. -
Convert Binary Data into Pdf & send it as attachment in a mail from R/3
Hi,
Scenario:
The interactive form saved in WebDynpro Application is sent to R/3 in binary format. It has to be converted into pdf and sent it as an attachment in mail to the respective person in workflow.
Kindly help on these issues :
1. How to receive the binary data in R/3 sent by the WebDynpro Application ?
To my knowledge we can receive the binary in XSTRING data type. Plz correct me if am wrong.
2. How do i convert the received binary data into pdf ?
Thanks,
Bharath Kaushik KrishnanHI Bharath,
I think You can reuse teh XString for binary data.there are certain function modules in R/3 for creating pdf/for sending it as pdf attatchment.please search in abap forums you will find more information
With Regards
Naidu -
Converting binary data into pdf and placing into application server
Hi Friends,
I am able to get PO details in binary format and then using GUI_DOWNLOAD with file type with 'bin' and file name with 'sample.pdf' extension , got PO in pdf format.
But i need to get with pdf extension in application server without using GUI_DOWNLOAD.
Is there any functional modules for it?
With Warm Regards,
Madhu!!!Hi Madhu,
Check this code.
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
Write statement to represent report output. Spool request is created
if write statement is executed in background. This could also be an
ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
Alternative way could be to submit another program and store spool
id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
to sap-spool
spool parameters %_print
archive parameters %_print
without spool dynpro
and return.
Get spool id from program called above
IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
FORM get_job_details *
FORM get_job_details.
Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
perform send_email using p_email2.
ENDFORM.
FORM send_email *
--> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
Hope this resolves your query.
<b>Reward all the helpful answers.</b>
Regards -
Printing binary data in PDF format
HI all,
Any idea on how to print Binary content in a PDF format
I have read a PDF format from application server in a Binary format, I need to print the binary content on a printer in PDF format
Any help on this is appreciated <REMOVED BY MODERATOR>
Thanks
Aakash
Edited by: Alvaro Tejada Galindo on Jun 9, 2008 3:15 PMHi papick,
this may be easier than expected for a million dollar erp system:
You need a PDF printer.
When I played around with adobe interactive forms our basis guys created a new printer in SPAD with
Device Attributes
Device Type PDF1
Device Class Stabdard Printer
location PDF-Frontend printer = Standard printer for workstation
Access Method
Host Spool Access Method FF
Host printer PDF
Then need some expremimenting with Functions
RSPO_OUTPUT_DEVICEDATA Spool Output Control of an Internal Table with Formatted Data
or something alike (see function group SPOD)
Then you should be able to create an entry in spooler (SP01) with spool request type adobe pdf document.
Sorry, I don't have this problem, thus I did not check out the details yet.
But I'm convinced it should work that way because the ADS server creates a complete PDF binary and it can be printed using the above described printer - actually a HP Laserjet V was configured as frontend printer and it can print the pdf.
Regards,
Clemens -
Binary Data to PDF and Word Doc
All,
We have requirement to open a PDF or DOC in a new window from a BAPI output structure. The field returned from the BAPI is a binary field. Following is the code that is implemented for this scenario.
for(int i=0;i<wdcontext.nodeOutput().nodePtx_Drao().size();i++)
IWDCachedWebResource resource = WDwebResource.getWebResource(wdcontext.nodeOutput().nodePtx_Drao().getPtx_DraoElementAt(i).getOrblk(), WdWebResourcetype.PDF);
IWDWindow win = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.getUrl(WDFileDownloadBehaviour.OPEN_PLACE.ordinal()), "test");
win.open();
The problem we are facing here is when we try to open the PDF it throws an error saying "File does not begin with '%PDF-'". If we try to open a word document by changing the resource type some junk values are coming.
Has anyone come across this type of development issues?
Appreciate all your replies and new inputs in this regard.
Thanks & Regards,
Nagarajan.Hi,
I also tried with the same using the below code. Even I am getting the same error.
byte[] test=new byte[9];test[0]=2;
IWDCachedWebResource resource = WDWebResource.getWebResource(test,WDWebResourceType.PDF);
When i tried the same code with other file type its working file.
IWDCachedWebResource resource = WDWebResource.getWebResource(test,WDWebResourceType.DOC);
From where are you getting this actual byte array? from R/3?. In internet if you search about this error we are getting the results like "The PDF file has a .mme extension rather than a .pdf extension".
Note: This is not the problem with Window or LinkToURL ui elments.
Posting this to give you an idea.
Regards,
Charan -
Sending binary data from JSP (1.1)
Hi all:
I am using Tomcat 3.2.1 and Apache under Linux Mandrake OS.
I have a JSP (1.1) sending binary data (GIF, PDF, DOC ..) using response.getOutputStream().write(data)
method.
The problem is the precompiler automatically creates the JspWriter and puts some out.write("\r\n") lines
before I use getOutputStream method. The JVM throws an IllegalStateException because I am using both
methods (this is from Servlet 2.2 specification).
Must I change my code to forwarding to a servlet that make this work or is there a simple solution to
avoid this?
Thanks in advance.
J.
nullHi Shreeharsha
Please refer to below docs for sending data from JSP page to RFC. In which you need to use sap connectors for connecting to SAP backend system.
http://help.sap.com/saphelp_nw04/helpdata/en/b6/55e3952a902447847066a0df27b0d6/content.htm
Hope it helps
Regards
Arun -
DETAIL_DATASTORE for binary data
can i put binary data like PDF,word doc in DETAIL_DATASTORE?
You should as this question in the Oracle Text forum, where you will get a more expert, quicker answer.
-
Map binary data (PDF) to XML not possible due to non-printable chars
Hi XI Gurus,
we have the following issue.
We send a PDF as binary data (as a hex string '25255044462D3' ) along with some other information from ERP within one RFC to XI , doing a message split 1:n for those two kind of messages (1. the PDF, 2. the XML) an send the split messages to file/ftp receiver adapter.
The message split and sending of the messages is working well, but we encounter some problems with non-printable chars (hex code below 0x20) in the pdf binary. The PDF data and the dynamic file name is mapped into an XML. But the non printable characters are converted into '#' when mapped into the XML target field.
(Due to the 1:n multi mapping, we cannot put the filename into dynamic configuration, so we have to map the pdf and the filename into an XML and extract the content with variable substitution in receiver file adapter....)
My question is: how can binary data with non-printable chars be sent through XI and can be mapped into an XML without beeing replaced by '#' ?
Any help will be greatly appreciated.
Thanks and regards
HolgerMaybe I didn´t explained it clearly enough.
We do not have the issue that the RFC puts the '#' into the string. We got from the RFC a hex string containing the pdf as visible hex values like:
As you can see we have the pdf as hex string. During message mapping XI replaces some non-printable chars like '0x04' or '0x19' with '#'.
My question is: how can we avoid those char replacement ?
BTW: I grabbed a pdf with sender file adapter, routed through XI without any mapping and send it with ftp in binary mode. But the pdf contains more chars as the origional file and the pdf content is not visible when opening with a pdf reader like Acrobat. I guess the file adpter has problems with carriage return and linefeed chars. Some CR and LF are replaced inserted somehow.
Best regards,
Holger -
Smart forms convert to pdf binary data
Dear All,
I'm working on smart forms integrations with .net and I need to send the smart forms PDF binary data though custom rfc .
For that i'm converting smart forms otf data to pdf in and pass this data through rfc but this idata is is not wokring on .net guys when they are converting this on pdf..
so is there any need of decoded smart forms otf data before passing through or i'm missing some basic step?
Please guide me?
Rg
Anujhi,
Have a look on this wiki:
[http://wiki.sdn.sap.com/wiki/display/Snippets/SmartformoutputtoPDFformat]
And maybe this one could also interest you:
[|http://wiki.sdn.sap.com/wiki/display/Snippets/SmartformtoMailasPDF+attachment]
regards
mickael -
How to extract binary data from a File?
Hello there!
Hope I'm right here.
I have a slight problem with a file containing text- and binary-data. At the beginning of the file is only some text followed by some html-code and at the end is some binary stuff like a pdf oder an image (jpg/gif).
My problem is now how to split these parts and save them in the suitable format. The text and the html are no problem, but I don't know how to extract the binary data. I tried it out with an Inputstream, but I don't know how to find the exact position where the binary data begins.
Anyone have an idea how I can solve this?
Thanks in advance and sorry for my bad english.I don't believe a bullet-proof solution exists.
If you know where the HTML ends, you may skip whitespace and then assume the rest is binary data. Or, if you know the first bytes of the binary data, you may locate those. With either of these solutions, though, you risk coming across a file where it doesn't work as expected, for example if the first byte of the binary data happens to match a whitespace character. -
Download file problem for binary data?
Dear All,
I have wrote a jsp file to do download page. I have used a piece of code from the JDC to this. This code will prompt the download dialog box each time user clicks the download button. The code itself will set the content type for different application. The code is like below:
try
java.io.File fileobj = new java.io.File(strFolder + strFile);
response.setContentType(application.getMimeType(fileobj.getName()));
response.setHeader("Content-Disposition","attachment; filename=\""
+ strFile + "\"");
java.io.FileInputStream in = new java.io.FileInputStream(fileobj);
int ch;
while ((ch = in.read()) != -1) {
out.write(ch);
out.flush();
in.close();
} catch(Exception e)
The code can download and handle text file correctly when it is openned in the text editor or inside the IE. But when a PDF file or Image is downloaded and openned in the PDF viewer or image viewer, it is corrupted and cannot be viewed. What is the problem? Any ideas?
So, I wonder this code can handle binary data or not. It is seen like there is no different code to handle text and binary data in Java/Jsp.
Thank you very much!
Best Regards,
Rockyu Lee
Add following lines to .tld file (custom tag definition)
<tag>
<name>downloadbinary</name>
<tagclass>org.rampally.DownloadBinaryTag</tagclass>
<bodycontent>JSP</bodycontent>
</tag>
Add following line to JSP files.
In JSP, keep one line of source. Make sure that there are no space and additional line feeds at the any where
in the JSP files except JSP tags.
<%@ taglib uri="/WEB-INF/taglibs/mb.tld" prefix="mytags" %>
<mytags:downloadbinary />
I am hoping that you have all required parameters such as fileName to download, etc.
in your session or request object.
Tag class ....
public class DownloadBinaryTag extends TagSupport {
public int doEndTag() throws JspException {
// TODO: get binary data from filename or
// binary data buffer from datase.
// I am making it simple .. assume that it is a request parameter for
// you test easily.
String fileName = request.getParameter( "filename" );
java.io.File file = new java.io.File( fileName);
java.io.DataInputStream dis;
try {
dis = new java.io.DataInputStream(new FileInputStream(fileName));
} catch (FileNotFoundException e) {
// do error handling ...
return EVAL_PAGE;
BinaryUtil.sendBinaryFile( dis, (HttpServletResponse) pageContext.getResponse(), contentType );
return EVAL_PAGE;
public class BinaryUtil
static public void sendBinaryFile( DataInputStream dis,
HttpServletResponse response,
String contentType ) {
try {
response.setContentType(contentType);
String fileName="test.pdf";
response.setHeader("Content-disposition", "inline; filename=" + newFileName );
ServletOutputStream sout = response.getOutputStream();
int len;
byte[] data = new byte[128 * 1024];
while ((len = dis.read(data, 0, 128 * 1024)) >= 0)
sout.write(data, 0, len);
sout.flush();
sout.close();
} catch (Exception e) {
System.out.println(e.getMessage());
static public void sendBinaryFile( byte[] data,
HttpServletResponse response,
String contentType ) {
try {
response.setContentType(contentType);
String fileName="test.pdf";
response.setHeader("Content-disposition", "inline; filename=" + newFileName );
ServletOutputStream sout = response.getOutputStream();
sout.write(data);
sout.flush();
sout.close();
} catch (Exception e) {
System.out.println(e.getMessage());
You may have to change 'inline' to 'attachment' if you do not want IE to inline the document.
That's all!!.. Hope this helps...!
Maybe you are looking for
-
Everytime I print a doc, I can select to print a single page but right after that selection an HP print window opens and the only option is Start Printing or Cancle Printers. The upper border of the popup says " HP Officejet 6500 "
-
How do I make a word doc to PDF
How do I make a work doc. to PDF
-
Upgrade Windows 8.1 to Pro Issue
I am trying to upgrade my Windows 8.1 machine to pro. I am doing this via DVD and product key I purchased. When I try to perform the upgrade the only option I get when I am asked, "Choose what you want to keep" is nothing. I would like to keep everyt
-
(South wales) Very bad Broadband Speed, please he...
Hi there guys. First off i tryed reading the stickies and didnt find anything that helped me. Ill explain whats going on. Ive only been with Bt for about 2 months, the told me that i can get 3.Mbps on my Line, so ofc i have 2.5 but only 0.5 of a
-
I can't open Photoshop Elements 11 after a redownload.
I am trying to redownload Photoshop Elements 11 on my new PC. There are 2 files to download. I can't download the second file, nor can I open it. I get an error message that says I am missing the "archive file part." What do I do?