从 tiff 转换为 Pdf 时,DPI 分辨率会导致问题

DPI resolution is causing issues when converting from tiff to Pdf

我在将 .tif 转换为 .pdf 时遇到问题。基本上对于水平和垂直 DPI 均为 96 的每个文档,转换仅捕获文档的左上角 - 它被极度拉伸。但是,如果文档的水平 DPI 为 204,垂直 DPI 为 196,则可以正确显示。这是我需要在我的代码(下面)中解决的问题,还是我有必要为我的文档的每一页更新 DPI 分辨率(我必须以编程方式执行)以便 dpi 在将其转换为 204 和 96 之前pdf.

    Dim destination As String = FileName & "pdf"

    Dim MyImage As Image = Image.FromFile(FileName & "tif")

    Dim doc As New PdfDocument()

    For PageIndex As Integer = 0 To MyImage.GetFrameCount(FrameDimension.Page) - 1
        MyImage.SelectActiveFrame(FrameDimension.Page, PageIndex)

        Dim img As XImage = XImage.FromGdiPlusImage(MyImage)
        Dim page = New PdfPage()

        If img.PixelWidth > img.PixelHeight Then
            page.Orientation = PageOrientation.Landscape
        Else
            page.Orientation = PageOrientation.Portrait
        End If
        doc.Pages.Add(page)

        Dim xgr As XGraphics = XGraphics.FromPdfPage(doc.Pages(PageIndex))

        xgr.DrawImage(img, 0, 0)
    Next
    doc.Save(destination)
    doc.Close()
    MyImage.Dispose()

PDF 页面没有任何 DPI(矢量格式)。

在 Windows 中,对于没有可用 DPI 信息的图像,您通常会获得 96 DPI。 如果图像以 200 DPI 扫描,但 Windows 报告 96 DPI,则 PDF 中的图像将有两倍大小,您将只能看到扫描图像的四分之一(假设您将扫描的 A4 页面绘制到新的A4 页)。
204/196 DPI 听起来像传真格式,所以我假设我们在谈论扫描的页面。

Hans Passant 已经给了你解决方案:在调用 DrawImage 时指定目标矩形,你可以让所有图像填满整个页面。