PDF Services API: Merge issue

New Here ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

While combine/merging pdf files to single file it’s not merging in sequence, we are sending file list in sequence but however it’s not merging in sequence. Kindly let us know is there any option to merge the files in sequence.

 

Example,

10 individual pdf files (file1.pdf, file2.pdf, file3.pdf, file4.pdf…file10.pdf) needs to merge to single file (File.pdf). When we use PDF Services API, it’s not merging in correct order. File.Pdf should have form file1,file2,file3,file4…file10 in this order. But File.pdf it’s not in sequence it’s like file1,file3,file7,file3,etc. We need to single file as in order instead of out of sequence.

TOPICS
PDF Services API

Views

218

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 10, 2021 Nov 10, 2021

Copy link to clipboard

Copied

Can you share your code that you are using?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

Poseted code which we are using in C#

//inputPath is Path (C:\test\AllPDFFiles\)

public static void mergePDFMethod(Credentials credentials, string inputPath, string outputPath)
{

try
{
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

// Add operation input from source files.

filesList = Directory.GetFiles(Path.GetDirectoryName(Path.GetDirectoryName(@outputPath) + "\\TempMerge\\"), "*.pdf", SearchOption.TopDirectoryOnly).Select(fn => new FileInfo(fn)).OrderBy(f => f.Name).ToArray();
foreach (var a in filesList.ToArray())
{
FileRef combineSource = FileRef.CreateFromLocalFile(a.ToString());
combineFilesOperation.AddInput(combineSource);

}
FileRef result = combineFilesOperation.Execute(executionContext);

// Save the result to the specified location.
result.SaveAs(@outputPath);
Console.WriteLine("End of Merge method");
}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Console.WriteLine("End of catch");
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

//inputPath is Path (C:\test\AllPDFFiles\)

public static void mergePDFMethod(Credentials credentials, string inputPath, string outputPath)
{

try
{
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

// Add operation input from source files.

filesList = Directory.GetFiles(Path.GetDirectoryName(Path.GetDirectoryName(@outputPath) + "\\TempMerge\\"), "*.pdf", SearchOption.TopDirectoryOnly).Select(fn => new FileInfo(fn)).OrderBy(f => f.Name).ToArray();
foreach (var a in filesList.ToArray())
{
FileRef combineSource = FileRef.CreateFromLocalFile(a.ToString());
combineFilesOperation.AddInput(combineSource);

}
FileRef result = combineFilesOperation.Execute(executionContext);

// Save the result to the specified location.
result.SaveAs(@outputPath);
Console.WriteLine("End of Merge method");
}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Console.WriteLine("End of catch");
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

//inputPath is Path (C:\test\AllPDFFiles\)

public static void mergePDFMethod(Credentials credentials, string inputPath, string outputPath)
{

try
{
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

// Add operation input from source files.

filesList = Directory.GetFiles(Path.GetDirectoryName(Path.GetDirectoryName(@outputPath) + "\\TempMerge\\"), "*.pdf", SearchOption.TopDirectoryOnly)
.Select(fn => new FileInfo(fn)).OrderBy(f => f.Name).ToArray();
foreach (var a in filesList.ToArray())
{
FileRef combineSource = FileRef.CreateFromLocalFile(a.ToString());
combineFilesOperation.AddInput(combineSource);

}
FileRef result = combineFilesOperation.Execute(executionContext);

// Save the result to the specified location.
result.SaveAs(@outputPath);
Console.WriteLine("End of Merge method");
}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Console.WriteLine("End of catch");
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

@Raymond Camden,

 

We are facing issue while merging pdf. as you requested we have posted the code in the covrsation. Request you to help us to resolve ASAP we are in dead line to move to PROD.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

I am not a .Net expert, but I'm wondering if the loop:

foreach (var a in filesList.ToArray())

is returning in the order you think it is. If, in the loop, you were able to add a log message, can you confirm that the logs report in the right order?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

We have verfied in log, its displayed as right order (correcet sequance). After below line 

FileRef result = combineFilesOperation.Execute(executionContext);

the output is not in correcr order.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

I whipped up a quick Node.js example and so far I can't reproduce this. In order to ensure it isn't an issue w/ the .Net SDK, would you mind creating a quick sample that is _not_ dynamic, but simply merges 3 files, hard coded. You can take the code from here (https://opensource.adobe.com/pdftools-sdk-docs/release/latest/howtos.html#combine-pdf-files) as an example. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2022 Jan 11, 2022

Copy link to clipboard

Copied

LATEST

Thanks for the update. We have fixed the issue in our code itsself.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2021 Nov 15, 2021

Copy link to clipboard

Copied

//inputPath is Path (C:\test\AllPDFFiles\)

public static void mergePDFMethod(Credentials credentials, string inputPath, string outputPath)
{

try
{
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

// Add operation input from source files.

filesList = Directory.GetFiles(Path.GetDirectoryName(Path.GetDirectoryName(@outputPath) + "\\TempMerge\\"), "*.pdf", SearchOption.TopDirectoryOnly).Select(fn => new FileInfo(fn)).OrderBy(f => f.Name).ToArray();
foreach (var a in filesList.ToArray())
{
FileRef combineSource = FileRef.CreateFromLocalFile(a.ToString());
combineFilesOperation.AddInput(combineSource);

}
FileRef result = combineFilesOperation.Execute(executionContext);

// Save the result to the specified location.
result.SaveAs(@outputPath);
Console.WriteLine("End of Merge method");
}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Console.WriteLine("End of catch");
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources