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

Free Support Forum - aspose.com

Combining PDFs cause strange page orientation changes

Hi Support,

I have started with creating a PDF (defaults to A4 portrait). After creating a page with code, I then add a page from a separate PDF. This separate PDF is also in A4 portrait but yet the combined PDF changes to landscape for this page but keeps the contents in portrait thus chopping off the bottom part. I have looked at code for each page and there is a function CurrPDFPage.Rotate which returns on90 for this page which has the wrong orientation. I am guessing that this tells me that it has rotated this page automatically (can’t understand why) - how can the page be put back to the way it was in the original PDF?

See the example screen shot attached - in the combined doc, Page 3 is generated in code and Page 4 has been appended from a standalone PDF. Also attached is a preview of the standalone PDF.

Also the following information was established during generation:
Page 3 width is 595 and height is 842, rotation: None, size considering rotation: width 595 : height 842
Page 4 width is 595 and height is 842, rotation: on90, size considering rotation: width 842 : height 595

Hi Martin,


Thanks for contacting support.

Would you please share input document(s) along with the code snippet which you are using to perform the merging operation? This way we can test the scenario in our environment and address it accordingly.


Best Regards,

Hi, the overall PDF produced was 100+ pages long, so I have deleted most pages. A new document is create and a table added to the first page. Then a second PDF document is opened from a memory stream and appended to the first PDF. Then a new page is added with a table and then another PDF document created from a memory stream and the pages appended etc.
See the 4 page combined document and the two standalone PDFs that are appended.

The actual code is as follows:

Dim PDFByteArr() As Byte = rs2(“binary”) 'Get from table field into byte array
Dim CurrPDFms As New System.IO.MemoryStream(PDFByteArr) 'convert bytearray to ms
Dim PDFdoc2 As New Aspose.Pdf.Document(CurrPDFms) 'create a new PDF doc from ms
PDFdoc.Pages.Add(PDFdoc2.Pages) 'append to current PDF

Hi Martin,


Thanks for sharing input documents.

I have tested the scenario in our environment and was unable to notice any issue. After merging process, the pages in the resultant file were fine in context of there orientation. Please check the following routine which I have performed to test the scenario by the code snippet which is also given below. For your reference, an output file is also attached.

- Created a PDF with one table and saved into stream.
- Added pages of another PDF (TRAIN+TICKET+TO+LONDON+2.3.17.pdf) into new created PDF.
- Added new page again with a table in current PDF.
- Added pages of another PDF (20170315160007351.pdf) into current PDF.
- Saved current PDF at physical location. (Combined.pdf)

Code Snippet [VB.NET]:

Dim table
= New Table()<o:p></o:p>

table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow

Dim row As Row = table.Rows.Add()

row.Cells.Add().Paragraphs.Add(New TextFragment("Cell1"))

row.Cells.Add().Paragraphs.Add(New TextFragment("Cell2"))

row.Cells.Add().Paragraphs.Add(New TextFragment("Cell3"))

Dim doc As New Document()

Dim currpage As Page = doc.Pages.Add()

currpage.Paragraphs.Add(table)

doc.Save(New MemoryStream())

Dim doc2 = New Document(dataDir + "TRAIN+TICKET+TO+LONDON+2.3.17.pdf")

doc.Pages.Add(doc2.Pages)

currpage = doc.Pages.Add()

table = New Table()

table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow

row = table.Rows.Add()

row.Cells.Add().Paragraphs.Add(New TextFragment("Cell4"))

row.Cells.Add().Paragraphs.Add(New TextFragment("Cell5"))

row.Cells.Add().Paragraphs.Add(New TextFragment("Cell6"))

currpage.Paragraphs.Add(table)

doc.Save(New MemoryStream())

Dim doc3 = New Document(dataDir + "20170315160007351.pdf")

doc.Pages.Add(doc3.Pages)

doc.Save(dataDir + "CombinedPdf.pdf")



Furthermore, I have used latest version of the API which is Aspose.Pdf for .NET 17.4.0. Please confirm if you are using latest version of the API as it is always recommended and in case you are using latest version OR my above assumptions are different than your actual scenario, please share some more details by sharing a sample console application which is able to reproduce the issue.


PS: Also, sharing the environment details (i.e OS Version, Application Type, etc) in which you are working, would help us in investigating the scenario and address it accordingly.

Hi, I agree that your example works fine (although VS2010/Framework 4 Client Profile/Win7 does not understand “New TextFragment”). However, my program produces the results that I have shown. It is a complex program and my only idea as to why my results are different is that the PDFs to append are coming directly from a database. Please could you explain why I get the following output from this code.

Debug.Print("Page " & PDFcurrPage.Number.ToString & " width is " & PDFcurrPage.Rect.Width.ToString & " and height is " & PDFcurrPage.Rect.Height.ToString & ", rotation: " & PDFcurrPage.Rotate.ToString & ", size considering rotation: width " & CurrPDFPageRect.Width.ToString & " : height " & CurrPDFPageRect.Height.ToString)

Page 1 width is 595 and height is 842, rotation: None, size considering rotation: width 595 : height 842
Page 2 width is 595 and height is 842, rotation: on90, size considering rotation: width 842 : height 595
Page 3 width is 595 and height is 842, rotation: None, size considering rotation: width 595 : height 842
Page 4 width is 595 and height is 842, rotation: on90, size considering rotation: width 842 : height 595


This code tells me that Aspose PDF has detected something on the pages that are coming out wrong and is manipulating them in some way. Please can you ask the programmers what this means?

This is SO frustrating!

I will add another post with full code, but it is rather complex and you will not be able to try it as such but might spot some obvious mistake…

    Dim dsExpenses As New DataSet, dtExpenses As DataTable, adapter As New SqlDataAdapter(ADOCmdMiscSelects)<br>        adapter.SelectCommand.CommandTimeout = 300<br>        'Fill the dataset'<br>        adapter.Fill(dsExpenses) 'Does this get both tables loaded?<br>        dsExpenses.Tables(0).TableName = "Expenses"<br>        dtExpenses = dsExpenses.Tables("Expenses")<br><br>        Dim DTblExpenseTypeTotals As New DataTable<br>        DTblExpenseTypeTotals.Columns.Add("expense_type_key", GetType(System.String))<br>        DTblExpenseTypeTotals.Columns.Add("total_miles", GetType(System.Int32))<br>        DTblExpenseTypeTotals.Columns.Add("total_claim", GetType(System.Decimal))<br>        DTblExpenseTypeTotals.PrimaryKey = New DataColumn() {DTblExpenseTypeTotals.Columns("expense_type_key")}<br>        Dim DTPDFPages As New DataTable<br>        DTPDFPages.Columns.Add("staff_key", GetType(String))<br>        DTPDFPages.Columns.Add("last_page", GetType(Integer))<br>        Dim DRCurrExpCategoryTot As DataRow<br><br>        Dim CurrStaffTotMiles As Integer = 0, CurrStaffTotClaim As Decimal = 0, CurrStaffKey As String = "", CurrSectionHeaderTitle As String = ""<br><br>        Dim PDFdoc As New Aspose.Pdf.Document()<br>        Dim PDFPageInfo As Aspose.Pdf.PageInfo = PDFdoc.PageInfo<br>        Dim PDFmarginInfo As Aspose.Pdf.MarginInfo = PDFPageInfo.Margin<br>        Dim CurrStaffPDFTbl As Aspose.Pdf.Table, CurrStaffPDFTblRow As Aspose.Pdf.Row, CurrStaffPDFTblCellExpenseType As Aspose.Pdf.Cell, CurrStaffPDFTblCellExpenseDate As Aspose.Pdf.Cell, CurrStaffPDFTblCellExpenseMiles As Aspose.Pdf.Cell, CurrStaffPDFTblCellExpenseClaim As Aspose.Pdf.Cell, CurrStaffPDFTblCellExpenseDetails As Aspose.Pdf.Cell<br>        Dim CurrStaffPDFTbl2 As Aspose.Pdf.Table, CurrStaffPDFTblRow2 As Aspose.Pdf.Row, CurrStaffPDFTblCellExpenseType2 As Aspose.Pdf.Cell, CurrStaffPDFTblCellExpenseMiles2 As Aspose.Pdf.Cell, CurrStaffPDFTblCellExpenseClaim2 As Aspose.Pdf.Cell<br><br>        Dim TMHeaderStamp As New Aspose.Pdf.TextStamp("Holder")<br>        TMHeaderStamp.VerticalAlignment = VerticalAlignment.Top<br>        TMHeaderStamp.HorizontalAlignment = HorizontalAlignment.Center<br>        TMHeaderStamp.TextState.FontSize = 12<br>        TMHeaderStamp.TopMargin = 24<br>        TMHeaderStamp.RightMargin = 36<br><br>        Dim BLFooterStamp As New Aspose.Pdf.TextStamp(Now.Date.ToString("dd-MMM-yy"))<br>        BLFooterStamp.VerticalAlignment = VerticalAlignment.Bottom<br>        BLFooterStamp.HorizontalAlignment = HorizontalAlignment.Left<br>        BLFooterStamp.TextState.FontSize = 10<br>        BLFooterStamp.BottomMargin = 24<br>        BLFooterStamp.LeftMargin = 36<br><br>        Dim BRFooterStamp As New Aspose.Pdf.PageNumberStamp()<br>        BRFooterStamp.VerticalAlignment = VerticalAlignment.Bottom<br>        BRFooterStamp.HorizontalAlignment = HorizontalAlignment.Right<br>        BRFooterStamp.TextState.FontSize = 10<br>        BRFooterStamp.BottomMargin = 24<br>        BRFooterStamp.RightMargin = 36<br><br>        PDFmarginInfo.Left = 36<br>        PDFmarginInfo.Right = 36<br>        PDFmarginInfo.Top = 48<br>        PDFmarginInfo.Bottom = 48<br><br>        Dim PDFcurrPage As Aspose.Pdf.Page = PDFdoc.Pages.Add()<br>        Dim PDFparagraphs As Aspose.Pdf.Paragraphs = PDFcurrPage.Paragraphs<br>        For Each dr As DataRow In dtExpenses.Rows<br>            'See if staff key has changed - if so then output summary table and record page number so that we know which page to return to to insert receipts<br>            If dr("staff_key") <> CurrStaffKey Then<br>                If CurrStaffKey <> "" Then<br>                    'Load dt into PDF table<br>                    'CurrStaffPDFTbl.ImportDataTable(dt, True)<br>                    'Finish current member of staff<br>                    CurrStaffPDFTblRow = CurrStaffPDFTbl.Rows.Add()<br>                    CurrStaffPDFTblCellExpenseType = CurrStaffPDFTblRow.Cells.Add("TOTALS")<br>                    CurrStaffPDFTblCellExpenseDate = CurrStaffPDFTblRow.Cells.Add()<br>                    CurrStaffPDFTblCellExpenseMiles = CurrStaffPDFTblRow.Cells.Add(CurrStaffTotMiles.ToString("G29"))<br>                    CurrStaffPDFTblCellExpenseMiles.Alignment = HorizontalAlignment.Right<br>                    CurrStaffPDFTblCellExpenseClaim = CurrStaffPDFTblRow.Cells.Add(CurrStaffTotClaim.ToString("###,##0.00"))<br>                    CurrStaffPDFTblCellExpenseClaim.Alignment = HorizontalAlignment.Right<br>                    'Now create a summary table and insert into last cell of detail table<br>                    CurrStaffPDFTbl2 = New Aspose.Pdf.Table()<br>                    CurrStaffPDFTbl2.ColumnWidths = "100 30 40"<br>                    CurrStaffPDFTbl2.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))<br>                    CurrStaffPDFTbl2.DefaultCellBorder = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))<br>                    CurrStaffPDFTbl2.IsBordersIncluded = False<br>                    CurrStaffPDFTblRow2 = CurrStaffPDFTbl2.Rows.Add()<br>                    CurrStaffPDFTblCellExpenseType2 = CurrStaffPDFTblRow2.Cells.Add("Expense type")<br>                    CurrStaffPDFTblCellExpenseMiles2 = CurrStaffPDFTblRow2.Cells.Add("Miles")<br>                    CurrStaffPDFTblCellExpenseClaim2 = CurrStaffPDFTblRow2.Cells.Add("Claim")<br>                    For Each CurrDTRow As DataRow In DTblExpenseTypeTotals.Rows<br>                        CurrStaffPDFTblRow2 = CurrStaffPDFTbl2.Rows.Add()<br>                        CurrStaffPDFTblCellExpenseType2 = CurrStaffPDFTblRow2.Cells.Add(iGDropDownValueToText(DropDownExpenseTypes, CurrDTRow("expense_type_key")))<br>                        If CurrDTRow("total_miles") > 0 Then CurrStaffPDFTblCellExpenseMiles2 = CurrStaffPDFTblRow2.Cells.Add(CDec(CurrDTRow("total_miles")).ToString("G29")) Else CurrStaffPDFTblCellExpenseMiles2 = CurrStaffPDFTblRow2.Cells.Add()<br>                        CurrStaffPDFTblCellExpenseMiles2.Alignment = HorizontalAlignment.Right<br>                        CurrStaffPDFTblCellExpenseClaim2 = CurrStaffPDFTblRow2.Cells.Add(CDec(CurrDTRow("total_claim")).ToString("###,##0.00"))<br>                        CurrStaffPDFTblCellExpenseClaim2.Alignment = HorizontalAlignment.Right<br>                    Next<br>                    CurrStaffPDFTblCellExpenseDetails = CurrStaffPDFTblRow.Cells.Add()<br>                    CurrStaffPDFTblCellExpenseDetails.Paragraphs.Add(CurrStaffPDFTbl2)<br>                    PDFparagraphs.Add(CurrStaffPDFTbl)<br>                    'Force actual building of tables<br>                    PDFdoc.ProcessParagraphs()<br>                    'Now add pdfs of receipts<br>                    If rf.CurrentEmbedReceiptScans.value Or rf.HistoricalEmbedReceiptScans.value Then<br>                        ADOCmdMiscSelects2.Parameters("@p_staff_key").Value = CurrStaffKey<br>                        ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = DBNull.Value<br>                        ADOCmdMiscSelects2.Parameters("@p_process_date").Value = DBNull.Value<br>                        Select Case ADOCmdMiscSelects.Parameters("@p_op").Value<br>                            Case "REPPARCUR"<br>                                ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSPC"<br>                            Case "REPACCCUR"<br>                                ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSAC"<br>                            Case "REPPARHIS"<br>                                ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSPH"<br>                                ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = rf.HistSelectProcessedByWhoWhen.value.Substring(0, 6).Trim<br>                                ADOCmdMiscSelects2.Parameters("@p_process_date").Value = CDate(rf.HistSelectProcessedByWhoWhen.value.Substring(6))<br>                            Case "REPACCHIS"<br>                                ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSAH"<br>                                ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = rf.HistSelectProcessedByWhoWhen.value.Substring(0, 6).Trim<br>                                ADOCmdMiscSelects2.Parameters("@p_process_date").Value = CDate(rf.HistSelectProcessedByWhoWhen.value.Substring(6))<br>                        End Select<br>                        Dim rs2 As SqlDataReader = ADOCmdMiscSelects2.ExecuteReader<br>                        While rs2.Read<br>                            Dim PDFByteArr() As Byte = rs2("binary")<br>                            Dim CurrPDFms As New System.IO.MemoryStream(PDFByteArr)<br>                            Dim PDFdoc2 As New Aspose.Pdf.Document(CurrPDFms)<br>                            PDFdoc.Pages.Add(PDFdoc2.Pages)<br>                        End While<br>                        rs2.Close()<br>                    End If<br>                    'Now record what page number we are left at<br>                    DTPDFPages.Rows.Add(CurrStaffKey, PDFdoc.Pages.Count)<br>                End If<br>                CurrStaffPDFTbl = New Aspose.Pdf.Table()<br>                CurrStaffPDFTbl.ColumnWidths = "100 60 30 40 300"<br>                CurrStaffPDFTbl.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))<br>                CurrStaffPDFTbl.DefaultCellBorder = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))<br>                CurrStaffPDFTbl.IsBordersIncluded = False<br>                If CurrStaffKey <> "" Then 'If not first employee then start a new page<br>                    PDFcurrPage = PDFdoc.Pages.Add()<br>                    PDFparagraphs = PDFcurrPage.Paragraphs<br>                End If<br>                CurrStaffPDFTblRow = CurrStaffPDFTbl.Rows.Add()<br>                CurrStaffPDFTblCellExpenseType = CurrStaffPDFTblRow.Cells.Add("Expense type")<br>                CurrStaffPDFTblCellExpenseDate = CurrStaffPDFTblRow.Cells.Add("Date")<br>                CurrStaffPDFTblCellExpenseMiles = CurrStaffPDFTblRow.Cells.Add("Miles")<br>                CurrStaffPDFTblCellExpenseClaim = CurrStaffPDFTblRow.Cells.Add("Claim")<br>                CurrStaffPDFTblCellExpenseDetails = CurrStaffPDFTblRow.Cells.Add("Details")<br><br>                'table1.ImportDataTable(dt, True, 0, 0)<br>                'table1.IsInNewPage = True<br>                'paragraphs.Add(table1)<br>                CurrStaffTotClaim = 0<br>                CurrStaffTotMiles = 0<br>                CurrStaffKey = dr("staff_key")<br>                DTblExpenseTypeTotals.Rows.Clear()<br>            End If<br>            'Add expense to current staff table<br>            CurrStaffPDFTblRow = CurrStaffPDFTbl.Rows.Add()<br>            CurrStaffPDFTblCellExpenseType = CurrStaffPDFTblRow.Cells.Add(iGDropDownValueToText(DropDownExpenseTypes, dr("category")))<br>            CurrStaffPDFTblCellExpenseDate = CurrStaffPDFTblRow.Cells.Add(CDate(dr("expense_date")).ToString("dd-MMM-yy"))<br>            If dr("miles") > 0 Then CurrStaffPDFTblCellExpenseMiles = CurrStaffPDFTblRow.Cells.Add(CDec(dr("miles")).ToString("G29")) Else CurrStaffPDFTblCellExpenseMiles = CurrStaffPDFTblRow.Cells.Add()<br>            CurrStaffPDFTblCellExpenseMiles.Alignment = HorizontalAlignment.Right<br>            CurrStaffPDFTblCellExpenseClaim = CurrStaffPDFTblRow.Cells.Add(CDec(dr("claim")).ToString("###,##0.00"))<br>            CurrStaffPDFTblCellExpenseClaim.Alignment = HorizontalAlignment.Right<br>            CurrStaffPDFTblCellExpenseDetails = CurrStaffPDFTblRow.Cells.Add(dr("details"))<br>            If dr("category") = "MILEAG" Or dr("category") = "STUMIL" Then CurrStaffTotMiles += dr("miles")<br>            CurrStaffTotClaim += dr("claim")<br>            DRCurrExpCategoryTot = DTblExpenseTypeTotals.Rows.Find(dr("category"))<br>            If IsNothing(DRCurrExpCategoryTot) Then<br>                DTblExpenseTypeTotals.Rows.Add(dr("category"), dr("miles"), dr("claim"))<br>            Else<br>                DRCurrExpCategoryTot("total_miles") += dr("miles")<br>                DRCurrExpCategoryTot("total_claim") += dr("claim")<br>            End If<br>        Next<br>        'Finish current member of staff<br>        CurrStaffPDFTblRow = CurrStaffPDFTbl.Rows.Add()<br>        CurrStaffPDFTblCellExpenseType = CurrStaffPDFTblRow.Cells.Add("TOTALS")<br>        CurrStaffPDFTblCellExpenseDate = CurrStaffPDFTblRow.Cells.Add()<br>        CurrStaffPDFTblCellExpenseMiles = CurrStaffPDFTblRow.Cells.Add(CurrStaffTotMiles.ToString("G29"))<br>        CurrStaffPDFTblCellExpenseMiles.Alignment = HorizontalAlignment.Right<br>        CurrStaffPDFTblCellExpenseClaim = CurrStaffPDFTblRow.Cells.Add(CurrStaffTotClaim.ToString("###,##0.00"))<br>        CurrStaffPDFTblCellExpenseClaim.Alignment = HorizontalAlignment.Right<br>        'Now create a summary table and insert into last cell of detail table<br>        CurrStaffPDFTbl2 = New Aspose.Pdf.Table()<br>        CurrStaffPDFTbl2.ColumnWidths = "100 30 40"<br>        CurrStaffPDFTbl2.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))<br>        CurrStaffPDFTbl2.DefaultCellBorder = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))<br>        CurrStaffPDFTbl2.IsBordersIncluded = False<br>        CurrStaffPDFTblRow2 = CurrStaffPDFTbl2.Rows.Add()<br>        CurrStaffPDFTblCellExpenseType2 = CurrStaffPDFTblRow2.Cells.Add("Expense type")<br>        CurrStaffPDFTblCellExpenseMiles2 = CurrStaffPDFTblRow2.Cells.Add("Miles")<br>        CurrStaffPDFTblCellExpenseClaim2 = CurrStaffPDFTblRow2.Cells.Add("Claim")<br>        For Each CurrDTRow As DataRow In DTblExpenseTypeTotals.Rows<br>            CurrStaffPDFTblRow2 = CurrStaffPDFTbl2.Rows.Add()<br>            CurrStaffPDFTblCellExpenseType2 = CurrStaffPDFTblRow2.Cells.Add(iGDropDownValueToText(DropDownExpenseTypes, CurrDTRow("expense_type_key")))<br>            If CurrDTRow("total_miles") > 0 Then CurrStaffPDFTblCellExpenseMiles2 = CurrStaffPDFTblRow2.Cells.Add(CDec(CurrDTRow("total_miles")).ToString("G29")) Else CurrStaffPDFTblCellExpenseMiles2 = CurrStaffPDFTblRow2.Cells.Add()<br>            CurrStaffPDFTblCellExpenseMiles2.Alignment = HorizontalAlignment.Right<br>            CurrStaffPDFTblCellExpenseClaim2 = CurrStaffPDFTblRow2.Cells.Add(CDec(CurrDTRow("total_claim")).ToString("###,##0.00"))<br>            CurrStaffPDFTblCellExpenseClaim2.Alignment = HorizontalAlignment.Right<br>        Next<br>        CurrStaffPDFTblCellExpenseDetails = CurrStaffPDFTblRow.Cells.Add()<br>        CurrStaffPDFTblCellExpenseDetails.Paragraphs.Add(CurrStaffPDFTbl2)<br>        PDFparagraphs.Add(CurrStaffPDFTbl)<br>        'Force actual building of tables<br>        PDFdoc.ProcessParagraphs()<br>        'Now add pdfs of receipts<br>        'Now add pdfs of receipts<br>        If rf.CurrentEmbedReceiptScans.value Or rf.HistoricalEmbedReceiptScans.value Then<br>            ADOCmdMiscSelects2.Parameters("@p_staff_key").Value = CurrStaffKey<br>            ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = DBNull.Value<br>            ADOCmdMiscSelects2.Parameters("@p_process_date").Value = DBNull.Value<br>            Select Case ADOCmdMiscSelects.Parameters("@p_op").Value<br>                Case "REPPARCUR"<br>                    ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSPC"<br>                Case "REPACCCUR"<br>                    ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSAC"<br>                Case "REPPARHIS"<br>                    ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSPH"<br>                    ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = rf.HistSelectProcessedByWhoWhen.value.Substring(0, 6).Trim<br>                    ADOCmdMiscSelects2.Parameters("@p_process_date").Value = CDate(rf.HistSelectProcessedByWhoWhen.value.Substring(6))<br>                Case "REPACCHIS"<br>                    ADOCmdMiscSelects2.Parameters("@p_op").Value = "GETRECSAH"<br>                    ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = rf.HistSelectProcessedByWhoWhen.value.Substring(0, 6).Trim<br>                    ADOCmdMiscSelects2.Parameters("@p_process_date").Value = CDate(rf.HistSelectProcessedByWhoWhen.value.Substring(6))<br>            End Select<br>            Dim rs2 As SqlDataReader = ADOCmdMiscSelects2.ExecuteReader<br>            While rs2.Read<br>                Dim PDFByteArr() As Byte = rs2("binary")<br>                Dim CurrPDFms As New System.IO.MemoryStream(PDFByteArr)<br>                Dim PDFdoc2 As New Aspose.Pdf.Document(CurrPDFms)<br>                PDFdoc.Pages.Add(PDFdoc2.Pages)<br>            End While<br>            rs2.Close()<br>        End If<br>        'Now record what page number we are left at<br>        DTPDFPages.Rows.Add(CurrStaffKey, PDFdoc.Pages.Count)<br>        'Now add headers and footers (how do we know which pages are for which person?)<br>        Dim CurrPDFPage As Integer = 1, CurrPDFPageRect As Aspose.Pdf.Rectangle<br>        For Each CurrDTRow As DataRow In DTPDFPages.Rows<br>            For i As Integer = CurrPDFPage To CurrDTRow("last_page")<br>                Select Case rf.ReportTab.SelectedIndex<br>                    Case 0 'CURR<br>                        If rf.CurrSelectBranchAndMode.textvalue.Contains("(Partner mode)") Then<br>                            CurrSectionHeaderTitle = "Current Expenses for " & iGDropDownValueToText(DropDownEmployees, CurrDTRow("staff_key")) & " awaiting approval by office partner"<br>                        Else<br>                            CurrSectionHeaderTitle = "Current Expenses for " & iGDropDownValueToText(DropDownEmployees, CurrDTRow("staff_key")) & " awaiting processing by accounts"<br>                        End If<br>                    Case 1 'HIST<br>                        If rf.HistSelectBranchAndMode.textvalue.Contains("(Partner mode)") Then<br>                            CurrSectionHeaderTitle = "Expenses for " & iGDropDownValueToText(DropDownEmployees, CurrDTRow("staff_key")) & " that were approved by " & rf.HistSelectProcessedByWhoWhen.textvalue<br>                        Else<br>                            CurrSectionHeaderTitle = "Expenses for " & iGDropDownValueToText(DropDownEmployees, CurrDTRow("staff_key")) & " that were processed by " & rf.HistSelectProcessedByWhoWhen.textvalue<br>                        End If<br>                End Select<br>                TMHeaderStamp.Value = CurrSectionHeaderTitle<br>                PDFcurrPage = PDFdoc.Pages(i)<br>                CurrPDFPageRect = PDFcurrPage.GetPageRect(True)<br>                Debug.Print("Page " & PDFcurrPage.Number.ToString & " width is " & PDFcurrPage.Rect.Width.ToString & " and height is " & PDFcurrPage.Rect.Height.ToString & ", rotation: " & PDFcurrPage.Rotate.ToString & ", size considering rotation: width " & CurrPDFPageRect.Width.ToString & " : height " & CurrPDFPageRect.Height.ToString)<br>                PDFcurrPage.AddStamp(TMHeaderStamp)<br>                PDFcurrPage.AddStamp(BLFooterStamp)<br>                PDFcurrPage.AddStamp(BRFooterStamp)<br>                CurrPDFPage += 1<br>            Next<br>        Next<br>        Cursor = Cursors.Default<br>        Try<br>            PDFdoc.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\" & ReturnCleanPathAndFilename(FNAndHdr) & ".pdf")<br>            Cursor = Cursors.Default<br>            System.Diagnostics.Process.Start(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\" & ReturnCleanPathAndFilename(FNAndHdr) & ".pdf")<br>        Catch ex As Exception<br>            Cursor = Cursors.Default<br>            MsgBox("Sorry! Your application has still got the last version of this document open so unable to write the new version. Please close this document in your application again and re-run the report")<br>        End Try<br><br>

