1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
Dim result As Boolean = False
Dim f As Integer = 0 'Pointeur le fichier en cours
Dim fileName As String = String.Empty 'Nom du fichier pdf en cours
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing 'Reader itext
Dim pageCount As Integer = 0 'Nombre de pages sur le PDF en cours
Dim pdfDoc As iTextSharp.text.Document = Nothing 'Fichier de sortie
Dim writer As iTextSharp.text.pdf.PdfWriter = Nothing 'Writer itext
Dim cb As iTextSharp.text.pdf.PdfContentByte = Nothing
Dim page As iTextSharp.text.pdf.PdfImportedPage = Nothing 'page importée
Dim rotation As Integer = 0
Dim filefront As String
Dim outputpath As String = ""
'Ouvre background
fileName = "c:\background.pdf"
filefront = "c:\front.pdf"
outputpath = "c:\sortie.pdf"
reader = New iTextSharp.text.pdf.PdfReader(fileName)
pdfDoc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18)
writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, New IO.FileStream(outputpath, IO.FileMode.Create))
pdfDoc.Open()
cb = writer.DirectContent
'Creation d'une nouvelle page de sortie
pdfDoc.NewPage()
page = writer.GetImportedPage(reader, 1)
'récupère la rotation de la page
rotation = reader.GetPageRotation(1)
'ajoute la page importée au contentbyte en tenant compte de la rotation
If rotation = 90 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(1).Height)
ElseIf rotation = 270 Then
cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(1).Width + 60, -30)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
reader = New iTextSharp.text.pdf.PdfReader(filefront)
cb = writer.DirectContent
page = writer.GetImportedPage(reader, 1)
'récupère la rotation de la page
rotation = reader.GetPageRotation(1)
'ajoute la page importée au contentbyte en tenant compte de la rotation
If rotation = 90 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(1).Height)
ElseIf rotation = 270 Then
cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(1).Width + 60, -30)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
pdfDoc.Close() |
Partager