Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Jan 21, 2025 5:37 am

封面纸张是A4横,结合用的tif图纸也是A4横,
结合之后封面纸张是A4横,但是结合用的tif图纸变成A4纵了,并且文字也被缩小表示了。
利用PdfDocument.MergeFiles进行文件合并处理时,可以做到根据用户需求自己指定文件方向吗?

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Tue Jan 21, 2025 6:24 am

Hello,

你好,感谢你的来信。MergeFiles合并的时候没有参数设置页面方向,针对你的情况,你可以针对合并前的PDF文档先修改页面。你可以具体提供下你目前的测试文档和代码,我进一步提供详细实现示例给你。

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Wed Jan 22, 2025 5:48 am

Thank you
I send current code and samples.
I want to combine [TEST.pdf] and [TEST.tif].
The print orientation for these files is landscape.

But , when I perform this merging process, the first page(= [TEST.pdf] ) is output in landscape orientation, and the second page(= [TEST.tif]) is output in portrait orientation.

Please teach me how to implement it.

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Wed Jan 22, 2025 6:23 am

Hello,

Thank you for your feedback. I have reviewed your code. When converting tif to PDF, please refer to the following sample code to add a landscape page.
Code: Select all
         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()
                         .........

If you have any other questions, please contact us.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Thu Jan 23, 2025 5:30 am

Thank you.
Is it possible to determine the printing direction of a tiff file and change the processing?

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Thu Jan 23, 2025 6:37 am

Hello,

Thank you for your feedback. You can judge by the height and width of the tif image. Based on the code below, if the width is greater than the height, add a landscape page, otherwise, add a portrait page.
Code: Select all
                     Dim width As Single = image.PhysicalDimension.Width
                     Dim height As Single = image.PhysicalDimension.Height

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Wed Jun 25, 2025 2:12 am

Thank you for previously showing me how to merge PDF and TIFF files. I'm currently encountering an issue where the image resolution decreases when converting a TIFF file to PDF. Could you please advise me on how to perform the conversion while maintaining the original image quality?

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Wed Jun 25, 2025 6:21 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more accurately, could you please provide us with your test code and tiff file? You can upload it as an attachment or send it to this email [email protected]. Thanks in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Wed Jul 02, 2025 6:05 am

I have attached [sample.zip], which contains the files “sample1.pdf”, “sample2.tif”, and “code.txt”.
I combined “sample1.pdf” and “sample2.tif” to create “sample3.pdf”. However, when converting “sample2.tif” to PDF, the resolution appears to have dropped, resulting in a noticeably rough display.

Additionally, “code.txt” contains the actual source code used for this process.
Could you please review it along with the files and help me resolve the issue?

Thank you in advance for your support.

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Wed Jul 02, 2025 10:36 am

Hello,

Thanks for more information.
After testing, I found that the cause of your issue may be that you use Bitmap to redraw the image. As a suggestion, please use the PdfImage object directly. I attached my test code for your reference.
Code: Select all
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)
Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Thu Jul 03, 2025 2:03 am

Thank you very much. I’ll try the approach you suggested.

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Tue Jul 29, 2025 1:12 am

Thank you for the previous source code. After implementing it, the result has improved, but the image quality is still somewhat rough.
Do you have any other suggestions or alternative solutions?

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Tue Jul 29, 2025 3:03 am

Hello,

Thanks for your reply.
Compared to your previous approach, the image quality has already improved significantly. I have uploaded my results for your reference. Could you reply and let us know the areas you would like to optimize, so we can further confirm if there is a suitable solution? Thank you in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Tue Jul 29, 2025 5:58 am

Thank you for your response.
The implemented source code is attached as a reference.
Is the implementation method correct?

maemaemae
 
Posts: 12
Joined: Tue Jan 21, 2025 5:33 am

Tue Jul 29, 2025 6:32 am

Hello,

Thanks for your reply.
Please try commenting out the code snippet below and retesting. The code snippet I provided already scales the image. Attached is the PDF generated from your tif file.
Code: Select all
'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


Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron