Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从多个图像生成单个PDF_C#_Asp.net_Pdf_Pdf Generation - Fatal编程技术网

C# 从多个图像生成单个PDF

C# 从多个图像生成单个PDF,c#,asp.net,pdf,pdf-generation,C#,Asp.net,Pdf,Pdf Generation,我需要从多个图像创建一个pdf文件。例如,我有12个图像,然后pdf将生成3个页面,其中4个图像在单个页面中,2个图像在一行中 那么,是否有任何dll示例可以用于从图像生成pdf?看看这本书,这或多或少也涵盖了iTextSharp,它是iText pdf库的.NET版本。也就是说,您必须编写的C#与Java代码示例几乎相同 您可以从下载示例。一个特别有趣的示例(Java代码)是上的示例。相应的C#示例可在上找到 祝你好运 有多个库支持此功能: iTextSharp-: - 谢谢,我已经用这个表

我需要从多个图像创建一个pdf文件。例如,我有12个图像,然后pdf将生成3个页面,其中4个图像在单个页面中,2个图像在一行中

那么,是否有任何dll示例可以用于从图像生成pdf?

看看这本书,这或多或少也涵盖了iTextSharp,它是iText pdf库的.NET版本。也就是说,您必须编写的C#与Java代码示例几乎相同

您可以从下载示例。一个特别有趣的示例(Java代码)是上的示例。相应的C#示例可在上找到


祝你好运

有多个库支持此功能:

  • iTextSharp-:
  • -

  • 谢谢,我已经用这个表在一个pdf页面上创建了6个图像

    Public Function CreatePDF(images As System.Collections.Generic.List(Of Byte())) As String
            Dim PDFGeneratePath = Server.MapPath("../images/pdfimages/")
            Dim FileName = "attachmentpdf-" & DateTime.Now.Ticks & ".pdf"
    
            If images.Count >= 1 Then
                Dim document As New Document(PageSize.LETTER)
                Try
                    ' Create pdfimages directory in images folder.
                    If (Not Directory.Exists(PDFGeneratePath)) Then
                        Directory.CreateDirectory(PDFGeneratePath)
                    End If
    
                    ' we create a writer that listens to the document
                    ' and directs a PDF-stream to a file
                    PdfWriter.GetInstance(document, New FileStream(PDFGeneratePath & FileName, FileMode.Create))
    
                    ' opens up the document
                    document.Open()
                    ' Add metadata to the document.  This information is visible when viewing the
    
                    ' Set images in table
                    Dim imageTable As New PdfPTable(2)
                    imageTable.DefaultCell.Border = Rectangle.NO_BORDER
                    imageTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER
    
                    For ImageIndex As Integer = 0 To images.Count - 1
                        If (images(ImageIndex) IsNot Nothing) AndAlso (images(ImageIndex).Length > 0) Then
                            Dim pic As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(SRS.Utility.Utils.ByteArrayToImage(images(ImageIndex)), System.Drawing.Imaging.ImageFormat.Jpeg)
    
                            ' Setting image resolution
                            If pic.Height > pic.Width Then
                                Dim percentage As Single = 0.0F
                                percentage = 400 / pic.Height
                                pic.ScalePercent(percentage * 100)
                            Else
                                Dim percentage As Single = 0.0F
                                percentage = 240 / pic.Width
                                pic.ScalePercent(percentage * 100)
                            End If
    
                            pic.Border = iTextSharp.text.Rectangle.BOX
                            pic.BorderColor = iTextSharp.text.BaseColor.BLACK
                            pic.BorderWidth = 3.0F
    
                            imageTable.AddCell(pic)
                        End If
                        If ((ImageIndex + 1) Mod 6 = 0) Then
                            document.Add(imageTable)
                            document.NewPage()
    
                            imageTable = New PdfPTable(2)
                            imageTable.DefaultCell.Border = Rectangle.NO_BORDER
                            imageTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER
                        End If
                        If (ImageIndex = (images.Count - 1)) Then
                            imageTable.AddCell(String.Empty)
                            document.Add(imageTable)
                            document.NewPage()
                        End If
                    Next
                Catch ex As Exception
                    Throw ex
                Finally
                    ' Close the document object
                    ' Clean up
                    document.Close()
                    document = Nothing
                End Try
            End If
    
            Return PDFGeneratePath & FileName
        End Function
    

    google for iTextSharp非常有用,可用于创建pdf并将图像放入其中。您已检查过,例如,是的,这是一个很好的示例。如何在第页添加4个图像..任何应用于代码的设置。我向您发送了一个关于如何添加多个图像的iTextSharp链接示例。如果您想让它们以不同的方式显示,只需将它们添加到表格而不是段落中即可。我没有试过,但它应该能起作用。或者,如果这还不够,您可以将它们合并到c中。如何在c#中合并图像:注意:itext是商业或AGPLP什么是PdfWriter?@Kiquenet它来自itextSharp。全名为“iTextSharp.text.pdf.PdfWriter”