Hi Martin,


Thanks for sharing code snippet.

msutherland25:
Please could you explain why I get the following output from this code.

Debug.Print("Page " & PDFcurrPage.Number.ToString & " width is " & PDFcurrPage.Rect.Width.ToString & " and height is " & PDFcurrPage.Rect.Height.ToString & ", rotation: " & PDFcurrPage.Rotate.ToString & ", size considering rotation: width " & CurrPDFPageRect.Width.ToString & " : height " & CurrPDFPageRect.Height.ToString)

Page 1 width is 595 and height is 842, rotation: None, size considering rotation: width 595 : height 842
Page 2 width is 595 and height is 842, rotation: on90, size considering rotation: width 842 : height 595
Page 3 width is 595 and height is 842, rotation: None, size considering rotation: width 595 : height 842
Page 4 width is 595 and height is 842, rotation: on90, size considering rotation: width 842 : height 595


This code tells me that Aspose PDF has detected something on the pages that are coming out wrong and is manipulating them in some way. Please can you ask the programmers what this means?

I have tried your code snippet with the file which was generated in our environment and I observed the same output which you have shared. The rotation of 4th page which was added from the file (20170315160007351.pdf) appeared to be set on 90.

I have also tried to check the same parameters of the file (20170315160007351.pdf) separately by code and observed same values (Please check attached screenshot). It seems that the page rotation in the file (20170315160007351.pdf) is already set to on90, that is why you are getting this output.

