Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 将清晰的图像带到前面_Image_Pdf_Itextsharp - Fatal编程技术网

Image 将清晰的图像带到前面

Image 将清晰的图像带到前面,image,pdf,itextsharp,Image,Pdf,Itextsharp,为我们的web应用程序构建文档生成系统,并根据需要对文档进行标记。该文档以powerpoint格式设计,并通过PDF打印。第一页基本上是一个大图像,图像中有一个白色区域。 我试图将品牌标识放置在分配的空白处。定位是确定的,但是,我的品牌形象出现在PDF文档的全页图像后面 谷歌搜索之后,我似乎找不到“z-index”类型的函数。。。会以为我不是唯一一个有这个问题的人吗 添加图像的代码部分如下所示: image.ScaleToFit(width, height); i

为我们的web应用程序构建文档生成系统,并根据需要对文档进行标记。该文档以powerpoint格式设计,并通过PDF打印。第一页基本上是一个大图像,图像中有一个白色区域。 我试图将品牌标识放置在分配的空白处。定位是确定的,但是,我的品牌形象出现在PDF文档的全页图像后面

谷歌搜索之后,我似乎找不到“z-index”类型的函数。。。会以为我不是唯一一个有这个问题的人吗

添加图像的代码部分如下所示:

        image.ScaleToFit(width, height);
        image.SetDpi(300, 300);

        // Position the logo.
        image.SetAbsolutePosition(fromLeft, fromBottom);

        // Add the image.
        document.Add(image);

非常奇怪的是,您需要以下行将图像添加到现有PDF:

document.Add(image);
这就好像你用的是PdfWriter而不是PdfStamper,这会很奇怪

在开始编写代码之前,可能您忽略了或没有搜索StackOverflow:


您可能已经找到了使用GetUnderContent的示例。这将在现有内容下添加内容。如果希望内容覆盖现有内容,则需要GetOverContent,如代码示例所示。

可能有点晚了,但我也遇到了同样的问题,我已经通过以下段落解决了问题,代码在Visual Basic中:

Public Class PDF

  Public Doc As Document
  Public Writer As PdfWriter
  Public Cb As PdfContentByte

  Public Sub setFrontImage(ByVal _appendImg As String, align As Integer, x As Integer, y As Integer, ByVal w As Integer, h As Integer, _leading As Integer)

    Dim ct As New ColumnText(Cb)
    Dim ph As Phrase
    Dim ch As Chunk

    Dim p As Paragraph = new Paragraph()
    Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(_appendImg)
    image.ScaleAbsolute(w, h)
    p.Add(new Chunk(image,x,y))

    ct.SetSimpleColumn(p,x, y, w, h, _leading, align)
    ct.Go()

  End Sub
End Class

<>我看到你用绝对的位置把你的标志放在你的图像上,所以我认为,如果你不需要在限制的空间内使用它,那么就要修改块的使用宽度和高度。我们使用的包装器是几年前写的,到现在为止工作得很好。可能是引用文档时使用的示例。不确定,我会调查的。谢谢你的建议。好的,经过进一步的调查,我们正在使用PdfReader和PdfWriter,但是出于某种原因,我们使用文档来添加图像。这肯定是一个疏忽——尽管一直在起作用。我们基本上是合并各种文档,然后添加所需的图像。对PdfContentByte.AddImage和图像的快速更改将正确显示分层。使用PdfWriter和文档将丢弃所有交互功能。请正确使用iText!有大量使用PdfWriter的在线示例。他们都用错了吗?不幸的是,他们中的大多数都不正确,这对写官方文档的人(即我)和遵循错误建议的人来说都是令人沮丧的。合并文档是使用PdfCopy或PdfSmartCopy完成的,而不是使用PdfWriter。
Public Class PDF

  Public Doc As Document
  Public Writer As PdfWriter
  Public Cb As PdfContentByte

  Public Sub setFrontImage(ByVal _appendImg As String, align As Integer, x As Integer, y As Integer, ByVal w As Integer, h As Integer, _leading As Integer)

    Dim ct As New ColumnText(Cb)
    Dim ph As Phrase
    Dim ch As Chunk

    Dim p As Paragraph = new Paragraph()
    Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(_appendImg)
    image.ScaleAbsolute(w, h)
    p.Add(new Chunk(image,x,y))

    ct.SetSimpleColumn(p,x, y, w, h, _leading, align)
    ct.Go()

  End Sub
End Class