We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

After converting Tif to PDF, I can not shrink the image too much

When converting tif files to PDF, the pdf file looks good.
When I try to open it, and making bigger using (+ sign) there is no problem, but, I can NOT make it small using (- sign)

Example.JPG (6.1 KB)

@bsotelo,

Please share the input TIFF image and sample code with us to reproduce the issue. We will check your issue soon.

Files.zip (42.1 KB)
We are calling AddImageToNewPage method, and after saving the image, we call OptimizeDocument

private void AddImageToNewPage(string sourceImageFile, Document doc)
{
using (var ms = new MemoryStream())
{
using (var sourceFileStream = new FileStream(sourceImageFile, FileMode.Open))
{
sourceFileStream.CopyTo(ms);

                var myImage = new Bitmap(ms);
                // Convert multi page or multi frame TIFF to PDF
                var dimension = new FrameDimension(myImage.FrameDimensionsList[0]);
                var frameCount = myImage.GetFrameCount(dimension);

                // Iterate through each frame
                for (var frameIdx = 0; frameIdx <= frameCount - 1; frameIdx++)
                {
                    var page = doc.Pages.Add();
                    myImage.SelectActiveFrame(dimension, frameIdx);
                    var currentImage = new MemoryStream();
                    myImage.Save(currentImage, ImageFormat.Tiff);

                    SetPageInfo(myImage, page);

                    var image = new Aspose.Pdf.Image { ImageStream = currentImage };

                    
                    if (IsABlackAndWhiteImage(myImage))
                        image.IsBlackWhite = true;

                    page.Paragraphs.Add(image);
                }
            }
        }
    }

    public void SetPageInfo(Bitmap myImage, Page page)
    {
        page.PageInfo.IsLandscape = myImage.Width > myImage.Height;
        page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
        page.PageInfo.Height = myImage.Height;
        page.PageInfo.Width = myImage.Width;
    }

    public bool IsABlackAndWhiteImage(Bitmap myImage)
    {
        var isBlackAndWhite = myImage.PixelFormat == PixelFormat.Format1bppIndexed;
        return isBlackAndWhite;
    }

    private void OptimizeDocument(Document doc)
    {
        var optimizationOptions = new OptimizationOptions()
        {
            AllowReusePageContent = true,
            LinkDuplcateStreams = true,
            RemoveUnusedObjects = true,
            RemoveUnusedStreams = true,
            //UnembedFonts = true
        };

        optimizationOptions.ImageCompressionOptions.Version = ImageCompressionVersion.Mixed;
        optimizationOptions.ImageCompressionOptions.ImageQuality = 100;
        optimizationOptions.ImageCompressionOptions.CompressImages = true;
        optimizationOptions.ImageCompressionOptions.ResizeImages = true;
        // optimizationOptions.ImageCompressionOptions.MaxResolution = 144;

        // optimizationOptions.ImageEncoding = ImageEncoding.Jpeg;

        doc.OptimizeSize = true;
        doc.OptimizeResources(optimizationOptions);
    }

@bsotelo

We are checking the scenario and will get back to you shortly.

@bsotelo

Would you kindly share how you are viewing the generated PDF? Are you opening it in Adobe Reader? By using (+) and (-) signs, do you mean zoom in/out? Please share some more details to replicate this issue at our side so that we can address it accordingly.

ExampleFile.JPG (15.4 KB)
I double click to the pdf file and it opens in Microsoft Edge
I’m attaching a screenshot.
if I click over the “-”, I can NOT make the image smaller
if I click over the “+” I can make the image bigger

@bsotelo

This behavior seems specific to the viewer offered with Microsoft Edge Browser. It restores the PDF document to 100% zoom or default size upon pressing (-) sign. Please note that Aspose.PDF cannot control the behavior or settings of the PDF Viewers. If you open the PDF in Adobe Reader, you can notice that it allows to Zoom in/out as per your desired level. Please feel free to let us know in case you need more information or face any issues while using the API.

Before, we were generating pdf files without applying optimization functionality, and we were able to use the (-) and (+) to making smaller or bigger, but the images size was huge, and was recommended by you, to use optimization functionality, in order to have a good pdf size. After using optimization, we are experiencing not able to make the image small (-)
Attached you will find an example of a pdf (without optimization), and able to making small and big
ExampleImageMakingSmallAndBig.pdf (1.5 MB)

@bsotelo

We were able to notice this behavior in our environment as well. Therefore, an investigation ticket as PDFNET-51095 has been logged in our issue management system. We will further look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Any idea when about ISSUE: PDFNET-51095 will be done?

@bsotelo

The issue has been logged under free support model and it will be resolved on a first come first serve basis. We will surely inform you once we have some definite updates regarding its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.