We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cannot open Merged PDF

Hi,

We have a .net service which downloads multiple PDFs (based on user input) from a sharepoint website and merges them into a single PDF.
We have an issue where the user chooses to view a single PDF. The user is unable to view the generated PDF using Adobe reader 8. (Adobe Reader 9 works fine). However the users desktop is committed to using Adobe Reader 8 for the near term. The user has no issues opening the original PDF file from the sharepoint site.

I have uploaded both the PDF files.

Aspose also seems to shrink the file sizes.

Code to merge the files



public void GenerateMemoryStream(DocFormsInput AODocFormsInput, out MemoryStream outputMemoryStream, out DocFormsOutput AODocFormsOutput)
{
string strError = string.Empty;
outputMemoryStream = new MemoryStream();
AODocFormsOutput = new DocFormsOutput();
AODocFormsOutput.StatusInfo = new List();

MemoryStream docCoverPageStream = null;
MemoryStream mstrFileOne = null;
MemoryStream mstrFileTwo = null;
DateTime dtStartTime = DateTime.Now;

try
{

Document pdfDocument1 = null;
//If strInputXML is null or empty, do not generate Doc Cover Page
if (!string.IsNullOrEmpty(AODocFormsInput.strInputXml))
{
//Generate Doc Cover Page

GenerateDocumentCoverPage(AODocFormsInput.strDocType, AODocFormsInput.strInputXml, out docCoverPageStream, out strError);
pdfDocument1 = new Document(docCoverPageStream);
AODocFormsOutput.TimeRequired_DocCoverPageGeneration = ((TimeSpan)DateTime.Now.Subtract(dtStartTime)).ToString();
}

//Need to check sourcefiles array atleast contains 1 pdf
if (AODocFormsInput.strSourceFiles != null && AODocFormsInput.strSourceFiles.Length > 0)
{
if (string.IsNullOrEmpty(strError))
{
for (int pdfCnt = 0; pdfCnt < AODocFormsInput.strSourceFiles.Length; pdfCnt++)
{
if (pdfDocument1 == null)
{
try
{
//pdf document 1 will be the first string in strSourceFiles[]
//byte[] strFileOne = client.DownloadData(AODocFormsInput.strSourceFiles[pdfCnt]);
byte[] strFileOne = GetDocument(AODocFormsInput.strSourceFiles[pdfCnt], AODocFormsInput.strUserName, AODocFormsInput.strPassword, AODocFormsInput.strDomain);
mstrFileOne = new MemoryStream(strFileOne);
pdfDocument1 = new Document(mstrFileOne);
}
catch (Exception)
{
StatusInfo status = new StatusInfo();
status.Severity = “W”;
status.BusinessDescription = " Unable To DownLoad file " + AODocFormsInput.strSourceFiles[pdfCnt];
status.Code = “PDF_MERGER_1007”;

AODocFormsOutput.StatusInfo.Add(status);
}
}
else
{
if (!string.IsNullOrEmpty(AODocFormsInput.strSourceFiles[pdfCnt]))
{
try
{
//byte[] strFileTwo = client.DownloadData(AODocFormsInput.strSourceFiles[pdfCnt]);
byte[] strFileTwo = GetDocument(AODocFormsInput.strSourceFiles[pdfCnt], AODocFormsInput.strUserName, AODocFormsInput.strPassword, AODocFormsInput.strDomain);
mstrFileTwo = new MemoryStream(strFileTwo);
Document pdfDocument2 = new Document(mstrFileTwo);
pdfDocument1.Pages.Add(pdfDocument2.Pages);
}
catch (Exception)
{
StatusInfo status = new StatusInfo();
status.Severity = “W”;
status.BusinessDescription = " Unable To DownLoad file " + AODocFormsInput.strSourceFiles[pdfCnt];
status.Code = “PDF_MERGER_1007”;

AODocFormsOutput.StatusInfo.Add(status);
}
}
}

}
}
else
{
StatusInfo status = new StatusInfo();
status.Severity = “E”;
status.BusinessDescription = strError;
status.Code = “PDF_MERGER_1008”;

AODocFormsOutput.StatusInfo.Add(status);
}
}

AODocFormsOutput.TimeRequired_DownloadAndMergePDFs = ((TimeSpan)DateTime.Now.Subtract(dtStartTime)).ToString();
pdfDocument1.HideToolBar = false;
pdfDocument1.Save(outputMemoryStream);
pdfDocument1.Dispose();



}
catch (Exception ex)
{
StatusInfo status = new StatusInfo();
status.Severity = “E”;
status.BusinessDescription = ex.Message;
status.Code = “PDF_MERGER_1009”;

AODocFormsOutput.StatusInfo.Add(status);
}
finally
{

if (docCoverPageStream != null)
{
docCoverPageStream.Close();
docCoverPageStream.Dispose();
}
if (mstrFileOne != null)
{
mstrFileOne.Close();
mstrFileOne.Dispose();
}
if (mstrFileTwo != null)
{
mstrFileTwo.Close();
mstrFileTwo.Dispose();
}

}

}

------------

Hi Padmanabhan, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.Pdf.

Please share your template PDF files which are used in the merging process for our testing. We will check your issue and get back to you soon.

Sorry for the inconvenience,

The PDF files are attached in the post itself.
I am uploading again.

Hi Padmanabhan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the confirmation.

We will check your issue with Adobe Acrobat version 8 and share our test results with you soon.

Sorry for the inconvenience,

Any update on this issue?
We are due to move to production in a few days and this issue is a showstopper for us.

Hi Padmanabhan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for being patient.

