Article View: microsoft.public.it.dotnet.vb
Article #1Merging the First Page of PDFs Using iText and VB/C#
From: 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
Technical Details
Message-ID:
<417d96f6-346a-49f4-925a-ccb429fe1aaen@googlegroups.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nnrp.usenet.blueworldhosting.com!!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <417d96f6-346a-49f4-925a-ccb429fe1aaen@googlegroups.com> Subject: Merging the First Page of PDFs Using iText and VB/C# Date: Fri, 02 Jun 2023 15:14:52 +0000 From: Antonio Annunziata <antann@gmail.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nnrp.usenet.blueworldhosting.com!!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail X-Received: by 2002:a05:620a:29d2:b0:74e:2894:7eb2 with SMTP id s18-20020a05620a29d200b0074e28947eb2mr2716707qkp.12.1685718892801; X-Received: by 2002:a05:6902:1108:b0:ba8:93c3:331a with SMTP id o8-20020a056902110800b00ba893c3331amr2148399ybu.5.1685718892538; Fri, 02 Jun Newsgroups: microsoft.public.it.dotnet.vb Injection-Info: google-groups.googlegroups.com; posting-host=93.149.133.183; posting-account=Q7YYGgoAAAA-D_yG0ZsusEKgA_Qj0AN5 NNTP-Posting-Host: 93.149.133.183 User-Agent: G2/1.0 MIME-Version: 1.0 Injection-Date: Fri, 02 Jun 2023 15:14:52 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 2800