New page in iTextSharp - vb.net

I'm trying to create a PDF with iTextSharp which reads the values out of a form, which are inserted from a DataGridView.
So, after a specific amount of lines of the DataGridView I want to create a new page with PdfFile.NewPage()
This code writes the DataGridView into a PDF:
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For j As Integer = 0 To DataGridView1.Columns.Count - 1
pdfcell = New PdfPCell(New Phrase(DataGridView1(j, i).Value.ToString(), pTable))
PdfTable.HorizontalAlignment = PdfPCell.ALIGN_LEFT
PdfTable.AddCell(pdfcell)
Next
Next
PdfFile.Add(PdfTable)
The reason for doing that is because the DataGridView overwrites the footer.
After 20 DataGridView lines a PdfFile.NewPage() should follow. On the second page it should continue with the 21 DataGridView lines.
For example after 50 lines a new page.
This is the code for the footer:
Inherits PdfPageEventHelper
Public Overrides Sub OnendPage(ByVal writer As iTextSharp.text.pdf.PdfWriter, ByVal document As iTextSharp.text.Document)
Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim cb As PdfContentByte = writer.DirectContent
cb.BeginText()
cb.SetFontAndSize(bf, 12)
cb.SetTextMatrix(50, 30)
cb.ShowText("TEXTTEXT " & writer.PageNumber)
cb.EndText()
I already tried this. It is just creating the next page but still overwrites the footer:
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For j As Integer = 0 To DataGridView1.Columns.Count - 1
pdfcell = New PdfPCell(New Phrase(DataGridView1(j, i).Value.ToString(), pTable))
PdfTable.HorizontalAlignment = PdfPCell.ALIGN_LEFT
PdfTable.AddCell(pdfcell)
Next
Select Case i
Case 20, 30, 60, 99
PdfFile.NewPage()
End Select
Next
PdfFile.Add(PdfTable)

Related

How to dynamicallty create multiple controls at runtime