Now after changing the rotation of page to none, I have merged it into new document again and got attached output in which you can observe the width and height of the last page is different.

msutherland25:
(although VS2010/Framework 4 Client Profile/Win7 does not understand “New TextFragment”).

Please import the Namespace “Aspose.Pdf.Text” in your class, then you will be able to use/access TextFragment object.

msutherland25:
I will add another post with full code, but it is rather complex and you will not be able to try it as such but might spot some obvious mistake…

I have checked the code snippet which you have shared and I was unable to define if there is some mistake, as it seemed fine. Because you were reading files from database as byte[], so I also tried to merge the documents by reading files as byte[] and did not notice any issue.

Now concerning to the issue which you are facing in context of page orientation, it would really be appreciated if you prepare a simple console application which is able to reproduce the issue and share with us, so that we can test the scenario in our environment and address it accordingly.


Best Regards,

I much appreciate your help. You are correct that some of the individual PDFs extracted from the database seem to be on90 or sometimes on270 and not always on A4 size (they have been mostly scanned on a MFD). I just don’t know where this orientation info comes from (does the scanner set this parameter?) I just don’t know why in my program, Apose PDF.Net seems to take pages with on90 or on270 and changes the orientation to landscape but DOES NOT reposition the image within the PDF so that the whole image is visible. I have tried numerous ideas to resize the paper to A4 (portrait or landscape) and show ALL the image. Please can you suggest some code that will take ANY size page (only likely to be smaller than A4) with ANY orientation and set A4 portrait/landscape and re-size/re-position image to fill the paper. Thank you

