Hi Team, Please see the code below. When I try to convert tif image to pdf. it is creating pdf with increased Size. ie. 99 KB tif to 2221 KB. I have also tried compress method , but no use it is not compressing.
#region TIFF if (imageLocation.Split('.').Last().ToUpper() == "TIF" || imageLocation.Split('.').Last().ToUpper() == "TIFF") { if (isNewDoc) { int MainDocInt = PDFLib.SelectedDocument(); double startHeight = PDFLib.PageHeight(); bool firstpage = true; Image imageIn = Image.FromFile(imageLocation); Guid objGuid = imageIn.FrameDimensionsList[0]; var objDimension = new FrameDimension(objGuid);
int pageCount = imageIn.GetFrameCount(FrameDimension.Page); for (int i = 0; i < pageCount; i++) {
if (!firstpage) { int newDoc = PDFLib.NewDocument(); PDFLib.SelectDocument(newDoc); } if (String.IsNullOrEmpty(PageSize) || PageSize.ToUpper() == "DEFAULT") { imageIn.SelectActiveFrame(objDimension, i); int ImageWidth = imageIn.Size.Width; int ImageHeight = imageIn.Size.Height;
PDFLib.SetPageDimensions(ImageWidth, ImageHeight);
int imageInt = PDFLib.AddImageFromFile(imageLocation, i+1); PDFLib.SelectImage(imageInt); PDFLib.CompressImages(1); PDFLib.DrawImage(0, PDFLib.PageHeight(), ImageWidth, ImageHeight); PDFLib.CompressImages(1); } else { imageIn.SelectActiveFrame(objDimension, i); PDFLib.SetPageSize(PageSize); float ImageWidth = imageIn.Size.Width; float ImageHeight = imageIn.Size.Height; float PageWidth = Convert.ToInt32(PDFLib.PageWidth()); float PageHeight = Convert.ToInt32(PDFLib.PageHeight()); float heightScale = PageHeight / ImageHeight; float widthScale = PageWidth / ImageWidth;
float scale = 0; if (heightScale > widthScale) scale = widthScale; else scale = heightScale;
//PDFLib.SetPageDimensions(ImageWidth, ImageHeight);
int imageInt = PDFLib.AddImageFromFile(imageLocation, i+1); PDFLib.SelectImage(imageInt); if (scale == 0) PDFLib.DrawImage(0, PDFLib.PageHeight(), ImageWidth, ImageHeight); else { PDFLib.DrawScaledImage(0, PDFLib.PageHeight(), scale); } }
if (!firstpage) { int thisDoc = PDFLib.SelectedDocument(); PDFLib.SelectDocument(MainDocInt); PDFLib.MergeDocument(thisDoc); } if (firstpage) firstpage = false;
} isNewDoc = false; } else { int MainDoc = PDFLib.SelectedDocument(); int NewDoc = PDFLib.NewDocument(); PDFLib.SelectDocument(NewDoc);
int MainDocInt = PDFLib.SelectedDocument(); double startHeight = PDFLib.PageHeight(); bool firstpage = true; Image imageIn = Image.FromFile(imageLocation); Guid objGuid = imageIn.FrameDimensionsList[0]; var objDimension = new FrameDimension(objGuid);
int pageCount = imageIn.GetFrameCount(FrameDimension.Page); for (int i = 0; i < pageCount; i++) { if (!firstpage) { int newDoc = PDFLib.NewDocument(); PDFLib.SelectDocument(newDoc); } if (String.IsNullOrEmpty(PageSize)) { imageIn.SelectActiveFrame(objDimension, i); int ImageWidth = imageIn.Size.Width; int ImageHeight = imageIn.Size.Height;
PDFLib.SetPageDimensions(ImageWidth, ImageHeight);
int imageInt = PDFLib.AddImageFromFile(imageLocation, i); PDFLib.SelectImage(imageInt); PDFLib.DrawImage(0, PDFLib.PageHeight(), ImageWidth, ImageHeight); } else { imageIn.SelectActiveFrame(objDimension, i); PDFLib.SetPageSize(PageSize); int ImageWidth = imageIn.Size.Width; int ImageHeight = imageIn.Size.Height; int PageWidth = Convert.ToInt32(PDFLib.PageWidth()); int PageHeight = Convert.ToInt32(PDFLib.PageHeight()); float heightScale = ImageHeight / PageHeight; float widthScale = ImageWidth / PageWidth;
float scale = 0; if (heightScale > widthScale) scale = widthScale; else scale = heightScale;
//PDFLib.SetPageDimensions(ImageWidth, ImageHeight);
int imageInt = PDFLib.AddImageFromFile(imageLocation, 0); PDFLib.SelectImage(imageInt); if (scale == 0) PDFLib.DrawImage(0, PDFLib.PageHeight(), ImageWidth, ImageHeight); else { PDFLib.DrawScaledImage(0, PDFLib.PageHeight(), scale); } }
if (!firstpage) { int thisDoc = PDFLib.SelectedDocument(); PDFLib.SelectDocument(MainDocInt); PDFLib.MergeDocument(thisDoc); } if (firstpage) firstpage = false; }
PDFLib.SelectDocument(MainDoc); PDFLib.MergeDocument(NewDoc); } } #endregion
|