I am trying to add multiple labels to a userform at runtime
It's for the player names of a board game; and until the game starts the number of players are not known. I have managed to figure out for myself how to use the dynamic array function to create the list of players. I used a For.....Next loop to add the player names. I thought I could do that to add the labels to the form, but it only adds one. Depending on where the new control type is declared, it either adds the first player only, or the last player
This code produces one label only within the groupbox, the last player
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Players_Num As Integer = InputBox("Enter the number of players")
Dim Players(Players_Num) As String
Dim newText As New Label
For i = 0 To Players_Num - 1
Players(i) = InputBox("Enter player name")
Next
'This piece of code was jsut for me to test that I was successfully using a For...Loop
'to add the players names, and will be deleted later on
For x = 0 To Players_Num - 1
MessageBox.Show(Players(x))
Next
For z = 0 To Players_Num - 1
newText.Name = "txt" & Players(z)
newText.Text = Players(z)
newText.Size = New Size(170, 20)
newText.Location = New Point(12 + 5, 12 + 5)
GroupBox1.Controls.Add(newText)
Next
End Sub
End Class
This one places only the first player
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Players_Num As Integer = InputBox("Enter the number of players")
Dim Players(Players_Num) As String
For i = 0 To Players_Num - 1
Players(i) = InputBox("Enter player name")
Next
'This piece of code was jsut for me to test that I was successfully using a For...Loop
'to add the players names, and will be deleted later on
For x = 0 To Players_Num - 1
MessageBox.Show(Players(x))
Next
For z = 0 To Players_Num - 1
Dim newText As New Label
newText.Name = "txt" & Players(z)
newText.Text = Players(z)
newText.Size = New Size(170, 20)
newText.Location = New Point(12 + 5, 12 + 5)
GroupBox1.Controls.Add(newText)
Next
End Sub
End Class
I've tried this in vs 2015 and 2019 Community
Where is it going wrong?
From the looks of the code, you are correctly creating the controls but their location is the same for all of them, essentially, they are being place one of top of the other, the first is hidden with the second, which is hidden with the third.
The line
newText.Location = New Point(12 + 5, 12 + 5)
needs to be modified to place the labels at different locations.
Perhaps, something like:
newText.Location = New Point(12 + 5, 12 + (z * 25))
This will vertically align the labels with a gap of 25 between them
You are placing them all in the same location
newText.Location = New Point(12 + 5, 12 + 5)
Use your 'z' index to place them at different locations in order to be able to see them
For me it is easier to contain controls in a TableLayoutPanel then add the TLP to what ever control collection, such as a GroupBox This way you can couple a Label with TextBox, for example. Here's an example how you can create controls from a DataTable. In your case you would only need 1 ColumnStyle for labels, I just thought I would show you a good practice for future shortcuts. (I rarely use the designer to place controls)
'Start test data
Dim DtTable As New DataTable
With DtTable
Dim NewDtRow As DataRow = .NewRow
For i As Integer = 0 To 25
Dim DtCol As New DataColumn With {.ColumnName = "Col" & i, .DataType = GetType(String)}
.Columns.Add(DtCol)
NewDtRow(DtCol.ColumnName) = "Test" & i
Next
.Rows.Add(NewDtRow)
End With
'End test data
Dim TLP1 As New TableLayoutPanel With {.Name = "TlpFields"}
With TLP1
.BorderStyle = BorderStyle.Fixed3D
.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
.AutoScroll = True
.AutoSize = True
.RowStyles.Clear()
.ColumnStyles.Clear()
.Dock = DockStyle.Fill
.ColumnCount = 2
.ColumnStyles.Add(New ColumnStyle With {.SizeType = SizeType.AutoSize})
End With
For Each DtCol As DataColumn In DtTable.Columns
With TLP1
.RowCount += 1
.RowStyles.Add(New RowStyle With {.SizeType = SizeType.AutoSize})
'create labels
.Controls.Add(New Label With {
.Text = DtCol.ColumnName,
.Anchor = AnchorStyles.Right}, 0, .RowCount)
'create textboxs
Dim TxtBox As New TextBox With {
.Name = "TextBox" & DtCol.ColumnName,
.Size = New Size(170, 20),
.Anchor = AnchorStyles.Left}
'add binding
TxtBox.DataBindings.Add("Text", DtTable, DtCol.ColumnName)
.Controls.Add(TxtBox, 1, .RowCount)
End With
Next
Controls.Add(TLP1)

vb.net loop through list box contains path for rtf files then convert to html code then insert to datagridview

I have a problem with vb.net code, after i finished with all codes that get files from path then loop through this list to get RTF text then convert it to HTML... until here everything is okay
my problem starts here>>> inserting the result to new row in datagridview it just does this to first row, then stops after that!
here's the codes
For i = 0 To ListBox1.Items.Count - 1
'get RTF files...
RichTextBox1.LoadFile(ListBox1.Items(i).ToString(),
RichTextBoxStreamType.RichText)
RichTextBox1.SelectAll()
RichTextBox1.SelectionAlignment =
HorizontalAlignment.Right
'Convert to html method...
converttohtml()
'just for fallow the process
MsgBox("Ok " + i.ToString())
'insert new row with the html result
DataGridView1.Rows.Insert(i, New String() {RichTextBox2.Text, RichTextBox1.Text})
'increase progress by one
ProgressBar1.Value += 1
Next
my problem fixed... by help of a freelancer ... here's the code
'add column to datagridview ...
Dim col As New DataGridViewTextBoxColumn
col.DataPropertyName = "cellvalue"
col.HeaderText = "Article"
col.Name = "Article"
DataGridView1.Columns.Add(col)
'second coulmn...
Dim cols As New DataGridViewTextBoxColumn
cols.DataPropertyName = "cellnumber"
cols.HeaderText = "number"
cols.Name = "number"
DataGridView1.Columns.Add(cols)
'third coulmn...
Dim colsa As New DataGridViewTextBoxColumn
colsa.DataPropertyName = "cellnumber"
cols.HeaderText = "number"
colsa.Name = "number"
DataGridView1.Columns.Add(colsa)
DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
ProgressBar1.Value = 0
Dim x As Integer = 0
For i = 0 To ListBox1.Items.Count - 1
'get RTF files...
RichTextBox1.LoadFile(ListBox1.Items(i).ToString(),
RichTextBoxStreamType.RichText)
RichTextBox1.SelectAll()
RichTextBox1.SelectionAlignment =
HorizontalAlignment.Right
'Convert to html method...
converttohtml()
'just for fallow the process
MsgBox("Ok " + i.ToString())
'insert new row with the html result
DataGridView1.Rows.Insert(i, New String()
{RichTextBox2.Text, RichTextBox1.Text, xstring})
'increase progress by one
ProgressBar1.Value += 1
Next
End Sub
cells just needed to be wrap... BY M P.

Loop for PDF Cells always Off by One

I am trying to make a barcode label printer through cells. I have a pdfTable that has 3 columns. But everytime I tried to export the pdfTable with a cell count that is not equal or divisible by 3 (which is the number of columns), the cell count are always increasing or off by 1.
For example :
Tried to export 30 cells which is divisible to the pdfTable columns which is 3 (works fine)
Tried to export 1 or 10 cells which is not divisible to the pdfTable columns which is 3 (cell count are always off by 1). Results are like 1 cell become 2 cells and 10 cells become 11 cells.
I always check if there is something wrong with my loop that causes the cells to increase by 1 but I can't find anything.
Here is my code for exporting a PDF :
Public Function print_itembarcodes(lbl169 As Label)
Dim pdfTable As New PdfPTable(3) 'pdfTable Column Count'
pdfTable.DefaultCell.Padding = 3
pdfTable.WidthPercentage = 100
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER
pdfTable.DefaultCell.Border = Rectangle.NO_BORDER
Dim emptyCell As New PdfPCell
emptyCell.Border = 0
Dim count As Integer
count = 0
For i As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows.Count - 1 'Read item one by one'
Admin_Menu.Label169.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(1).Value
Admin_Menu.Label170.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(0).Value
Admin_Menu.Label171.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(4).Value
Barcode.process_printbarcode(Admin_Menu.Label169)
save_printbarcode()
For j As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Cell quantity to be exported for one item'
pdfTable.AddCell(create_barcodecell) 'Create a cell with barcode'
count = count + 1
Next
Next
For k As Integer = 0 To count Mod 3
pdfTable.AddCell(emptyCell)
Next
count = 0
Try
'Exporting to PDF'
Dim folderPath As String = "C:\Temp\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using stream As New FileStream(folderPath & "temp2.pdf", FileMode.Create)
Dim pdfdoc As New Document(PageSize.A4, 15.0F, 15.0F, 10.0F, 20.0F)
PdfWriter.GetInstance(pdfdoc, stream)
pdfdoc.Open()
pdfdoc.Add(pdfTable)
pdfdoc.Close()
stream.Close()
System.Diagnostics.Process.Start("C:\\Temp\\temp2.pdf")
End Using
Catch ex As MySqlException
MsgBox(ex.Message)
Finally
MysqlConn.Dispose()
End Try
Return True
End Function
Here is my code for the function of creating a cell with barcode :
Public Function create_barcodecell()
Dim SaveFileDialog1 = "D:\School\Capstone\Sta. Lucia East Bowling and Billiard Hall Management System\Item Barcodes\"
Dim Barcode2 As Image = Image.GetInstance(SaveFileDialog1 + Admin_Menu.Label169.Text + ".png")
Barcode2.ScaleAbsolute(170.0F, 50.0F)
img.ScalePercent(20.0F)
img.Alignment = iTextSharp.text.Image.ALIGN_CENTER
Dim itemname, itemprice, itemcode As New Paragraph
itemname.Alignment = Element.ALIGN_CENTER
itemprice.Alignment = Element.ALIGN_CENTER
itemcode.Alignment = Element.ALIGN_CENTER
Dim codeFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10)
Dim tagFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)
Dim priceFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11)
codeFont.Color = BaseColor.WHITE
tagFont.Color = BaseColor.WHITE
priceFont.Color = BaseColor.WHITE
itemname.Add(New Chunk(Admin_Menu.Label170.Text, tagFont))
itemprice.Add(New Chunk("P " + Admin_Menu.Label171.Text + ".00", priceFont))
itemcode.Add(New Chunk(Admin_Menu.Label169.Text, codeFont))
Dim pdfCell As New PdfPCell
pdfCell.UseVariableBorders = True
pdfCell.BackgroundColor = BaseColor.RED
pdfCell.BorderColorLeft = BaseColor.BLACK
pdfCell.BorderColorRight = BaseColor.BLACK
pdfCell.BorderColorTop = BaseColor.BLACK
pdfCell.BorderColorBottom = BaseColor.BLACK
pdfCell.PaddingTop = 10
pdfCell.PaddingBottom = 10
pdfCell.PaddingLeft = 8
pdfCell.PaddingRight = 10
pdfCell.AddElement(img)
pdfCell.AddElement(itemname)
pdfCell.AddElement(Barcode2)
pdfCell.AddElement(itemcode)
pdfCell.AddElement(itemprice)
Return pdfCell
End Function
The loop started by
For j As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Cell quantity to be exported for one item'
executes Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value + 1 times. You might want to start with the value 1 instead of 0 to get rid of the off-by-one.
The loop started by
For k As Integer = 0 To count Mod 3
executes (count Mod 3) + 1 times.
My first idea was that you might also want to start with the value 1 instead of 0, after all if Count already is a multiple of 3, you don't want it to run at all.
When I set up a simplified version of your program, though, in which I started that loop at 1, I got an exception, too. Thus, I reconsidered the actual purpose of that extra loop (which I myself recommended in my answer to your previous question) and figured out that the number of iterations was completely wrong to start with:
For Count = 1 one needs 2 extra iterations, for Count = 2 one needs 1 extra iteration, for Count = 3 none is needed, for Count = 4 one needs 2 extra iterations, ...
So, one does not need Count Mod 3 iterations of the second loop at all but instead (3 - (Count Mod 3)) Mod 3 iterations, or more simple
While count Mod 3 <> 0
pdfTable.AddCell(emptyCell)
count = count + 1
End While
which also is what intuition should dictate: Continue adding empty cells until the cell count is a multiple of 3...
The test code
I simplified your code to be able to run it at all, after all I don't have those many variables you use. The final version (including the fixes mentioned above, the first loop starting at 1, the second one using the While now) was this:
Public Sub CreateTableLuciferRodstark(filledCells As Integer, fileName As String)
Dim pdfTable As New PdfPTable(3) 'pdfTable Column Count'
pdfTable.DefaultCell.Padding = 3
pdfTable.WidthPercentage = 100
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER
pdfTable.DefaultCell.Border = Rectangle.NO_BORDER
Dim emptyCell As New PdfPCell
emptyCell.Border = 0
Dim count As Integer = 0
For j As Integer = 1 To filledCells
pdfTable.AddCell(create_barcodecell) 'Create a cell with barcode'
count = count + 1
Next
While count Mod 3 <> 0
pdfTable.AddCell(emptyCell)
count = count + 1
End While
Using stream As New FileStream(fileName, FileMode.Create)
Dim pdfdoc As New Document(PageSize.A4, 15.0F, 15.0F, 10.0F, 20.0F)
PdfWriter.GetInstance(pdfdoc, stream)
pdfdoc.Open()
pdfdoc.Add(pdfTable)
pdfdoc.Close()
End Using
End Sub
Public Function create_barcodecell()
Dim pdfCell As New PdfPCell
pdfCell.UseVariableBorders = True
pdfCell.BackgroundColor = BaseColor.RED
pdfCell.BorderColorLeft = BaseColor.BLACK
pdfCell.BorderColorRight = BaseColor.BLACK
pdfCell.BorderColorTop = BaseColor.BLACK
pdfCell.BorderColorBottom = BaseColor.BLACK
pdfCell.PaddingTop = 10
pdfCell.PaddingBottom = 10
pdfCell.PaddingLeft = 8
pdfCell.PaddingRight = 10
pdfCell.AddElement(New Paragraph("an item"))
pdfCell.AddElement(New Paragraph("a code"))
pdfCell.AddElement(New Paragraph("a price"))
Return pdfCell
End Function
I ran the code for 1 to 6 filled cells:
CreateTableLuciferRodstark(1, "Table1of3.pdf")
CreateTableLuciferRodstark(2, "Table2of3.pdf")
CreateTableLuciferRodstark(3, "Table3of3.pdf")
CreateTableLuciferRodstark(4, "Table4of3.pdf")
CreateTableLuciferRodstark(5, "Table5of3.pdf")
CreateTableLuciferRodstark(6, "Table6of3.pdf")
and the results are:
Table1of3.pdf:
Table2of3.pdf:
Table3of3.pdf:
Table4of3.pdf:
Table5of3.pdf:
Table6of3.pdf:

Out of memory exception when merging multiple pdf

I have to merge multiple pdf's into one pdf. I'm using iTextSHarp 5.5.10.0 to accomplish this, and it work fine when I merge small files( 2 or more, with 20 pages each), and even work when I try to merge 2 files, one with 3000 pages and the second with 1300 pages, but when I try to merge 3 pdf's with 3000 pages each, I get an out of memory exception.
I don't know how to solve this.
I'm using fileStream and not memoryStream.
I took the code from the answer to this question:
VB.Net Merge multiple pdfs into one and export
Public Function MergePdfFiles(ByVal pdfFiles() As String, ByVal outputPath As String) As Boolean
Dim result As Boolean = False
Dim pdfCount As Integer = 0 'total input pdf file count
Dim f As Integer = 0 'pointer to current input pdf file
Dim fileName As String
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
Dim pageCount As Integer = 0
Dim pdfDoc As iTextSharp.text.Document = Nothing 'the output pdf document
Dim writer As PdfWriter = Nothing
Dim cb As PdfContentByte = Nothing
Dim page As PdfImportedPage = Nothing
Dim rotation As Integer = 0
Try
pdfCount = pdfFiles.Length
If pdfCount > 1 Then
'Open the 1st item in the array PDFFiles
fileName = pdfFiles(f)
reader = New iTextSharp.text.pdf.PdfReader(fileName)
'Get page count
pageCount = reader.NumberOfPages
pdfDoc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18)
writer = PdfWriter.GetInstance(pdfDoc, New FileStream(outputPath, FileMode.OpenOrCreate))
With pdfDoc
.Open()
End With
'Instantiate a PdfContentByte object
cb = writer.DirectContent
'Now loop thru the input pdfs
While f < pdfCount
'Declare a page counter variable
Dim i As Integer = 0
'Loop thru the current input pdf's pages starting at page 1
While i < pageCount
i += 1
'Get the input page size
pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i))
'Create a new page on the output document
pdfDoc.NewPage()
'If it is the 1st page, we add bookmarks to the page
'Now we get the imported page
page = writer.GetImportedPage(reader, i)
'Read the imported page's rotation
rotation = reader.GetPageRotation(i)
'Then add the imported page to the PdfContentByte object as a template based on the page's rotation
If rotation = 90 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height)
ElseIf rotation = 270 Then
cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
End While
'Increment f and read the next input pdf file
f += 1
If f < pdfCount Then
fileName = pdfFiles(f)
reader = New iTextSharp.text.pdf.PdfReader(fileName)
pageCount = reader.NumberOfPages
End If
End While
'When all done, we close the document so that the pdfwriter object can write it to the output file
pdfDoc.Close()
result = True
End If
Catch ex As Exception
Return False
End Try
Return result
End Function
I get the Exception from this line, in the end of the while, when trying to read the second file:
reader = New iTextSharp.text.pdf.PdfReader(fileName)
How can I solve this?

