Free Support Forum - aspose.com

Changing orientation

Hi,

I have a Multi Page Tiff in which some image will fit in Portrait and some will fit into Landscape.

I am trying to convert that to a PDF file.

Is there a way that the PDF file generated will have some page in portrait and some in landscape so that image does not appear cut or shrinked.

Here is my input tiff... (see attachment)

You will notice that Page 1-3 is a candidate for A4 where as 4-5 can do with some other pageSize but they all should be in one PDF file.

Can this be done... If yes .. Can you provide me some code snippet

Thanks & regards,

Vikash

Hello Vikash,

Thanks for using our products.

With the current release version, it's possible that you can change the page orientation of PDF document when placing multiple TIFF images inside a single document (for Landscape TIFF images set the orientation as Landscape and for Portrait TIFF's, set the orientation as Portrait). However, I am afraid you might not be able to access individual frames from TIFF image and place them over specific pages (after specifying the orientation information for that particular page). For the sake of implementation, the feature of accessing individual TIFF frames is already logged in our issue tracking system as PDFNET-24181 under new features list and the requirement of placing contents over specific pages inside PDF is also logged as PDFNET-24242. Currently all the contents inside PDF document are added in Flow-Layout (Top-Left to Bottom-Right) approach.

Please be patient and spare us little time. Once these features become available, we would be more than happy to update with the status of correction. We apologize for your inconvenience.

Hello Nayyer Shahbaz,

I am facing the similar problem, can you please provide me with the code sample for setting the orientation to Landscape or portrait based on the input image orientation format.

Thanks,
Jess

Hi Jess,


Thanks for contacting support.

I am afraid the feature to get particular frame from TIFF image is not yet implemented. However if you have individual image files with different orientation, you may consider following the instructions specified over following link for setting page orientation according to image dimensions How to Set page orientation according to image dimensions.

We are sorry for your inconvenience.

Hello Nayyer Shahbaz,
Thanks for the immediate response. Well that is what I am looking for setting the page orientation.
But the link you provided as I am new to your product, I am having hard time to reach the correct sample for saving the different TIFF images to PDF as landscape or portrait as per the input provided.

I figured out the other documents for page orientation. But for the tiff images I am not successful.
I tried couple of different ways but still the PDF output produced shows the Portrait display irrespective the orientation of TIFF images provided as input.

Please advice or provide a working sample of code for dealing with different page orientation of tiff images to be converted to PDF.

Thanks
Jess

Hello Jess,


Thanks for your patience.

I have tested the scenario using PDF file which you have shared over 430091 and as per my observations, the TIFF image is appearing as Landscape in resultant PDF file. Please take a look over the attached PDF file which I have generated using Aspose.Pdf for .NET 7.5.0 using following code snippet (its based on code snippet which you have shared over 430091).

[C#]

bool ModifySize = false;<o:p></o:p>

var p = new Pdf();

var sect1 = p.Sections.Add();

// Create a BitMap object

// Set margins so image will fit, etc.

sect1.PageInfo.Margin.Top = 5;

sect1.PageInfo.Margin.Bottom = 5;

sect1.PageInfo.Margin.Left = 5;

sect1.PageInfo.Margin.Right = 5;

TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));

Bitmap image = new Bitmap("c:/pdftest/Sample1_Tiff_Version+.tif");

var imageht = new Aspose.Pdf.Generator.Image(sect1);

imageht.ImageInfo.ImageFileType = ImageFileType.Tiff;

imageht.ImageInfo.TiffFrame = -1;

Console.WriteLine("Image Height--" + image.Height);

Console.WriteLine("Page Height" + sect1.PageInfo.PageHeight);

Console.WriteLine("Image Width--" + image.Width);

Console.WriteLine("Page Width" + sect1.PageInfo.PageWidth);

//Add image object into the Paragraphs collection of the sect1tion

sect1.Paragraphs.Add(imageht);

int imgHt = (int)sect1.PageInfo.PageHeight;

int imgWth = (int)sect1.PageInfo.PageWidth;

if (image.Width > sect1.PageInfo.PageWidth)

{

Console.WriteLine("Image width is greater than Page width");

sect1.IsLandscape = true;

}

else {

Console.WriteLine("Image Width is less than Page width");

sect1.IsLandscape = false;

}

imageht.ImageInfo.SystemImage = image;

p.Save("c:/pdftest/Sample1_Tiff_Version+.pdf");


I have not changed the width and height of input image and have placed it in its original dimensions. In case you still face the same problem, please feel free to contact.

I have a Aspose.Pdf. Kit Version 5.5.0.0 and Aspose.Pdf Version 5.2.0.0.

I am facing the error, "The type or namespace name ‘Generator’ does not exist in the namespace ‘Aspose.Pdf’ ".

So does this version supports or do I need to upgrade to newer versions.
Also I replaced your code of line :
var imageht=new Aspose.Pdf.Generator.Image(sect1);
With
var imageht=new Aspose.Pdf.Image(sect1);
and I was able to run the application, but still the pdf document that was produced from same tiff image is Portrait version.


Thanks,
Jess

Hi Jess,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the details.

Well, Aspose.Pdf.Generator is not supported with the version you are using. You will need to upgrade to the newer version of Aspose.Pdf for .NET (v6.0 and above). I would suggest you to download and try the latest version of Aspose.Pdf for .NET v7.5 as it works fine as per your requirements (as shared by Nayyer).

Also, in the latest versions, Aspose.Pdf.Kit for .NET and Aspose.Pdf for .NET are merged in one product i.e. Aspose.Pdf for .NET. All the features of Aspose.Pdf.Kit for .NET can be found under Aspose.Pdf.Facades namespace in Aspose.Pdf for .NET.

You can see the following documentation link regarding details on how to upgrade your code from old Aspose.Pdf for .NET to newer version of Aspose.Pdf for .NET (v6.0 and above).

http://www.aspose.com/docs/display/pdfnet/Migration+from+Aspose.Pdf+Pre+6.x

http://www.aspose.com/docs/display/pdfnet/Migration+from+Aspose.Pdf.Kit

Sorry for the inconvenience,

Hello Nausherwan Aslam,

Thanks for sharing this information.
Can you suggest if the orientation problem can be fixed with my current version (as indicated in the previous response).

As stated previously, how can I have dynamic page orientation for the produced PDF document from TIFF image, because currently after converting the tiff to PDF the output that is produced is portrait display in PDF, where as the input is landscaped Tiff document.

Please advice.
Jess

jatrules:
Can you suggest if the orientation problem can be fixed with my current version (as indicated in the previous response).

As stated previously, how can I have dynamic page orientation for the produced PDF document from TIFF image, because currently after converting the tiff to PDF the output that is produced is portrait display in PDF, where as the input is landscaped Tiff document.
Hello Jess,

Did you get the chance to have a look over the PDF file which I have generated against 430392 post. As per my observations, the output which I have generated is in Landscape orientation. Furthermore, before upgrading your subscription against Aspose.Pdf for .NET 7.5.0, can you please test this release version in trial mode. It will help you and us in determining that the problem is actually resolved in new release version. We are sorry for this inconvenience.

PS, I am afraid we might not be able to fix any issue in older release versions because all the enhancements and bug fixing is performed against latest release versions.

Hello Nayyer Shahbaz,
I have attached:
1. the sample code snippet
2. the original .tif image, and
3. the produced .pdf image using the version7.5 for Aspose.Pdf.

But still you can see the image produced has scaling and aspect ratio problem.
The orientation problem still persists.

Please advice and provide some working sample that can support the aspect ratio , scaling while dealing with the orientation(portrait/landscape) depending upon the input image provided.

Thanks
Jess

Code Snippet:

{
bool ModifySize=false;
var p=new Pdf();
var sect1=p.Sections.Add();

// Create a BitMap object

// Set margins so image will fit, etc.
sect1.PageInfo.Margin.Top=5;
sect1.PageInfo.Margin.Bottom=5;
sect1.PageInfo.Margin.Left=5;
sect1.PageInfo.Margin.Right=5;

TypeConverter tc=TypeDescriptor.GetConverter(typeof(Bitmap));
//Bitmap myimage=(Bitmap)tc.ConvertFrom(data.File);
FileStream fs=File.OpenRead(@“c:\abc.tif”);
byte[] byteArray=new byte[fs.Length];
fs.Read(byteArray,0,Convert.ToInt32(fs.Length));


Bitmap image=new Bitmap(fs);

var imageht=new Aspose.Pdf.Generator.Image(sect1);//Version7.5 for Aspose.Pdf
//var imageht=new Aspose.Pdf.Generator.Image(sect1);//Version 5.2 for Aspose.Pdf

imageht.ImageInfo.ImageFileType=ImageFileType.Tiff;
imageht.ImageInfo.TiffFrame=-1;

//Add image object into the Paragraphs collection of the sect1tion
sect1.Paragraphs.Add(imageht);
int imgHt=(int)sect1.PageInfo.PageHeight;
int imgWth=(int)sect1.PageInfo.PageWidth;
int imageheight=image.Height;
int imagewidth=image.Width;

var ratioX=(double)imgWth/image.Width;
var ratioY=(double)imgHt/image.Height;

var ratio=Math.Min(ratioX,ratioY);

var newWidth=(int)(image.Widthratio);
var newHeight=(int)(image.Height
ratio);

if(image.Width>sect1.PageInfo.PageWidth)
{

imgWth=(int)sect1.PageInfo.PageWidth;
newHeight=(int)(image.Heightratio);
imgHt=newHeight;
sect1.IsLandscape=true;

}
else
{

imgHt=(int)sect1.PageInfo.PageHeight;
newWidth=(int)(image.Width
ratio);

imgWth=newWidth;
sect1.IsLandscape=false;

}
Bitmap result=new Bitmap(imgWth,imgHt);

Graphics.FromImage(result).DrawImage(image,0,0,imgWth,imgHt);
Bitmap bmp=new Bitmap(result);
imageht.ImageInfo.SystemImage=bmp;

p.Save(“c:/Sample1_Tiff_Version+.pdf”);
fs.Close();
}

Hello,
I am trying to convert the TIFF image to PDF, but the resultant produced PDF orientation, scale and aspect ratio fails.

Can you share this post of setting the width and height to conserve the aspect ratio and scaling.
Or a piece of code snippet would be a great help.

Thanks,
Jess

Hello Jess,


Thanks for sharing the additional details and sorry for replying you late.

I have again tested the scenario using Aspose.Pdf for .NET 7.5.0 over Windows 7 X64 in VisualStudio 2010 where I have used the same code snippet as shared in your above post and as per my observations, the resultant PDF has Landscape orientation but there are scaling and aspect ratio problems and they are occurring because of the calculation against Image Width/Height that you have performed. Please take a look over the attached abc_Tiff_Version+.pdf file which I have generated.

Besides this, I have also tested the scenario using code snippet shared over 430392 and resultant PDF seems to be correct (see attached abc_Tiff_Version_MyApproach.pdf). Can you please share some details regarding your working environment.

PS, I have also tested this issue in Licensed as well as Trial mode but it does not seem to be the reason of this problem.

Hello Nayyer Shahbaz,
Thanks for sharing the knowledge, but as we cant upgrade the version from 5.2 to 7.5 for Aspose.
So I am trying to convert the TIFF image to PDF.
I am trying to calculate the aspect ratio or the scaling factor, so that the converted PDF image is not squeezed for one dimension only or to one corner of the output.
Also it should not grow that most of the part is cropped.

So can you help me if this type of calculation be supported by Aspose and not disturbing the scaling factor or aspect ratio.
I am using the trial version for Aspose 7.5 and other configurations are the same that you used.

Please provided some suggestion or a code snippet I can use with your tool to preserve the scaling factor while mainting the aspect ratio, so that the image produced as a pdf is correct as per the expectations(Portrait or Landscape).

Thanks,
Jess

Hi Jess,


I am working over this requirement and will get back to you soon. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

Hello Nayyer,

Any updates so far on this issue.

Also I have new version of code snippet, it does two things:
1) Converts the tiff image to pdf.
i.e converts the landscaped tiff image to landscape pdf image on a portrait page.
It scales down the image (Image1-Tiff to PDF).
2) Converts the tiff image to pdf.
It has a checkpoint to see whether the input image is portrait or landscape, so that the output produced is as per the input dimensions.
The landscaped tiff image is converted to blank output landscaped PDF document(Image2 -Tiff to PDFwith orientation).

Please review and verify and provide me some support to have the picture displayed properly in the produced pdf document.

Attachments:
1) Image1,
2) Image2,
3) Code snippet(with and without using the orientation set for the input image).

Thanks,
Jess.

Hello Support,
Any updates so far.

Thanks,
Jess

Hi Jess,


I am still in the process of preparing the code sample to fulfill your requirements but I am afraid the process has taken longer than expected. Nevertheless, I am trying my level best to share the required resources ASAP. We are sorry for this delay and inconvenience.

Hello Support,

Any update on this issue

Thanks,
Jess

jatrules:

Also I have new version of code snippet, it does two things:
1) Converts the tiff image to pdf.
i.e converts the landscaped tiff image to landscape pdf image on a portrait page.
It scales down the image (Image1-Tiff to PDF).
2) Converts the tiff image to pdf.
It has a checkpoint to see whether the input image is portrait or landscape, so that the output produced is as per the input dimensions.
The landscaped tiff image is converted to blank output landscaped PDF document(Image2 -Tiff to PDFwith orientation).
Hi Jess,

Thanks for sharing the details and resource files and sorry for the delayed response.

I have tested the scenario using code snippet which you have shared above and have tried using abc.tif shared over 431510 and as per my observations, the image is properly appearing in resultant PDF file. Besides this, I have also tried using TIFF images with Portrait dimensions and as per my observations, some of the images are properly appearing and for some TIFF files, the output PDF is blank. There might be some issue with the input TIFF image. However as per your above statement that Landscape images are not properly being converted, can you please share some more sample TIFF images so that we can further test and investigate this issue at our end.

We are really sorry for this delay and inconvenience.