Hi Martin,


Thanks for your feedback.

msutherland25:
I just don’t know where this orientation info comes from (does the scanner set this parameter?) I just don’t know why in my program, Apose PDF.Net seems to take pages with on90 or on270 and changes the orientation to landscape but DOES NOT reposition the image within the PDF so that the whole image is visible

Would you please a code snippet which you are using to add image inside the PDF, so that we can look into this and share our finding with you accordingly.

msutherland25:
I have tried numerous ideas to resize the paper to A4 (portrait or landscape) and show ALL the image. Please can you suggest some code that will take ANY size page (only likely to be smaller than A4) with ANY orientation and set A4 portrait/landscape and re-size/re-position image to fill the paper. Thank you

As per my understandings, you want to add image inside a PDF so that it is visible completely and fit into page boundaries as well. Please check following code snippet(s) where I have shown adding image inside PDF with two styles.

1) Add image according to page boundaries (height/width):

Document doc = new Document();<o:p></o:p>

doc.Pages.Add();

Page page = doc.Pages[1];

page.Resources.Images.Add(new FileStream(dataDir + "image.jpg", FileMode.Open));

page.Contents.Add(new Operator.GSave());

Aspose.Pdf.Rectangle prectangle = page.GetPageRect(false);

Matrix matrix = new Matrix(new double[] { prectangle.URX - prectangle.LLX, 0, 0, prectangle.URY - prectangle.LLY, prectangle.LLX, prectangle.LLY });