Create Table of Contents using iTextSharp

I'm working on some code that I can't make it work.
I have a program that takes multiple pdf's and merges them into one file. Now I need to create a table of contents on the first page. You can see examples of the documents below.
I would like to outsource this to someone who is an expert with iTextSharp. I don't think this will take more than an hour or two the most.
The requirements are:
The toc will be based of the bookmarks.
The toc text will be linked to the proper page so the user can click on the text to go to the page.
The existing bookmarks in sampe1.pdf must remain.
The page numbers are already calculated, so do don't have to worry about that.
The working code must be part of the VB.Net project files I give you. I've tried several snippets without luck, I would like it to just work without me having to adapt the code.
The file I generate looks like this: http://gamepacks.org/sample1.pdf
The file with toc should look like this (layout, not the font style): http://gamepacks.org/sample2.pdf
I would appreciate anyone who can help me out.
The code I used to generate sample1.pdf looks like this to give you an idea what you need to work with.
Public Sub MergePdfFiles(ByVal docList As List(Of Portal.DocumentRow), ByVal outputPath As String)
'
' http://www.vbforums.com/showthread.php?475920-Merge-Pdf-Files-and-Add-Bookmarks-to-It-(Using-iTextSharp)
'
If docList.Count = 0 Then Exit Sub
Dim tmpFile As String = "c:\STEP_1_Working.pdf"
Dim OutlineList As List(Of PdfOutline) = New List(Of PdfOutline)
Dim FirstPageIndex As Integer = 1 ' Tracks which page to link the bookmark
Dim result As Boolean = False
Dim pdfCount As Integer = 0 'total input pdf file count
Dim fileName As String = String.Empty 'current input pdf filename
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
Dim pageCount As Integer = 0 'current input pdf page count
Dim doc As iTextSharp.text.Document = Nothing 'the output pdf document
Dim writer As PdfWriter = Nothing
Dim cb As PdfContentByte = Nothing
'Declare a variable to hold the imported pages
Dim page As PdfImportedPage = Nothing
Dim rotation As Integer = 0
'Now loop thru the input pdfs
For Each row As Portal.DocumentRow In docList
reader = New iTextSharp.text.pdf.PdfReader(row.FilePath)
' Is this the first pdf file
If (row.Name = docList(0).Name) Then
doc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18)
writer = PdfWriter.GetInstance(doc, New IO.FileStream(tmpFile, IO.FileMode.Create))
' Always show the bookmarks
writer.ViewerPreferences = PdfWriter.PageModeUseOutlines
'Set metadata and open the document
With doc
.AddAuthor("Sample Title")
.AddCreationDate()
.Open()
End With
'Instantiate a PdfContentByte object
cb = writer.DirectContentUnder
End If
For i As Integer = 1 To reader.NumberOfPages
'Get the input page size
doc.SetPageSize(reader.GetPageSizeWithRotation(i))
'Create a new page on the output document
doc.NewPage()
'If it is the 1st page, we add bookmarks to the page
If i = 1 Then
If row.Parent = "" Then
Dim oline As PdfOutline = New PdfOutline(cb.RootOutline, PdfAction.GotoLocalPage(FirstPageIndex, New PdfDestination(FirstPageIndex), writer), row.Name)
Else
Dim parent As PdfOutline = Nothing
For Each tmp As PdfOutline In cb.RootOutline.Kids
If tmp.Title = row.Parent Then
parent = tmp
End If
Next
' Create new group outline
If parent Is Nothing Then
parent = New PdfOutline(cb.RootOutline, PdfAction.GotoLocalPage(FirstPageIndex, New PdfDestination(FirstPageIndex), writer), row.Parent)
End If
' Add to new parent
Dim oline As PdfOutline = New PdfOutline(parent, PdfAction.GotoLocalPage(FirstPageIndex, New PdfDestination(FirstPageIndex), writer), row.Name)
OutlineList.Add(oline)
End If
FirstPageIndex += reader.NumberOfPages
End If
'Now we get the imported page
page = writer.GetImportedPage(reader, i)
'Read the imported page's rotation
rotation = reader.GetPageRotation(i)
'Then add the imported page to the PdfContentByte object as a template based on the page's rotation
If rotation = 90 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height)
ElseIf rotation = 270 Then
cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
Next
Next
doc.Close()
End Sub