Thread View: microsoft.public.it.dotnet.vb
1 messages
1 total messages
Started by Antonio Annunziata
Fri, 02 Jun 2023 15:14
Merging the First Page of PDFs Using iText and VB/C#
Author: Antonio Annunziata
Date: Fri, 02 Jun 2023 15:14
Date: Fri, 02 Jun 2023 15:14
51 lines
3145 bytes
3145 bytes
Hello, i have written a function to merge the first page of one PDF into another using iTextSharp, and I have used the following code: ``` Public Function MergePagePdf(ByVal outputFile As String, ByVal inputFile2 As Byte(), ByVal inputFile1 As Byte(), ByRef strErrore As String) As Boolean Dim bRet As Boolean = False Dim positionx As Integer = 0 Dim positiony As Integer = 0 Dim document As iTextSharp.text.Document = New iTextSharp.text.Document() Try Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream(outputFile, FileMode.Create)) document.Open() Dim cb As PdfContentByte = writer.DirectContent Dim page1 As PdfImportedPage Dim page2 As PdfImportedPage Dim reader1 As PdfReader = New PdfReader(inputFile1) Dim reader2 As PdfReader = New PdfReader(inputFile2) document.SetPageSize(reader1.GetPageSizeWithRotation(1)) document.NewPage() page1 = writer.GetImportedPage(reader1, 1) page2 = writer.GetImportedPage(reader2, 1) cb.AddTemplate(page1, 0, 0) cb.AddTemplate(page2, positionx, positiony) If reader1.NumberOfPages > 1 Then For i As Integer = 2 To reader1.NumberOfPages document.SetPageSize(reader1.GetPageSizeWithRotation(i)) document.NewPage() page1 = writer.GetImportedPage(reader1, i) cb.AddTemplate(page1, 0, 0) Next End If bRet = True Catch e As Exception strErrore = e.Message bRet = False Finally If document IsNot Nothing Then document.Close() End Try Return bRet End Function ``` I am trying to achieve the same result with the new version of iText, but I haven't been successful. Is it possible to do it with the new version? If yes, can someone guide me on how to accomplish it? Thank you for your help. AA
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads