GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Good day,
I wanted to use these methods to resize the pages inside a PDF after the OCR has been done. To my surprise it didn't work as expected: it would only scale the image ON the page, and not the page itself. See the image for exemple (I have removed te page content for security reason).
I've used a scaling factor of 0.5f and dividing the current page width and height by 2. Both gave the same result.
Thanks for your time and help,
I wanted to use these methods to resize the pages inside a PDF after the OCR has been done. To my surprise it didn't work as expected: it would only scale the image ON the page, and not the page itself. See the image for exemple (I have removed te page content for security reason).
I've used a scaling factor of 0.5f and dividing the current page width and height by 2. Both gave the same result.
Thanks for your time and help,
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hi SarrasiM
Can you give us a small snippet to reproduce the problem on our side.
Best regards.
Jean-Luc
Can you give us a small snippet to reproduce the problem on our side.
Best regards.
Jean-Luc
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hello delbeke
Here's the code snippet as requested:
using (GdPicturePDF pdf = new GdPicturePDF())
{
var position = 1;
pdf.NewPDF(true);
pdf.SetJpegQuality(75);
pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch);
foreach (var img in Directory.GetFiles(@"C:\Tests"))
{
var imageId = gdp.CreateGdPictureImageFromFile(img);
if (imageId == 0)
throw new NullReferenceException(string.Format("The image {0} does not exists or could not be properly loaded.", img));
var intent = gdp.ColorDetection(imageId, false, true, true);
if (intent <= GdPictureOutputIntent.IntentGrayscale)
gdp.ConvertTo8BppGrayScaleAdv(imageId);
var res = pdf.AddImageFromGdPictureImage(imageId, false, false);
pdf.InsertPage((float)gdp.GetWidth(imageId) / (float)gdp.GetHorizontalResolution(imageId), (float)gdp.GetHeight(imageId) / (float)gdp.GetVerticalResolution(imageId), position);
pdf.SelectPage(position);
pdf.DrawImage(res, 0, 0, (float)gdp.GetWidth(imageId) / (float)gdp.GetHorizontalResolution(imageId), (float)gdp.GetHeight(imageId) / (float)gdp.GetVerticalResolution(imageId));
pdf.OcrPage("eng", @".\data", "", 200);
pdf.ScalePage(0.5f, 0.5f); // pdf.ResizePage(pdf.GetPageWidth() / 2f, pdf.GetPageHeight() / 2f);
status = pdf.GetStat();
if (status != GdPictureStatus.OK)
throw new InvalidOperationException(string.Format("Image {0} could not be added to pdf (Status Code: {1})", img, status.ToString()));
gdp.ReleaseGdPictureImage(imageId);
position++;
}
if (pdf.SaveToFile(@"C:\Tests\1.pdf") != GdPictureStatus.OK)
throw new InvalidOperationException(string.Format("File {0} could not be saved.", "1.pdf"));
pdf.CloseDocument();
}
Thank you,
Here's the code snippet as requested:
using (GdPicturePDF pdf = new GdPicturePDF())
{
var position = 1;
pdf.NewPDF(true);
pdf.SetJpegQuality(75);
pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch);
foreach (var img in Directory.GetFiles(@"C:\Tests"))
{
var imageId = gdp.CreateGdPictureImageFromFile(img);
if (imageId == 0)
throw new NullReferenceException(string.Format("The image {0} does not exists or could not be properly loaded.", img));
var intent = gdp.ColorDetection(imageId, false, true, true);
if (intent <= GdPictureOutputIntent.IntentGrayscale)
gdp.ConvertTo8BppGrayScaleAdv(imageId);
var res = pdf.AddImageFromGdPictureImage(imageId, false, false);
pdf.InsertPage((float)gdp.GetWidth(imageId) / (float)gdp.GetHorizontalResolution(imageId), (float)gdp.GetHeight(imageId) / (float)gdp.GetVerticalResolution(imageId), position);
pdf.SelectPage(position);
pdf.DrawImage(res, 0, 0, (float)gdp.GetWidth(imageId) / (float)gdp.GetHorizontalResolution(imageId), (float)gdp.GetHeight(imageId) / (float)gdp.GetVerticalResolution(imageId));
pdf.OcrPage("eng", @".\data", "", 200);
pdf.ScalePage(0.5f, 0.5f); // pdf.ResizePage(pdf.GetPageWidth() / 2f, pdf.GetPageHeight() / 2f);
status = pdf.GetStat();
if (status != GdPictureStatus.OK)
throw new InvalidOperationException(string.Format("Image {0} could not be added to pdf (Status Code: {1})", img, status.ToString()));
gdp.ReleaseGdPictureImage(imageId);
position++;
}
if (pdf.SaveToFile(@"C:\Tests\1.pdf") != GdPictureStatus.OK)
throw new InvalidOperationException(string.Format("File {0} could not be saved.", "1.pdf"));
pdf.CloseDocument();
}
Thank you,
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hi SarrasiM
I have made a try to scale a page from a pdf and with the latest version of GdPicture, it works as expected.
I have only used Pdf.ScalePage(0.5f, 0.5f) and the page is resized correctly, its contents is resized accordingly.
I think you should make a test on a multipage existing pdf and resize one of the page to see the impact of the ScalePage function.
You can help yourself with the sample there : https://www.gdpicture.com/guides/gdpicture/web ... ePage.html
Hope this help
Best regards.
Jean-Luc
I have made a try to scale a page from a pdf and with the latest version of GdPicture, it works as expected.
I have only used Pdf.ScalePage(0.5f, 0.5f) and the page is resized correctly, its contents is resized accordingly.
I think you should make a test on a multipage existing pdf and resize one of the page to see the impact of the ScalePage function.
You can help yourself with the sample there : https://www.gdpicture.com/guides/gdpicture/web ... ePage.html
Hope this help
Best regards.
Jean-Luc
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hello delbeke,
Please see the two images attached. One has been resized using Scale() while the other has kept the original images dimensions.
What we are looking to accomplish is to reduce the PDF size by resizing the images in it. This worked well in previous attempts as we scaled the image before adding to the PDF but we realised that doing so made the OCR suffer of a very low success rate. Right now, we are trying to add the image to the PDF in its original dimensions, OCR it, and then resize. After a few verification, the size was indeed divided by half, but the file size remains almost the same as you can see on the pictures included. How can we add image in original dimensions, OCR, and then resize and maintain the previous recognized text?
Thanks for your help, it is much appreciated.
Please see the two images attached. One has been resized using Scale() while the other has kept the original images dimensions.
What we are looking to accomplish is to reduce the PDF size by resizing the images in it. This worked well in previous attempts as we scaled the image before adding to the PDF but we realised that doing so made the OCR suffer of a very low success rate. Right now, we are trying to add the image to the PDF in its original dimensions, OCR it, and then resize. After a few verification, the size was indeed divided by half, but the file size remains almost the same as you can see on the pictures included. How can we add image in original dimensions, OCR, and then resize and maintain the previous recognized text?
Thanks for your help, it is much appreciated.
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hi SarrasiM
Hi, the problem is completely different, scaling add a scaling matrix at the beginning of the content stream, the pdf content is not changed.
What you need is a resize of the image inside the page after the OCR. You do not need to resize the pdf page..
something like this:
...
pdf.OcrPage("eng", @".\data", "", 200);
int ImageWidth = oGdPictureImaging.GetWidth(imageID);
int ImageHeight = oGdPictureImaging.GetHeight(imageID);
gdp.Resize(imageId, ImageWidth/2, ImageHeight/2, Drawing2D.InterpolationMode.Bicubic);
pdf.DeleteImage(res);
res = pdf.AddImageFromGdPictureImage(imageId, false, false);
pdf.DrawImage(0,0, pdf.GatPageWidth(), pdf.GetPageHeight);
Hope this help.
Jean-Luc
Hi, the problem is completely different, scaling add a scaling matrix at the beginning of the content stream, the pdf content is not changed.
What you need is a resize of the image inside the page after the OCR. You do not need to resize the pdf page..
something like this:
...
pdf.OcrPage("eng", @".\data", "", 200);
int ImageWidth = oGdPictureImaging.GetWidth(imageID);
int ImageHeight = oGdPictureImaging.GetHeight(imageID);
gdp.Resize(imageId, ImageWidth/2, ImageHeight/2, Drawing2D.InterpolationMode.Bicubic);
pdf.DeleteImage(res);
res = pdf.AddImageFromGdPictureImage(imageId, false, false);
pdf.DrawImage(0,0, pdf.GatPageWidth(), pdf.GetPageHeight);
Hope this help.
Jean-Luc
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hello delbeke,
Thanks, it worked
Thanks, it worked
Re: GdPicturePDF.Scale and GdPicturePDF.Resize only resizing image
Hi SarrasiM
Thanks for the return. Have a nice day.
Best regards
Jean-Luc
Thanks for the return. Have a nice day.
Best regards
Jean-Luc
Who is online
Users browsing this forum: No registered users and 1 guest