Look at the file concat_pdf.java, it's only 20 lines it shouldn't be
that difficult to understand.

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Douglas A. White
> Sent: Thursday, March 16, 2006 4:41 PM
> To: [email protected]
> Subject: [iText-questions] Newbie Concat PDF question - iTextSharp
> 
> Hi All,
> 
> I'm just getting started with ASP.NET and have created several PDFs of
> reports using Crystal Reports.
> 
> I now need a way to concatenate all 14 PDFs together into one 
> large PDF
> since CR doesn't allow for nested subreports.  We're using
> ASP.NET/VB.NET under the 2.0 .NET Framework.
> 
> I used Kamal Patel's C# to VB.NET converter to convert the Concat.cs
> code into VB and then set that as a function to which I'm 
> trying to pass
> references to the various PDFs to concatenate them together, but I'm
> getting a file not found error for the output PDF report.
> 
> A code snippet for trying to concatenate just the first two reports
> (Section01.pdf and Section02.pdf) together to form a 3rd report
> (ConcatenatedReport.pdf) consisting of Section01.pdf with 
> Section02.pdf
> appended afterwards.
> 
> I'm getting a file not found error for the "ConcatenatedReport.pdf"
> file.
> 
> What am I doing wrong?  Is there a better/simpler way to do this?  I
> don't mind hard-coding all 14 filenames in.
> 
> TIA,  Doug
> 
> ***************************
> My non-working Code snippet
> ***************************
> 
> Imports CrystalDecisions.CrystalReports.Engine
> Imports CrystalDecisions.Shared
> Imports System.IO
> Imports iTextSharp.text
> Imports iTextSharp.text.pdf
> 
> 
> Namespace scf
> 
> Partial Class SectionAll
>     Inherits System.Web.UI.Page
> 
> #Region " Web Form Designer Generated Code "
> 
>     'This call is required by the Web Form Designer.
>     <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
> 
>     End Sub
> 
> 
>     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
>         'CODEGEN: This method call is required by the Web 
> Form Designer
>         'Do not modify it using the code editor.
>         InitializeComponent()
>     End Sub
> 
> #End Region
> 
>     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>         'Put user code to initialize the page here
> 
>         Dim args(3) As String
> 
>         Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
>         Dim myDiskFileDestinationOptions As
> CrystalDecisions.Shared.DiskFileDestinationOptions
>         Dim myExportFileAll, myExportFile01, myExportFile02 As String
>         Dim myReport01 As New ReportDocument
>         Dim myReport02 As New ReportDocument
> 
>         myReport01.Load(Server.MapPath("Section1_rpt.rpt"))
>         myReport02.Load(Server.MapPath("Section2_rpt.rpt"))
> 
>         myExportFile01 =
> "D:\Inetpub\wwwroot\projects\PrintOuts\Section01.pdf"
>         myDiskFileDestinationOptions = New
> CrystalDecisions.Shared.DiskFileDestinationOptions
>         myDiskFileDestinationOptions.DiskFileName = myExportFile01
>         myExportOptions = myReport01.ExportOptions
>         myReport01.SetParameterValue("ShipID", Session("ShipID"))
> 
>         With myExportOptions
>             .DestinationOptions = myDiskFileDestinationOptions
>                 .ExportDestinationType = 
> ExportDestinationType.DiskFile
>                 .ExportFormatType = ExportFormatType.PortableDocFormat
>         End With
>         myReport01.Export()
> 
>         myExportFile02 =
> "D:\Inetpub\wwwroot\projects\PrintOuts\Section02.pdf"
>         myDiskFileDestinationOptions = New
> CrystalDecisions.Shared.DiskFileDestinationOptions
>         myDiskFileDestinationOptions.DiskFileName = myExportFile02
>         myExportOptions = myReport02.ExportOptions
>         myReport02.SetParameterValue("ShipID", Session("ShipID"))
> 
>         With myExportOptions
>             .DestinationOptions = myDiskFileDestinationOptions
>                 .ExportDestinationType = 
> ExportDestinationType.DiskFile
>                 .ExportFormatType = ExportFormatType.PortableDocFormat
>         End With
>         myReport02.Export()
> 
>         myExportFileAll =
> "D:\Inetpub\wwwroot\projects\PrintOuts\ConcatenatedReport.pdf"
> 
>         args.SetValue(myExportFileAll, 0)
>         args.SetValue(myExportFile01, 1)
>         args.SetValue(myExportFile02, 2)
> 
>         ConcatPDF(args)
> 
>         Response.ClearContent()
>         Response.ClearHeaders()
>         Response.ContentType = "application/pdf"
> 
>         Response.WriteFile(myExportFileAll)
>         Response.Flush()
>         Response.Close()
>         System.IO.File.Delete(myExportFileAll)
>     End Sub
> 
> End Class
> 
> End Namespace
> 
> 
> 
> **************************
> ConcatPDF.vb code
> ***************************
>  
> Public Class Concat
>  '    *
> '     * @param args the command line arguments
> '     */
>       Public Shared  Sub Main(ByVal args() As String)
>               If args.Length < 3 Then
>                       Console.Error.WriteLine("This tools needs at
> least 3 parameters:\njava Concat destfile file1 file2 [file3 ...]")
>               Else 
>                       Try
>                               Dim f As Integer =  1 
>                               ' we create a reader for a certain
> document
>                               Dim reader As PdfReader =  New
> PdfReader(args(f)) 
>                               ' we retrieve the total number of pages
>                               Dim n As Integer =  reader.NumberOfPages
> 
>                               Console.WriteLine("There are " + n + "
> pages in the original file.")
>  
>                               ' step 1: creation of a document-object
>                               Dim document As Document =  New
> Document(reader.getPageSizeWithRotation(1)) 
>                               ' step 2: we create a writer that
> listens to the document
>                               Dim writer As PdfWriter =
> PdfWriter.getInstance(document,New 
> FileStream(args(0),FileMode.Create)) 
>                               ' step 3: we open the document
>                               document.Open()
>                               Dim cb As PdfContentByte =
> writer.DirectContent 
>                               Dim page As PdfImportedPage
>                               Dim rotation As Integer
>                               ' step 4: we add content
>                               While f < args.Length
>                                       Dim i As Integer =  0 
>                                       While i < n
>                                               i = i + 1
>       
> document.setPageSize(reader.getPageSizeWithRotation(i))
>                                               document.NewPage()
>                                               page =
> writer.getImportedPage(reader, i)
>                                               rotation =
> reader.getPageRotation(i)
>                                               If rotation = 90 Or
> rotation = 270 Then
>       
> cb.addTemplate(page, 0, -1f, 1f, 0, 0,
> reader.getPageSizeWithRotation(i).Height)
>                                               Else 
>       
> cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0)
>                                               End If
>       
> Console.WriteLine("Processed page " + i)
>                                       End While
>                                       f = f + 1
>                                       If f < args.Length Then
>                                               reader = New
> PdfReader(args(f))
>                                               ' we retrieve the total
> number of pages
>                                               n = reader.NumberOfPages
>                                               Console.WriteLine("There
> are " + n + " pages in the original file.")
>                                       End If
>                               End While
>                               ' step 5: we close the document
>                               document.Close()
>                       Catch e As Exception
>                               Console.Error.WriteLine(e.Message)
>                               Console.Error.WriteLine(e.StackTrace)
>                       End Try
>               End If
>       End Sub
>  
> End Class
> 
> '----------------------------------------------------------------
> ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
> ' Developed by: Kamal Patel (http://www.KamalPatel.net) 
> '----------------------------------------------------------------
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking 
> scripting language
> that extends applications into web and mobile media. Attend 
> the live webcast
> and join the prime developer group breaking into this new 
> coding territory!
> http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to