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,
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,
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 Nayyer Shahbaz,
I have attached:
- the sample code snippet
- the original .tif image, and
- 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.Width<em>ratio);
var newHeight=(int)(image.Height</em> ratio);
if(image.Width>sect1.PageInfo.PageWidth)
{
imgWth=(int)sect1.PageInfo.PageWidth;
newHeight=(int)(image.Height<em>ratio);
imgHt=newHeight;
sect1.IsLandscape=true;
}
else
{
imgHt=(int)sect1.PageInfo.PageHeight;
newWidth=(int)(image.Width</em> 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,
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,
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,
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).
Hello Support,
Sorry for replying late.
Anyhow the problem is resolved.
For your question related to TIFF images, I used randomly googled many TIFF Images for testing purposes.
Thanks for the support though.
Jess
Hi Jess,