TIF 轉成PDF後頁面會縮小無法滿版

TIF 轉成PDF後頁面會縮小, 如何可以滿版?
以下是程式碼片段
using (FileStream fs = new FileStream($“D:\IMG2PDF.tif”, FileMode.Open, FileAccess.Read))
{
// Create a new Document object
Document pdfDocument = new Document();

            // Add a page to the PDF document
            Page page = pdfDocument.Pages.Add();

            // Create an image object
            Aspose.Pdf.Image image = new Aspose.Pdf.Image();

            // Set the image stream
            image.ImageStream = fs;
            image.ImageScale = 1.0F;
            // Add the image to the page's paragraphs collection
            page.Paragraphs.Add(image);

            // Save the PDF document
            pdfDocument.Save($"D:\\IMG2PDF.pdf");
        }

@JoeChiu

要將TIF圖像轉換為PDF並確保頁面滿版,您可以在添加圖像之前設置頁面的邊距為零,並根據圖像的尺寸調整PDF頁面的大小。以下是您可以參考的程式碼示例:

using (FileStream fs = new FileStream($"D:\\IMG2PDF.tif", FileMode.Open, FileAccess.Read))
{
    // 創建新的Document對象
    Document pdfDocument = new Document();

    // 添加一個頁面到PDF文檔
    Page page = pdfDocument.Pages.Add();

    // 設置頁面邊距為零
    page.PageInfo.Margin.Bottom = 0;
    page.PageInfo.Margin.Top = 0;
    page.PageInfo.Margin.Left = 0;
    page.PageInfo.Margin.Right = 0;

    // 創建圖像對象
    Aspose.Pdf.Image image = new Aspose.Pdf.Image();

    // 設置圖像流
    image.ImageStream = fs;

    // 將圖像添加到頁面的段落集合中
    page.Paragraphs.Add(image);

    // 保存PDF文檔
    pdfDocument.Save($"D:\\IMG2PDF.pdf");
}

在這段程式碼中,我們首先創建了一個新的PDF文檔並添加了一個頁面。然後,我們將頁面的邊距設置為零,這樣圖像就可以填滿整個頁面。最後,我們將TIF圖像添加到頁面中並保存PDF文檔。

這樣的設置應該能夠解決您遇到的頁面縮小問題,確保圖像滿版顯示。

來源:
[1]: Convert various Images formats to PDF in .NET - Aspose Documentation

原始.TIF 只有259kb,轉換成PDF後變成1,306kb,轉換後要如何維持一樣259kb左右

@JoeChiu

请尝试在添加TIF图像后优化PDF文档,以减少文件大小。

以下是我照著範例但看來不行,001.tif 原始259kb,轉換成001.pdf變1,306kb

using (FileStream fs = new FileStream(@“D:\001.tif”, FileMode.Open, FileAccess.Read))
{
// 創建新的Document對象
Document pdfDocument = new Document();

            // 添加一個頁面到PDF文檔
            Page page = pdfDocument.Pages.Add();

            // 設置頁面邊距為零
            page.PageInfo.Margin.Bottom = 0;
            page.PageInfo.Margin.Top = 0;
            page.PageInfo.Margin.Left = 0;
            page.PageInfo.Margin.Right = 0;
            // 創建圖像對象
            Aspose.Pdf.Image image = new Aspose.Pdf.Image();

            // 設置圖像流
            image.ImageStream = fs;

            // 將圖像添加到頁面的段落集合中
            page.Paragraphs.Add(image);

            var optimizeOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
            optimizeOptions.ImageCompressionOptions.CompressImages = true;
            optimizeOptions.ImageCompressionOptions.ImageQuality = 50;
            pdfDocument.OptimizeResources(optimizeOptions);

            // 保存PDF文檔
            pdfDocument.Save(@"D:\001.pdf");
            MessageBox.Show("轉檔完成");
        }

@JoeChiu

Can you please share your sample TIFF image in .zip format with us? We will test the scenario in our environment and address it accordingly.