Change resolution while convert tiff to pdf

Hello,
I need to build a pdf document from a set of TIFF images.
I started from your useful post : https://docs.aspose.com/words/net/convert-a-document-to-pdf/
Then I need to add an extra step, because I need to change resolution to TIFF images
(set to 200 dpi if they are more).
Can you provide me a sample for that ?
Thanks

Fabio D’Antonio

Hi Fabio,

Thanks for your inquiry. As your inquiry relates to Aspose.Words, I’m moving it to respective forum. Hopefully you will be answered soon.

Best Regards,

Hi Fabio,

Thanks for your inquiry. First of all, you can use the code suggested in the following article to be able to convert images to PDF format:
https://docs.aspose.com/words/net/convert-a-document-to-pdf/

Secondly, Aspose.Words does nothing with images upon converting documents to PDF. So, quality of images must be the same as in input document. While importing images into document, you can not change the image resolution by using Aspose.Words.

Hi,
thanks for your reply.
I think there was a misunderstanding because my quqestion was about Aspose.Pdf.
Is it possible to do what I need with Aspose.Pdf ?
Thanks

Hi Fabio,

Thanks for contacting support.

When using Aspose.Pdf.Generator to convert TIFF image to PDF format, it does not have any direct property or method to specify the Resolution of image in resultant but I have logged this task as PDFNEWNET-34661 in our issue tracking system under investigations list. We will further look into the details of this requirement and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

Hi Fabio,

Thanks for your patience. We have further investigated the issue reported earlier as PDFNEWNET-34661. Please try using the following code snippet to accomplish your requirement. Please note that resolution is 199.8 because image dimensions (120x180 image dimensions and backing resized image dimensions) are integers.

[C#]

string inFile = "c:/pdftest/print.tif";
string outFile = "c:/pdftest/ImageWithDimensions.pdf";
// Instantiate a Pdf object by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
// Create a section in the Pdf object
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
// Create an image object in the section
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);
// Add image object into the Paragraphs collection of the section
sec1.Paragraphs.Add(image1);
// Set the path of image file
// resolution of the image on the document page
int resolution = 200;
// image dimensions within the page
int imageWidth = 120;
int imageHeight = 180;
Bitmap bmp = (Bitmap)Bitmap.FromFile(inFile);
// compute physical image dimensions that will be placed to the page
int newHeight = (imageHeight * resolution) / 72;
int newWidth = (imageWidth * resolution) / 72;
// resize the image to meet resolution requirement
Bitmap resized = new Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics gr = Graphics.FromImage(resized))
{
    gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    gr.DrawImage(bmp, 0, 0, newWidth, newHeight);
}
using (MemoryStream imageStream = new MemoryStream())
{
    // save the resized image to stream
    resized.Save(imageStream, System.Drawing.Imaging.ImageFormat.Tiff);
    // set the stream for the image object
    image1.ImageInfo.ImageStream = imageStream;
    // set the type of image using ImageFileType enumeration
    image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
    // adding image with dimension as 180 Height and resolution as 200
    image1.ImageInfo.FixHeight = imageHeight;
    // adding image with dimension as 300 Height and resolution as 200
    image1.ImageInfo.FixWidth = imageWidth;
    // Save the Pdf
    pdf1.Save(outFile);
}

The issues you have found earlier (filed as PDFNEWNET-34661) have been fixed in Aspose.Pdf for .NET 7.8.0update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.