page.Contents.Add(new Operator.ConcatenateMatrix(matrix));

XImage ximage = page.Resources.Images[page.Resources.Images.Count];

page.Contents.Add(new Operator.Do(ximage.Name));

page.Contents.Add(new Operator.GRestore());

doc.Save(dataDir + "output.pdf");



2) Adjust page boundaries (height/width) according to image dimensions:

var pdf = new Aspose.Pdf.Document();

var pdfImageSection = pdf.Pages.Add();

FileStream stream = new FileStream(dataDir + "image.jpg", FileMode.Open);

var image = new Aspose.Pdf.Image { ImageStream = stream };

var bmp = new System.Drawing.Bitmap(stream);

pdfImageSection.PageInfo.Width = bmp.Width;

pdfImageSection.PageInfo.Height = bmp.Height;

pdfImageSection.Paragraphs.Add(image);

// remove extra white space in four corners by setting page margin information

pdfImageSection.PageInfo.Margin.Left = pdfImageSection.PageInfo.Margin.Right = pdfImageSection.PageInfo.Margin.Top = pdfImageSection.PageInfo.Margin.Bottom = 5f;

pdf.Save(dataDir + "output.pdf");



In case of any further assistance, please feel free to contact us.


Best Regards,

Sorry, but you are not understanding the problem. I am not inserting images into PDFs. I am appending existing PDFs which have come from scanners (and therefore are just images packaged as PDF files) to a created PDF. Aspose.Pdf.Net is rotating some of these pages from these appended PDFs but not rotating the contents such that the images within the PDF are not fully displayed. Please see the very first screenshots which I attached that show the resulting document. Page 1 is created as a new document with a table inserted, page 2 is from a separate PDF downloaded from a database (and the image is not fully visible) , page 3 again is populated with a table and page 4 contains an appended PDF (again the image is not fully visible). I need to produce a PDF document that is a mixture of created pages and existing PDFs.

I can not re-create what is happening in a simple program that you can try since it involves reading data from a database, but have provided my full source code for inspection.

It would be very helpful if you could provide code that would allow identification of the paper size and orientation of the PDF being appended and then apply whatever changes are necessary to ensure that the paper size is A4 (portrait or landscape) and that any images within the PDF are fully visible.

Thank you

Hello Martin,


Thanks for writing back.

I have tried the same scenario which you have shared and was unable to notice the issue which you have mentioned. However please share with us about the data type of the column in the database, where your PDF files are stored. We will try to replicate the issue in our environment again by fetching the files from database and merge them in new document.

msutherland25:
It would be very helpful if you could provide code that would allow identification of the paper size and orientation of the PDF being appended and then apply whatever changes are necessary to ensure that the paper size is A4 (portrait or landscape)

Please refer to following articles in order to accomplish your above requirements.

- Manipulate Page in a PDF File
- Trim White Space Around a Page

msutherland25:
that any images within the PDF are fully visible.

You can simple extract the image from the PDF file after loading it from database and add that image in the new PDF document by using the same approach which I have already shared with you. For information regarding extracting images, please visit “Extract Images from PDF File” in API documentation.


Best Regards,

Thanks for replying. Although it seems obvious to extract the images from the PDFs and simply insert these into blank pages, there are two reasons not to do this. Firstly some of the PDFs will be properly constructed ones with many objects and secondly some PDFs may have restrictions that prevent the extraction of objects. This is why I have instead opted to append the actual PDF pages to the current PDF being built which should work for PDFs with any restrictions other than viewing ones.

I really can’t understand why when you test it that Aspose.Pdf does not change the orientation of pages as it does for me. The PDFs are stored in SQL Server as varbinary(max) fields. I don’t think we will ever understand why my program gives a different result.

I really do need to correct pages which are unnecessarily rotated and ensure that image objects within the page are also rotated such that all of the image is visible.

I am not asking you to write the code for me - I have already tried such things as:

If CurrPDFPg.Rotate.ToString.Contains(“on90”) Then
'Correct a 90deg rotation
CurrPDFPg.Rotate = Rotation.None
Dim r As Aspose.Pdf.Rectangle = CurrPDFPg.MediaBox
Dim newHeight As Double = r.Width
Dim newWidth As Double = r.Height
Dim newLLX As Double = r.LLX
’ We must to move page upper in order to compensate changing page size
’ (lower edge of the page is 0,0 and information is usually placed from the
’ top of the page. That’s why we move lover edge upper on difference between
’ old and new height.
Dim newLLY As Double = r.LLY + (r.Height - newHeight)
CurrPDFPg.MediaBox = New Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight)
’ Sometimes we also need to set CropBox (if it was set in original file)
CurrPDFPg.CropBox = New Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight)
End If

Somehow, it must be possible to detect and correct these PDF pages so that the whole document is A4 and images on these pages are entirely visible as per the original PDF.

Regards, Martin

I should add that properly constructed PDFs that come from the database work absolutely fine - it is only ones that contain a whole page image and which have the on90 or on270 setting that seem to go wrong…

