I have two pdfs created using XFA pdf and then flattened.
When I try to concatenate these pdfs, the concatenation works however it loses the data in the pdf.
I tried trying to concatenate using Files, Streams and all options out there.
Help Appreciated.
Is data getting lost even after you flatten the PDF? Can you please share your sample PDFs for our reference? We will test the scenario in our environment and address it accordingly.
Hello Asad,
Please find attached the files I am trying to concatenate.
Below is the code used for Flattening.
private void TestSomething(string inputFile,string fnameppt)
{
//var inputFile = @"C:\DEV\FillFormField_out.pdf";
//string fnameppt = @"C:\DEV\FillFormField_out_New.pdf";
{
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(inputFile);
using (MemoryStream pptStream = new MemoryStream())
{
pdfDoc.Flatten();
pdfDoc.OptimizeSize = true;
pdfDoc.IsLinearized = true;
pdfDoc.Optimize();
//pdfDoc.Form.Type = FormType.Standard;
pdfDoc.Save(pptStream, Aspose.Pdf.SaveFormat.Pdf);
File.WriteAllBytes(fnameppt, pptStream.ToArray());
File.Delete(inputFile);
}
}
}
Below are the various ways I tried to concatenate, all works in concatenating but data is lost.
public void ConcatenateFiles(string dataDir, string crashId)
{
//License license = new License();
//license.SetLicense("Aspose.TotalAspose.Total.lic");
SetLicense();
PdfFileEditor pfe = new PdfFileEditor();
string[] files = Directory.GetFiles(dataDir);
pfe.CopyOutlines = false;
pfe.Concatenate(files, dataDir + string.Format("{0}.pdf",crashId));
}
public void ConcatenameWithStream(string dataDir, string crashId)
{
// For complete examples and data files, please go to [https://github.com/aspose-pdf/Aspose.Pdf-for-.NET](https://github.com/aspose-pdf/Aspose.Pdf-for-.NET)
// The path to the documents directory.
//string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Pages();
PdfFileEditor pfe = new PdfFileEditor();
string[] files = Directory.GetFiles(dataDir);
// Create PdfFileEditor object
PdfFileEditor pdfEditor = new PdfFileEditor();
// Output stream
FileStream outputStream = new FileStream(dataDir + "ConcatenateArrayOfPdfUsingStreams_out.pdf", FileMode.Create);
// Array of streams
FileStream[] inputStreams = new FileStream[2];
for(int i = 0; i < files.Length; i++)
{
inputStreams[i] = new FileStream( files[i].Trim(),FileMode.Open);
}
//inputStreams[0] = new FileStream(dataDir + "input.pdf", FileMode.Open);
//inputStreams[1] = new FileStream(dataDir + "input2.pdf", FileMode.Open);
// Concatenate file
pdfEditor.Concatenate(inputStreams, outputStream);
outputStream.Close();
}
public void ConcatenateAnotherWay(string dataDir, string crashId)
{
string[] files = Directory.GetFiles(dataDir);
// Open first document
Document pdfDocument1 = new Document(files[0]);
// Open second document
for(int i = 1; i < files.GetLength(0); i++)
{
Document pdfDocument2 = new Document(files[i]);
pdfDocument1.Pages.Add(pdfDocument2.Pages);
}
// Add pages of second document to the first
dataDir = dataDir + "ConcatenatePdfFiles_out.pdf";
// Save concatenated output file
pdfDocument1.Save(dataDir);
}
Thanks,
Kasturi Mohan
200000001_1_New.pdf (1.78 MB)
200000001_2_New.pdf (1.78 MB)
We tried to flatten the PDF documents before merging them but it looked like the API was unable to flatten them. Can you please share the output generated at your end along with the screenshot of the lost data in the output so that we can further compare the results with the ones produced at our end and address the issue accordingly?
Asad,
The Pdfs I sent is the result of flattening.
I have attached what we get once concatenated.
Is this what you are looking for?
Thanks,
Kasturi Mohan
200000001200000001.pdf (2.05 MB)
By simple merging the PDFs in our environment using Aspose.PDF for .NET 23.7 and below code snippet, we got the attached output that looks fine.
var doc1 = new Document(dataDir + "200000001_1_New.pdf");
var doc2 = new Document(dataDir + "200000001_2_New.pdf");
doc1.Pages.Add(doc2.Pages);
doc1.Save(dataDir + "mergedpdfs.pdf");
mergedpdfs.pdf (1.9 MB)
Can you please try using the latest version of the API with the above code and let us know in case issue still persists.
Hello Asad,
The pdf attached does not have the merged pdf, it still has only one of the pdf file, the other one has not concatenated.
Thanks,
Kasturi Mohan
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-55252
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.