PDF does not open to first page

We are using concatenate to create one PDF for the two attached files.

When you open the combined PDF, it opens to the 2nd page.

1 Like

Hi Jon,


Thanks for using our products.

I have tested the scenario using Aspose.Pdf for .NET 7.6.0 while using the following code snippet and I am unable to notice any issue. For your reference, I have also attached the resultant PDF file which I have generated.

[C#]

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

Document pdfDocument1 = new Document("c:/pdftest/Page+1.pdf");

//open second document

Document pdfDocument2 = new Document("c:/pdftest/Page+2.pdf");

//add pages of second document to the first

pdfDocument1.Pages.Add(pdfDocument2.Pages);

//save concatenated output file

pdfDocument1.Save(“c:/pdftest/Merged_output.pdf”);

Here is the code we are using:

Public Sub FillableField()
Dim oPDFConcatenate As New Aspose.Pdf.Facades.PdfFileEditor
Dim sFile1 As String = "C:\workspace\page 1.pdf"
Dim sFile2 As String = "C:\workspace\page 2.pdf"
Dim sOutputFile As String = "C:\workspace\output.pdf"
Dim glInputStreams As New List(Of Stream)
For Each sFile As String In New String() {sFile1, sFile2}
Dim oFileInfo As New FileInfo(sFile)
If oFileInfo.Length > 0 Then
glInputStreams.Add(New FileStream(sFile, FileMode.Open, FileAccess.Read))
End If
oFileInfo = Nothing
Next

'Concatenate the files to the destination
Using oOutputStream As New FileStream(sOutputFile, FileMode.Create, FileAccess.Write)
oPDFConcatenate.Concatenate(glInputStreams.ToArray, oOutputStream)
End Using

' Opens to incorrect page
'
Process.Start(sOutputFile)
End Sub

Also, doing it in the manner that you suggest strips the second page of the fillable field.

The user should be able to enter text on the line "US Army Corps of Engineers" to enter whatever they want in that field.

Hi Jon,


Thanks for sharing the details.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this issue
as
PDFNEWNET-34749 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. Please be patient and spare us little time. We are sorry
for this inconvenience.

Hi Jon,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-34749 and as per our observations, the second document has OpenAction which causes moving to 2nd page when trying to open the resultant document. In order to resolve this issue, you may remove OpenAction after concatenation.

[C#]

PdfFileEditor pfe = new
PdfFileEditor();<o:p></o:p>

pfe.Concatenate(new string[] { "c:/pdftest/Page+1.pdf", "c:/pdftest/Page+2.pdf" },"c:/pdftest/Concatenated_34749.pdf");

//remove open action from save document.

Document doc = new Document("c:/pdftest/Concatenated_34749.pdf");

//solution 1. remove open action after

doc.OpenAction = null;

doc.Save("c:/pdftest/Concatenated_34749_Action_Removed.pdf");


Furthermore, please note that the scenario of adding pages of 2nd document to 1st document works, but fields became un-editable because 1st document is encrypted. Therefore in order to fix this problem, document must be decrypted before saving:

[C#]

//solution 2. concatenate and decrpyt document ( to make field editable)

Document.Licensed = true;

Document doc1 = new Document(TestSettings.GetInputFile("34749-1.pdf"));

Document doc2 = new Document(TestSettings.GetInputFile("34749-2.pdf"));

doc1.Pages.Add(doc2.Pages);

doc1.Decrypt();

doc1.Save(TestSettings.GetOutputFile("34749-1.pdf"));


Third possible solution is to copy pages both 1st and 2nd documents to newly created empty document:

[C#]

//solutuion 3. add pages from both document into resultatnt document

Document doc = new Document();

Document doc1 = new Document(TestSettings.GetInputFile("34749-1.pdf"));

Document doc2 = new Document(TestSettings.GetInputFile("34749-2.pdf"));

doc.Pages.Add(doc1.Pages);

doc.Pages.Add(doc2.Pages);

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

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


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

Hi,


We are still encountering this issue when merging pdf document. Please see the attached files.

When we merged Expense Report.pdf, Scan1.pdf, Scan2.pdf, the merged document opens in page 3 instead of page 1.

We are already using the latest Aspose.PDF version and still can replicate this issue. Any idea why this occurs?

Thanks,
June

Hi June,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 10.7.0 and as per my observations, the resultant file is not opening at page one. However when setting document open action as Null, the resultant file is properly being displayed (first page is opening when using Adobe Reader 11 to view the document). For your reference, I have also attached the resultant file generated over my end.

[C#]

PdfFileEditor pfe = new
PdfFileEditor();<o:p></o:p>

pfe.Concatenate(new string[] { "c:/pdftest/Scan1.pdf", "c:/pdftest/Scan2.pdf", "c:/pdftest/Expense+Report.pdf" }, "c:/pdftest/Concatenated.pdf");

//remove open action from save document.

Document doc = new Document("c:/pdftest/Concatenated.pdf");

//solution 1. remove open action after

doc.OpenAction = null;

doc.Save(“c:/pdftest/Concatenated_Action_Removed.pdf”);