Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Convert a TIFF image to a PDF -> Size Increased |
Post Reply |
Author | |
vinoth.prog
Beginner Joined: 02 Nov 20 Location: Vancouver Status: Offline Points: 2 |
Post Options
Thanks(0)
Posted: 02 Nov 20 at 9:33PM |
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
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Vinoth,
BTW: this here is a forum from users to users - it's not a publisher forum. Please keep this in mind. To check your prob more deeper you should upload the tif anywhere to a free filehoster (like DropBox) and post the link here. So we can test with the tiff ourself for better advice. Regarding CommpressImages: What's the returning value of this function? What does LastErrorCode say directly after this function? Which version of QuickPDF you're using? Cheers and welcome here, Ingo |
|
Cheers,
Ingo |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
I agree with the suggestion to post the TIF image (and the PDF) so that we can look at it. Everything depends on how the TIF file was compressed and what compression you are using for the image in the PDF. With this information I hope the users here may be able to help in more detail.
The key thing you need to note is that you are actually not 'converting the image to PDF'. PDF is not an image format, it is a document format in which you can embed images. The process you are using will convert the (perhaps compressed) TIF image to a different (perhaps compressed) image format, and then you embed/draw the second image into a PDF file. So the fact that your output file is a PDF is of much less importance than exactly how you are processing the images. Also seeing the image would enable us to check how well this specific image will compress.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store