I am trying to concatenate two System.IO.Streams that I get from Crystal Reports
Hi Robert,
Thank you for the sample code, can you please share PDF documents after saving from memory streams. This will help us to investigate the exact issue and reply back to you soon.
We apologize for your inconvenience.
Thanks & Regards,
Attached is my sample pdf
Hi Robert,
Thank you for sharing the template PDF document.
I have tested your scenario with your template file and sample code of Aspose.Pdf.Facades and it works fine (attached is the resultant file for your reference).
Please feel free to contact support in case you need any further assistance.
Thanks & Regards,
Hello Eric,
I too am using v6.4.2
Hello Eric,
// create
MemoryStream object for first file
MemoryStream
memStream1 = new MemoryStream();
using
(FileStream fileStream = File.OpenRead(@“D:\pdftest\t.pdf”)
{
//
set the memorystream lenght equal to input file length
memStream1.SetLength(fileStream.Length);
fileStream.Read(memStream1.GetBuffer(), 0, (int)fileStream.Length);
}
MemoryStream
memStream2 = new MemoryStream();
using
(FileStream fileStream = File.OpenRead(@"D:\pdftest\Copy
of t.pdf"))
{
memStream2.SetLength(fileStream.Length);
fileStream.Read(memStream2.GetBuffer(), 0, (int)fileStream.Length);
}
Aspose.Pdf.Facades.PdfFileEditor edt;
//output
stream
MemoryStream
outputStream = new MemoryStream();
try
{
edt = new
Aspose.Pdf.Facades.PdfFileEditor();
edt.Concatenate(memStream1, memStream2,
outputStream);
// return pdfOutput;
}
catch
(Exception ex)
{
throw
new ApplicationException(null, ex);
}
finally
{
lic = null;
edt = null;
memStream1.Close();
memStream2.Close();
}
MessageBox.Show(outputStream.Length.ToString());
// Now we
need to save the contents of Output MemoryStream to PDF file
FileStream
fs = File.OpenWrite(@"D:\pdftest\Resultant-Concatenated.pdf");
// save
the contents of MemoryStream to FileStream object
fs.Write(outputStream.ToArray(),0,(int)outputStream.Length);
// close
the fileStream object
fs.Close();
// close
memorystream object holding merged document.
outputStream.Close();
I am getting closer...
I am guessing my original problem had to do with the way I was creating a second pdf from Crystal Reports. I think there were some pointer issues that was preventing the concatenation from working. I created a second, seperate report and I get a step further. The concatenation works and I can create a pdf that can be saved to disk and viewed. I am tyring however to output the concatenated stream to the web browser and have Adobe open. This works fine with the single pdf created from Crystal Reports. The Concatenated pdf throws the following error:
File does not beign with '%PDF-'.
For some reason the concatenated pdf causes this?
Also, I should add that I am now using Aspose.Pdf v6.5.0.0
Hi Eric,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for the details.
However, to exactly replicate your issue at our end, we would appreciate it if you can create a sample web application with your template files and post here to show us the issue. This will help us regenerate the issue and get to the cause of the issue soon.
Sorry for any inconvenience caused,
Attached is the sample project which shows the error
I tried this with the older Aspose.Pdf.Kit v6.0.0.0 and everything works fine. Looks like an issue with the new dll
Hi Eric,
Thank you for the sample applicatoin, kindly add Response.AddHeader line in "Page_Load" method as mentioned below. By adding this line of code, error "File does not begin with '%PDF-'" is not coming.
[C#]
protected void Page_Load(object sender, EventArgs e)
{
byte[] buffer;
System.IO.Stream _ReportStream;
_ReportStream = Merge();
buffer = new byte[_ReportStream.Length];
_ReportStream.Read(buffer, 0, buffer.Length);
System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=ConversionResult.pdf;");
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString());
System.Web.HttpContext.Current.Response.BinaryWrite(buffer);
}
Please feel free to contact support in case you face any problem.
Thanks & Regards,
I added the line of code you suggested and now I see two new items
1) I am promted to save or open the pdf (where with pdf.kit it just opens the pdf)
2) If I open the pdf I get an error in Adobe: "Adobe reader could not open 'ConversionResult[1].pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded). If I choose the save option then try to open the file I get the same error again. I have attached the file that was saved.
Hi Robert,
Thank you for sharing the sample application and resultant document. I have tested the scenario and I am able to notice the same problem. For the sake of correction, I have logged this problem as PDFNEWNET-32674 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction.
We apologize for your inconvenience.
Thanks & Regards,
The issues you have found earlier (filed as PDFNEWNET-32674) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.