封面纸张是A4横,结合用的tif图纸也是A4横,
结合之后封面纸张是A4横,但是结合用的tif图纸变成A4纵了,并且文字也被缩小表示了。
利用PdfDocument.MergeFiles进行文件合并处理时,可以做到根据用户需求自己指定文件方向吗?
Dim pdfDocument As New PdfDocument()
'Add a section
Dim section As PdfSection = pdfDocument.Sections.Add()
'Set the orientation as landscape
section.PageSettings.Orientation = PdfPageOrientation.Landscape
' Add a page to the PDF document.
Dim page As PdfPageBase = section.Pages.Add()
.........
Dim width As Single = image.PhysicalDimension.Width
Dim height As Single = image.PhysicalDimension.Height
Dim pdf As New PdfDocument()
Dim section As PdfSection = pdf.Sections.Add()
section.PageSettings.Orientation = PdfPageOrientation.Landscape
Dim page As PdfPageBase = section.Pages.Add()
' Load the image directly as PdfImage to avoid unnecessary conversions
Dim image As Image = Image.FromFile("sample2.tif")
Dim pdfImage As PdfImage = PdfImage.FromImage(image)
' Get page dimensions
Dim pageWidth As Single = page.Canvas.ClientSize.Width
Dim pageHeight As Single = page.Canvas.ClientSize.Height
' Calculate scaling while maintaining aspect ratio
If pdfImage.Width > pageWidth Or pdfImage.Height > pageHeight Then
Dim widthRatio As Single = pageWidth / pdfImage.Width
Dim heightRatio As Single = pageHeight / pdfImage.Height
Dim scaleRatio As Single = Math.Min(widthRatio, heightRatio)
' Draw scaled image centered on page
Dim scaledWidth As Single = pdfImage.Width * scaleRatio
Dim scaledHeight As Single = pdfImage.Height * scaleRatio
Dim xPos As Single = (pageWidth - scaledWidth) / 2
Dim yPos As Single = (pageHeight - scaledHeight) / 2
page.Canvas.DrawImage(pdfImage, xPos, yPos, scaledWidth, scaledHeight)
Else
' Draw original image centered on page
Dim xPos As Single = (pageWidth - pdfImage.Width) / 2
Dim yPos As Single = (pageHeight - pdfImage.Height) / 2
page.Canvas.DrawImage(pdfImage, xPos, yPos, pdfImage.Width, pdfImage.Height)
End If
pdf.SaveToFile("res2222.pdf", FileFormat.PDF)
'Dim width As Single = image.PhysicalDimension.Width
'Dim height As Single = image.PhysicalDimension.Height
'If width > page.Canvas.ClientSize.Width Then
' Dim widthFitRate As Single = width / page.Canvas.ClientSize.Width
' Dim size As Size = New Size(Math.Truncate(width / widthFitRate), Math.Truncate(height / widthFitRate))
' Dim scaledImage As Bitmap = New Bitmap(image, size)
' PdfImage = PdfImage.FromImage(image)
'Else
' PdfImage = PdfImage.FromImage(image)
'End If