While trying to upload the PDF on server. and it is uploading the blank PDF
on server. Following is the code:

$.ajax({                                        
                                url: "test.jsp",
                                type: 'POST',
                                data: 'name='+titleLabel.getText()+'&content=' +
data.mydata.length+imgdata,            
                                success: function(data){                        
        
                                        console.log(data);
                var serviceUrl =
getUrl("/sap/opu/odata/sap/Y_UPLOAD_FILE_SRV/?$format=xml");                    
                                        
                                                
        getToken(serviceUrl,function(userToken){                                
                        
                                
uploadPDFFile(data,userToken,titleLabel.getText());
                                                        
                                                });
                                },
                                error: function (request, textStatus, 
errorThrown) {                                    
                                   console.log(errorThrown);
                                  busy.close();
                                } 
                });

//////Code of test.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<%@ page import="javax.servlet.*,
javax.servlet.http.*,java.io.*,java.util.*"%>
<%@ page import= "java.io.FileOutputStream"%>
<%@ page import= "java.io.*, javax.sql.rowset.serial.SerialBlob"%>

<%@ page import= "com.itextpdf.text.Document, com.itextpdf.text.Paragraph"%>
<%@ page import= "com.itextpdf.text.DocumentException"%>
<%@ page import= "java.sql.Blob, java.sql.SQLException"%>
<%@ page import= "com.itextpdf.text.pdf.*, com.itextpdf.text.Image,
com.itextpdf.text.pdf.codec.Base64"%>
<%

response.setContentType("application/pdf");
String filename = request.getParameter("name")+".pdf";
String totalImg = request.getParameter("content");

//response.setHeader("Content-Disposition", "attachment; filename=\"" +
filename + "\"");

%>


<%
Document document = new Document();
try{
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, buffer); 
        document.open();
        int len = Integer.parseInt(totalImg);
        for (int i=0; i<len; i++)
        {
                String data = request.getParameter(&quot;Image&quot;+i);
                int start = data.indexOf(&quot;,&quot;);
                data = data.substring(start + 1);
                Base64 base64obj= null;
                
                Blob blob = new  SerialBlob(base64obj.decode(data));
                Image token = Image.getInstance(blob.getBytes(1, (int) 
blob.length()));
                int k = i+1;
                document.add(new Paragraph(&quot;00&quot;+k));
                document.add(token);
        }
        
        document.close();
        
    
        DataOutput dataOutput = new 
DataOutputStream(response.getOutputStream());
    byte[] bytes = buffer.toByteArray();
        response.setContentLength(bytes.length);
        for(int i = 0; i &lt; bytes.length; i++)
        {
                dataOutput.writeByte(bytes[i]);
        }

} 

catch(DocumentException e){
        e.printStackTrace();
}

%>
/// upload function in javascript

function uploadPDFFile(pdfContent,userToken,filename) {
        var uploadUrl = getUrl("/sap/opu/odata/sap/Y_UPLOAD_FILE_SRV/Files/");
        
        
        console.log("Token :"+userToken);
        console.log("Content :"+pdfContent);
        $.ajax({                                        
        url: uploadUrl,
        type: 'POST',
        data: pdfContent,
        beforeSend: function (request)
        {
            request.setRequestHeader("x-csrf-token",userToken); 
            request.setRequestHeader("slug",filename);            
            request.setRequestHeader("Content-Type","application/pdf");         
                
        },

        success: function(data, textStatus, request){  
                console.log("UPload Succes");
                console.log(data);
                console.log(textStatus);
                console.log(request);
                updateFolderDetail(TripId);
                
                document.getElementById("submitBtn").value = "Re-submit"; 
                jQuery.sap.require("sap.m.MessageBox");
                
                sap.m.MessageBox.alert(
                              "Your photos have been uploaded to SAP TEM as a 
PDF and can
now be attached to your expense report. Please arrange receipts in SAP TEM
in the same order as the photos in the PDF.",
                              function() {
                                  //do something on OK click
                              },
                              " "                     
                                 );
            //var token = request.getResponseHeader('x-csrf-token');
            //callback(token);
        },
        error: function (request, textStatus, errorThrown) {            
           console.log(errorThrown);
        } 
                 });



Please suggest.

Thanks
Preety  

                                



--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Uploading-PDF-file-to-server-tp4659197.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to