This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Export to PDF using server method - Not working

divya_p02 - Friday, April 5, 2013 2:20 AM:

i have created a server method to export datatable to pdf. the same code works in C# web application. When i run the same piece of code in ARAS, its throwing out errro...

 

Error says ;Server returned invalid SOAP message.%PDF-1.4
%??2 0 obj
<</Length 216/Filter/FlateDecode>>stream
x?}???0??{??????????k???????4??0NA??y (??????,V??sK%?bYg(?q?wI??w?j? ???/ _??,I?
????????.^?O4]?~??$??m???|???D}?C?;

 

Server Method Code

 Document pdfDoc = new Document(PageSize.A4, 10, 10, 90, 10);
    
        System.IO.MemoryStream mStream = new System.IO.MemoryStream();
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);

        PdfPTable table = new PdfPTable(3);
        pdfDoc.Open();
        PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));

        cell.Colspan = 3;

        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right

        table.AddCell(cell);

        table.AddCell("Col 1 Row 1");

        table.AddCell("Col 2 Row 1");

        table.AddCell("Col 3 Row 1");

        table.AddCell("Col 1 Row 2");

        table.AddCell("Col 2 Row 2");

        table.AddCell("Col 3 Row 2");

        pdfDoc.Add(table);
        pdfDoc.Close();
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Datatable.pdf");
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.BinaryWrite(mStream.ToArray());
        HttpContext.Current.Response.End();

 i have included itextsharp dll in bin folder of server and also name spaces for C# in method-config file.

 

Kindly help in this regard

Divya



gks by TSI - Monday, April 8, 2013 10:10 AM:

Your code works well, it's creating an PDF with the PDF-Standard 1.4 and i assume a length of 216 characters.

But not the sender is the problem.

The receiver (aras) does not understand what is produced by:

        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Datatable.pdf");
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.BinaryWrite(mStream.ToArray());
        HttpContext.Current.Response.End();

This does not work, as the aras client expects a SOAP-Message, not a PDF.

You need another way to transfer the file.



divya_p02 - Tuesday, April 9, 2013 5:48 AM:

Hi,

I tried small piece of sample code below. But still its not creating .PDF file. But same code runs in C# application.

Document myDocument = new Document(PageSize.A4);
PdfWriter.GetInstance(myDocument, new System.IO.FileStream(@"D:abc.pdf", FileMode.Create));
myDocument.Open();
myDocument.Add(new Paragraph("First Pdf File using iText"));
 

Even this is not working. Can you suggest any other method.

 

Regards,
Divya