I have tested the issue with Adobe Acrobat Reader 8.0 and I am able to reproduce the issue you mentioned. I have registered the issue in our issue tracking system with issue id: PDFNEWNET-34555 for further investigation from the development team. We will notify you via this forum thread regarding any updates against your reported issue.

Sorry for the inconvenience,

Hi,

Any update on this issue?
This is holding up our release. We need an answer ASAP.

Hi Padmanabhan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Our development team is still working on your issue. However, please try the following work around and let us know if it works fine with Adobe Acrobat 8 at your end. I checked this and it works fine at my end. You can simply merge the pages from your input documents to a new document as done in the below code.

//open first document

Document pdfDocument1 = new Document(@"D:\input1.pdf");

//open second document

Document pdfDocument2 = new Document(@"D:\input2.pdf");

//add pages to new document object

Document doc = new Document();

doc.Pages.Add(pdfDocument1.Pages);

doc.Pages.Add(pdfDocument2.Pages);

//save concatenated output file

doc.Save(@"D:\output.pdf");

Please do let us know in case you still face any issue.

Sorry for the inconvenience,

We are already doing very similar to this code (and it does not work)…
The only difference is we get load document 2 from a memory stream instead of a file…


Document pdfDocument = new Document();
byte[] strFileOne = GetDocument(AODocFormsInput.strSourceFiles[pdfCnt], AODocFormsInput.strUserName, AODocFormsInput.strPassword, AODocFormsInput.strDomain);
mstrFileOne = new MemoryStream(strFileOne);
pdfDocument1 = new Document(mstrFileOne);
pdfDocument.Pages.Add(pdfDocument1.Pages);

Hi Padmanabhan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I tried the following code and used “BeneDesignationForm-Adobe.pdf” as template file. I am unable to reproduce the issue. I have attached the generated file for reference. Please create a sample application and share with us to help us identify the cause of the issue.

// Create a FileStream object to read the file

FileStream fs = File.OpenRead(@"D:\BeneDesignationForm-Adobe.pdf");

// Read the file into Byte array

byte[] data = new byte[fs.Length];

fs.Read(data, 0, data.Length);

Document pdfDocument = new Document();

MemoryStream mstrFileOne = new MemoryStream(data);

Document pdfDocument1 = new Document(mstrFileOne);

pdfDocument.Pages.Add(pdfDocument1.Pages);

pdfDocument.Save(@"D:\BeneDesignationForm-next.pdf");

Sorry for the inconvenience,

We cannot open the PDF in the zip file using Adobe Reader 8.1.4 version.
BeneDesignationForm-Adobe.pdf is fine.
BeneDesignationForm-Aspose.pdf is not.

Our code also generates the same file 1237 KB.

Adobe Reader 8.1.4 cannot open this file.

Hi Padmanabhan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Well, the version of Adobe Reader I have on my machine is v8.0.0. I will look for the updated v8.1.4 and will share the results with you.

Sorry for the inconvenience,

Any update on this?
Were you able to recreate the issue with the proper version?

Hi Padmanabhan,


Thanks for your patience and sorry for replying you late.

I have tried viewing BeneDesignationForm-Aspose.pdf file which you have shared earlier and I am able to notice the error message when opening the file in Adobe Reader 8.1.3 and the issue does not seem to be occurring when viewing BeneDesignationForm-Adobe.pdf file.

However in order to reproduce this issue, I have created the copy of BeneDesignationForm-Adobe.pdf file and have tried to concatenate these two documents. When I have tired viewing the resultant PDF file in Adobe Reader 8.1.3, I am able to see the error message. For
the sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-34619. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We
apologize for your inconvenience.

Any update on this at all?
This has been open for more than a month without any progress.

This is no way to support a user. Even open source would have resolved faster than this.

Hi Padmanabhan,


Thanks for your patience.

You may consider using either of the following approaches to concatenate the PDF files. I have tested the scenario using Aspose.Pdf for .NET 7.6.0 and I am unable to notice any issue when viewing the resultant PDF in Adobe Reader 8.1.3.

Approach 1
[C#]

//open first document<o:p></o:p>

PdfFileEditor pfe = new PdfFileEditor();

pfe.Concatenate(new string[] { TestSettings.GetInputFile("34555-1.pdf"), TestSettings.GetInputFile("34555-1.pdf") },

TestSettings.GetOutputFile("34555-1.pdf"));


Approach 2
[C#]

//open first document

Document pdfDocument1 = new Document(TestSettings.GetInputFile("34555-1.pdf"));

//open second document

Document pdfDocument2 = new Document(TestSettings.GetInputFile("34555-1.pdf"));

//create new document

Document doc = new Document();

//add pages from 1st and 2nd documents to new document.

doc.Pages.Add(pdfDocument1.Pages);

doc.Pages.Add(pdfDocument2.Pages);

//pdfDocument1.Pages.Add(pdfDocument2.Pages);

//save concatenated output file

doc.Save(TestSettings.GetOutputFile("34555-2.pdf"));


Approach 3 (If converting to v. 1.3 is specified, then resultant file opens in Adobe Reader successfully)
[C#]

Document pdfDocument1 = new Document(TestSettings.GetInputFile("34555-1.pdf"));

//open second document

Document pdfDocument2 = new Document(TestSettings.GetInputFile("34555-1.pdf"));

//add pages of second document to the first

pdfDocument1.Pages.Add(pdfDocument2.Pages);

//save concatenated output file

pdfDocument1.Convert(TestSettings.GetOutputFile("34555-4.log"), PdfFormat.v_1_3, ConvertErrorAction.None);

pdfDocument1.Save(TestSettings.GetOutputFile("34555-4.pdf"));

The issues you have found earlier (filed as PDFNEWNET-34555;PDFNEWNET-34619) have been fixed in Aspose.Pdf for .NET 7.7.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.