File can't be compressed.
File can't be compressed.
Hello,
currently my software has an utility to compress PDF files.
I've read the forum and I've followed this tutorial: https://www.gdpicture.com/guides/gdpicture/web ... geMRC.html
The problem is that some documents have the exactly file size after the compression.
I let attached one of the documents which can't be compressed.
Than you so much.
currently my software has an utility to compress PDF files.
I've read the forum and I've followed this tutorial: https://www.gdpicture.com/guides/gdpicture/web ... geMRC.html
The problem is that some documents have the exactly file size after the compression.
I let attached one of the documents which can't be compressed.
Than you so much.
- Attachments
-
- Testdokument.pdf
- (2 MiB) Downloaded 862 times
Re: File can't be compressed.
Hi,
This document is basically not a good candidate as it is including vector text and image. So basically you re not validating this condition in the code: if (isPageImage).
You may want to reduce size of the embedded image, for such purpose here a good option: https://www.gdpicture.com/guides/gdpicture/web ... Image.html
Kind regards,
Loïc
This document is basically not a good candidate as it is including vector text and image. So basically you re not validating this condition in the code: if (isPageImage).
You may want to reduce size of the embedded image, for such purpose here a good option: https://www.gdpicture.com/guides/gdpicture/web ... Image.html
Kind regards,
Loïc
Re: File can't be compressed.
Hello there,
First of all thanks for the reply, I've been able to code the function and compress the image.
On the other hand I'm afraid it makes not a huge difference. The original file is 2 Mb and the compressed is 1.8 Mb.
I've realised that the function has no overloads to specify parameters.
Could I specify compression parameters somehow, or obtain the image from PDF to compress it externally and then use ReplaceImage function?
Thank you so much,
Jose Luis.
First of all thanks for the reply, I've been able to code the function and compress the image.
On the other hand I'm afraid it makes not a huge difference. The original file is 2 Mb and the compressed is 1.8 Mb.
I've realised that the function has no overloads to specify parameters.
Could I specify compression parameters somehow, or obtain the image from PDF to compress it externally and then use ReplaceImage function?
Thank you so much,
Jose Luis.
Re: File can't be compressed.
Hello,
You can use these methods to render the current page to GdPictureImage object:
https://www.gdpicture.com/guides/gdpicture/web ... Image.html
https://www.gdpicture.com/guides/gdpicture/web ... ageEx.html
And then you can use methods of GdPictureImaging class to improve the image.
You can use these methods to render the current page to GdPictureImage object:
https://www.gdpicture.com/guides/gdpicture/web ... Image.html
https://www.gdpicture.com/guides/gdpicture/web ... ageEx.html
And then you can use methods of GdPictureImaging class to improve the image.
Re: File can't be compressed.
Hello Gabriela, thanks for your reply.
Documentation for RenderPageToGdPictureImageEx Method says "The method's behaviour is specific for pages, which are entirely image-based", nevertheless my PDF is a text one with an image.
Will these functions work anyway?
Documentation for RenderPageToGdPictureImageEx Method says "The method's behaviour is specific for pages, which are entirely image-based", nevertheless my PDF is a text one with an image.
Will these functions work anyway?
Re: File can't be compressed.
Hello,
Yes, of course, they will work exactly like it is described. For image-based pages, the whole image is extracted "as is" in its original bit depth with the original dpi, so the method does not respect the DPI you will specify. For mixed pages, it will work with the required DPI you set.
Yes, of course, they will work exactly like it is described. For image-based pages, the whole image is extracted "as is" in its original bit depth with the original dpi, so the method does not respect the DPI you will specify. For mixed pages, it will work with the required DPI you set.
Re: File can't be compressed.
Thank you so much for the replies, they've been very useful.
I'm getting some troubles with ReplaceImageMRC and the attached pdf. It seems it's doing the compression over the top of the image but not on the rest of the image.
This is my current code on the 'else' of 'isPageImage':
You can find the output attached as well.
I'm getting some troubles with ReplaceImageMRC and the attached pdf. It seems it's doing the compression over the top of the image but not on the rest of the image.
This is my current code on the 'else' of 'isPageImage':
Code: Select all
int imageCount = pdf.GetPageImageCount();
for (int i = 0; i < imageCount; i++) {
int imgID = pdf.ExtractPageImage(i);
string imgRes = pdf.GetPageImageResName(imgID);
pdf.ReplaceImageMRC(imgRes, imgID);
GdPictureDocumentUtilities.DisposeImage(imgID);
}
- Attachments
-
- Testdokument_compressed.pdf
- (1.8 MiB) Downloaded 815 times
Re: File can't be compressed.
Hi,
Could you please send the whole code snippet you are using? It has no sense to add the 'else' of 'isPageImage' to ReplaceImageMRC() method.
Could you please send the whole code snippet you are using? It has no sense to add the 'else' of 'isPageImage' to ReplaceImageMRC() method.
Re: File can't be compressed.
I took this tutorial as example: https://www.gdpicture.com/guides/gdpicture/web ... geMRC.html
Code: Select all
for (int pageNo = 1; (pageNo <= pageCount) && (status == GdPictureStatus.OK); pageNo++) {
status = pdf.SelectPage(pageNo);
if (status == GdPictureStatus.OK) {
//We can ignore hidden text in the example.
bool isPageImage = pdf.IsPageImage(true);
status = pdf.GetStat();
if (status == GdPictureStatus.OK) {
if (isPageImage) {
//As the page is image-based, the image number is 1 and we can extract this image.
int imageID = pdf.ExtractPageImage(1);
status = pdf.GetStat();
if (status == GdPictureStatus.OK) {
//Getting the resource name of the extracted image, the index of the image to be used here is 0.
string imageResName = pdf.GetPageImageResName(0);
status = pdf.GetStat();
if (status == GdPictureStatus.OK) {
//The original image is replaced with the compressed image on the whole page surface here.
status = pdf.ReplaceImageMRC(imageResName, imageID);
//You need to dispose the used image resource here.
GdPictureDocumentUtilities.DisposeImage(imageID);
}
}
}
else {
GdPictureImaging pic = new GdPictureImaging();
int imageCount = pdf.GetPageImageCount();
for (int i = 0; i < imageCount; i++) {
int imgID = pdf.ExtractPageImage(i);
string imgRes = pdf.GetPageImageResName(imgID);
pdf.ReplaceImageMRC(imgRes, imgID);
GdPictureDocumentUtilities.DisposeImage(imgID);
}
}
}
}
}
if (status == GdPictureStatus.OK) {
status = pdf.SaveToFile(tempPath, true);
Re: File can't be compressed.
Hi,
This makes no sense. The ReplaceImageMRC() is ONLY for image-based pages. So the else statement is meaningless here. You need to use RenderPageToGdPictureImage() and then you can use AddImageFromGdPictureImage() method to make your source document image-based. So basically you need to prepare your source document first and then you can use the ReplaceImageMRC() method.
This makes no sense. The ReplaceImageMRC() is ONLY for image-based pages. So the else statement is meaningless here. You need to use RenderPageToGdPictureImage() and then you can use AddImageFromGdPictureImage() method to make your source document image-based. So basically you need to prepare your source document first and then you can use the ReplaceImageMRC() method.
Re: File can't be compressed.
Hi,
I agree, since the beginning of the topic I specified that my PDF contains vector text and images, so it's not an image-based PDF and I can't convert the PDF because I need the text to be selectable.
My question is: Can I compress somehow the embeded images in a non image-based PDF?
Thank you
I agree, since the beginning of the topic I specified that my PDF contains vector text and images, so it's not an image-based PDF and I can't convert the PDF because I need the text to be selectable.
My question is: Can I compress somehow the embeded images in a non image-based PDF?
Thank you
Re: File can't be compressed.
Hi,
This question has been answered above. You should try to use these methods:
https://www.gdpicture.com/guides/gdpicture/web ... Image.html
This question has been answered above. You should try to use these methods:
https://www.gdpicture.com/guides/gdpicture/web ... Image.html
Re: File can't be compressed.
Hello there,
Eventually I was allowed to convert mixed PDF's to image-based PDF's. So, following your instructions I get the page using RenderPageToGdPictureImage and then I replace the original with ReplaceImage.
Unfortunately, the PDF output is corrupted.
I let attached my current code and the PDF output:
Eventually I was allowed to convert mixed PDF's to image-based PDF's. So, following your instructions I get the page using RenderPageToGdPictureImage and then I replace the original with ReplaceImage.
Unfortunately, the PDF output is corrupted.
I let attached my current code and the PDF output:
Code: Select all
for (int pageNo = 1; (pageNo <= pageCount) && (status == GdPictureStatus.OK); pageNo++) {
status = pdf.SelectPage(pageNo);
if (status == GdPictureStatus.OK) {
//We can ignore hidden text in the example.
bool isPageImage = pdf.IsPageImage(true);
status = pdf.GetStat();
if (status == GdPictureStatus.OK) {
if (!isPageImage) {
int imgID = pdf.RenderPageToGdPictureImage(200, true);
string imgRes = pdf.GetPageImageResName(imgID);
pdf.ReplaceImage(imgRes, imgID, false, true);
}
}
}
}
- Attachments
-
- Testdokument_converted.pdf
- (1.89 MiB) Downloaded 831 times
Re: File can't be compressed.
Hello,
Here is a very simple code snippet that should work for you:
Please find the resulting file attached.
Here is a very simple code snippet that should work for you:
Code: Select all
GdPicturePDF sourcePDF = new GdPicturePDF();
GdPicturePDF destPDF = new GdPicturePDF();
if (sourcePDF.LoadFromFile("Testdokument.pdf", false) == GdPictureStatus.OK)
{
int imageID = sourcePDF.RenderPageToGdPictureImage(200, false);
if (sourcePDF.GetStat() == GdPictureStatus.OK)
{
if ((destPDF.NewPDF(PdfConformance.PDF) == GdPictureStatus.OK) &&
(destPDF.AddImageFromGdPictureImage(imageID, PdfAdvancedImageCompression.PdfAdvancedImageCompressionMRC) == GdPictureStatus.OK) &&
(destPDF.SaveToFile("Testdokument_imagebased.pdf") == GdPictureStatus.OK))
MessageBox.Show("Done!");
else
MessageBox.Show("Error!");
}
}
else MessageBox.Show("The file can't be loaded.");
oGdPicturePDF.Dispose();
- Attachments
-
- Testdokument_imagebased.pdf
- (96.49 KiB) Downloaded 833 times
Who is online
Users browsing this forum: No registered users and 1 guest