Hi Martin,


Thanks for sharing more details.

I have tried the scenario again by fetching the PDF files from database and merging them in new PDF document and I was still unable to notice the issue. I have attached the generated PDF document over our environment, for your reference.

Furthermore, I have taken the PDF with issue, which you have shared earlier in this forum thread and execute following code snippet on it to set the page rotation to none and page size to A4. I have also attached the resultant file (Combined+Pdf+out.pdf) for your reference.

Dim doc
As New Document(dataDir +
“Combined+Pdf.pdf”)<o:p></o:p>

For Each page As Page In doc.Pages

If page.Rotate = Rotation.on90 OrElse page.Rotate = Rotation.on270 Then

page.Rotate = Rotation.None

page.SetPageSize(PageSize.A4.Width, PageSize.A4.Height)

page.PageInfo.IsLandscape = False

End If

Next

doc.Save(dataDir + "Combined+Pdf+out.pdf")


You can use above code snippet to make sure the page size is A4 and its dimensions are as per your requirement. In case if you still face any issue, please feel free to contact us.


Best Regards,

Hi, I was excited to try out your new code, but sadly my development environment still produces the same results. Page size changes seem to be ignored and knowing that Aspose.Pdf does not always immediately carry out actions until Save, I decided to save the individual PDFs before and after orientation manipulation and also save the main document before and after each PDF is appended. This has created a large file which you can access via this link:

https://mail.linkdc.co.uk/home/martin@linkdc.co.uk/Briefcase/Aspose

If you look at the individual PDFs (good example is the one named “Insurance Update to cover business use.pdf”), it actually looks fine before manipulation and wrong after correction. However, even when not corrected it is wrong after being added to the main PDF.

I really am pulling my hair out!

My code with your cleanup bits is as follows:

PDFdoc.ProcessParagraphs()
'Now add pdfs of receipts
PDFdoc.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “” & ReturnCleanPathAndFilename(FNAndHdr) & " with " & PDFdoc.Pages.Count.ToString & " pages.pdf")
If rf.CurrentEmbedReceiptScans.value Or rf.HistoricalEmbedReceiptScans.value Then
ADOCmdMiscSelects2.Parameters("@p_staff_key").Value = CurrStaffKey
ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = DBNull.Value
ADOCmdMiscSelects2.Parameters("@p_process_date").Value = DBNull.Value
Select Case ADOCmdMiscSelects.Parameters("@p_op").Value
Case “REPPARCUR”
ADOCmdMiscSelects2.Parameters("@p_op").Value = “GETRECSPC”
Case “REPACCCUR”
ADOCmdMiscSelects2.Parameters("@p_op").Value = “GETRECSAC”
Case “REPPARHIS”
ADOCmdMiscSelects2.Parameters("@p_op").Value = “GETRECSPH”
ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = rf.HistSelectProcessedByWhoWhen.value.Substring(0, 6).Trim
ADOCmdMiscSelects2.Parameters("@p_process_date").Value = CDate(rf.HistSelectProcessedByWhoWhen.value.Substring(6))
Case “REPACCHIS”
ADOCmdMiscSelects2.Parameters("@p_op").Value = “GETRECSAH”
ADOCmdMiscSelects2.Parameters("@p_processed_by").Value = rf.HistSelectProcessedByWhoWhen.value.Substring(0, 6).Trim
ADOCmdMiscSelects2.Parameters("@p_process_date").Value = CDate(rf.HistSelectProcessedByWhoWhen.value.Substring(6))
End Select
Dim rs2 As SqlDataReader = ADOCmdMiscSelects2.ExecuteReader
While rs2.Read
Dim PDFByteArr() As Byte = rs2(“binary”)
Dim CurrPDFms As New System.IO.MemoryStream(PDFByteArr)
Dim PDFdoc2 As New Aspose.Pdf.Document(CurrPDFms)
PDFdoc2.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “” & rs2(“filename”) & " - before any corrections.pdf")
For Each CurrPDFPg As Aspose.Pdf.Page In PDFdoc2.Pages
CurrPDFPgeRect = CurrPDFPg.GetPageRect(True)
Debug.Print(rs2(“filename”) & " page " & CurrPDFPg.Number.ToString & " width is " & CurrPDFPg.Rect.Width.ToString & " and height is " & CurrPDFPg.Rect.Height.ToString & “, rotation: " & CurrPDFPg.Rotate.ToString & “, size considering rotation: width " & CurrPDFPgeRect.Width.ToString & " : height " & CurrPDFPgeRect.Height.ToString)
If CurrPDFPg.Rotate = Rotation.on90 OrElse CurrPDFPg.Rotate = Rotation.on270 Then
CurrPDFPg.Rotate = Rotation.None
CurrPDFPg.SetPageSize(PageSize.A4.Width, PageSize.A4.Height)
CurrPDFPg.PageInfo.IsLandscape = False
End If
Next
PDFdoc2.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “” & rs2(“filename”) & " - after any corrections.pdf”)
PDFdoc.Pages.Add(PDFdoc2.Pages)
PDFdoc.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “” & ReturnCleanPathAndFilename(FNAndHdr) & " with " & PDFdoc.Pages.Count.ToString & " pages.pdf”)
End While
rs2.Close()
End If

Hi Martin,


Thanks for your sharing input files.

I have checked that code snippet with your input files and observed that image(s) inside the page got cropped after manipulation of page(s). Though for the sake of investigation, I have logged an issue as PDFNET-42771 in our issue tracking system. We will further look into this and keep you updated on the status of its resolution. Please be patient and spare us little time.

msutherland25:
However, even when not corrected it is wrong after being added to the main PDF.

I wonder that I still was not able to replicate the issue which you have mentioned in the first place (fetching files from database, merge them and page orientation gets changed). It would be really helpful if you can create a sample application (include database if necessary) which replicates the issue and share with us. This way we will be able to observe the issue in our environment and address it accordingly.

We are sorry for the inconvenience.


Best Regards,

Hi,

I have finally worked out what is causing the problem!

It is the code that sets the margins even before the first page is added. I’m sure that this does come from one of your examples. Code that shows the problems is as follows:

Dim table = New Table()

table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow

Dim row As Row = table.Rows.Add()

row.Cells.Add(“Cell1”)

row.Cells.Add(“Cell2”)

row.Cells.Add(“Cell3”)



Dim doc As New Document()
Dim PDFPageInfo As Aspose.Pdf.PageInfo = doc.PageInfo
Dim PDFmarginInfo As Aspose.Pdf.MarginInfo = PDFPageInfo.Margin
PDFmarginInfo.Left = 36
PDFmarginInfo.Right = 36
PDFmarginInfo.Top = 48
PDFmarginInfo.Bottom = 48
Dim currpage As Page = doc.Pages.Add()


currpage.Paragraphs.Add(table)

'doc.Save(New MemoryStream())



Dim doc2 = New Document(New System.IO.MemoryStream(My.Resources.TRAIN_TICKET_TO_LONDON_2_3_17))



doc.Pages.Add(doc2.Pages)

currpage = doc.Pages.Add()



table = New Table()

table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow

row = table.Rows.Add()

row.Cells.Add(“Cell4”)

row.Cells.Add(“Cell5”)

row.Cells.Add(“Cell6”)



currpage.Paragraphs.Add(table)

'doc.Save(New MemoryStream())



Dim doc3 = New Document(New System.IO.MemoryStream(My.Resources._20170315160007351))



doc.Pages.Add(doc3.Pages)

doc.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “” & “CombinedPdf.pdf”)

Not sure why this should cause problems only for pages containing full page images? Perhaps even trying to place a full page image will cause the same issue and nothing to do with appending of PDFs as such?

I have removed the margin settings from my main code, but sadly the problem still persists. Hopefully now that you have an example that shows the problem, you can gain a better understanding of the problem.

Regards, Martin

Hi Martin,


Thanks for your feedback.

I have tried your code snippet and was able to observe that orientation of the pages got changed in the resultant PDF file. This was happening because you were assigning margin info for the whole document and API was generating issue with the merged pages as they were from different PDF file with different set of properties.

I have modified your code snippet like following and shifted the MarginInfo settings to the page level. Doing that has generated correct output which has also been attached for your reference.

[VB.NET]
Dim table As New Table()
table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow
Dim row As Row = table.Rows.Add()
row.Cells.Add(“Cell1”)
row.Cells.Add(“Cell2”)
row.Cells.Add(“Cell3”)
Dim doc As New Document()
Dim currpage As Page = doc.Pages.Add()
currpage.Paragraphs.Add(table)
currpage.PageInfo.Margin = New MarginInfo(36, 48, 36, 48)
doc.Save(New MemoryStream())
Dim doc2 As New Document(New MemoryStream(File.ReadAllBytes(dataDir + “TRAIN+TICKET+TO+LONDON+2.3.17.pdf”)))
doc.Pages.Add(doc2.Pages)
currpage = doc.Pages.Add()
currpage.PageInfo.Margin = New MarginInfo(36, 48, 36, 48)
table = New Table()
table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow
row = table.Rows.Add()
row.Cells.Add(“Cell4”)
row.Cells.Add(“Cell5”)
row.Cells.Add(“Cell6”)
currpage.Paragraphs.Add(table)
doc.Save(New MemoryStream())
Dim doc3 As New Document(New System.IO.MemoryStream(File.ReadAllBytes(dataDir + “20170315160007351.pdf”)))
doc.Pages.Add(doc3.Pages)
doc.Save(dataDir + “CombinedPdfWithMarginInfo.pdf”)

msutherland25:
I have removed the margin settings from my main code, but sadly the problem still persists. Hopefully now that you have an example that shows the problem, you can gain a better understanding of the problem.

I have tried to generate output by removing margin settings and was unable to notice the issue (Please check CombinedPdfWithOutMarginInfo.pdf). Please note that the examples have been provided to demonstrate the general understanding of API methods and features so that you can use/mold it as per your requirement. Nevertheless, would you please point out the example, so that we can check it again with latest version of API and share our feedback accordingly.


Best Regards,

Hi, have removed the margin settings just after creation of the PDF and only specified on pages that contain the table. Next for each added PDF, I cycle through the pages and set to A4 and the results you can see for yourself. Here is the code:

Dim table = New Table()
table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow
Dim row As Row = table.Rows.Add()
row.Cells.Add(“Cell1”)
row.Cells.Add(“Cell2”)
row.Cells.Add(“Cell3”)

Dim doc As New Document()
Dim currpage As Page = doc.Pages.Add()
currpage.PageInfo.Margin = New MarginInfo(36, 48, 36, 48)
currpage.Paragraphs.Add(table)
'doc.Save(New MemoryStream())

Dim doc2 = New Document(New System.IO.MemoryStream(My.Resources.TRAIN_TICKET_TO_LONDON_2_3_17))
For Each CurrPDFPg As Aspose.Pdf.Page In doc2.Pages
CurrPDFPg.SetPageSize(PageSize.A4.Width, PageSize.A4.Height)
CurrPDFPg.PageInfo.IsLandscape = False
Next
doc.Pages.Add(doc2.Pages)

currpage = doc.Pages.Add()
currpage.PageInfo.Margin = New MarginInfo(36, 48, 36, 48)
table = New Table()
table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow
row = table.Rows.Add()
row.Cells.Add(“Cell4”)
row.Cells.Add(“Cell5”)
row.Cells.Add(“Cell6”)
currpage.Paragraphs.Add(table)
'doc.Save(New MemoryStream())

Dim doc3 = New Document(New System.IO.MemoryStream(My.Resources._20170315160007351))
For Each CurrPDFPg As Aspose.Pdf.Page In doc3.Pages
CurrPDFPg.SetPageSize(PageSize.A4.Width, PageSize.A4.Height)
CurrPDFPg.PageInfo.IsLandscape = False
Next
doc.Pages.Add(doc3.Pages)

doc.Save(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “” & “CombinedPdf.pdf”)

As you will see, the pages are in A4 landscape and the images within the page are cropped.

Any ideas?

Hi Martin,


Thanks for writing back.

I have checked the code snippet which you have shared and have managed to observe the issue in our environment. Though I have already logged an issue in our issue tracking system regarding page orientation and cropped images, which have been associated with this forum thread as well. As soon as we have some definite updates regarding its resolution, we will certainly inform you. Please be patient and spare us little time.

We are sorry for the inconvenience,


Best Regards,