Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Sep 22, 2017 4:56 pm

Hello
We need to save a pdf into a black and white png. Our goal is to get an image of type 1bpp (just 1 bit depth, by now, it is creating a Pbgra32 image), reducing the size of the image created. We have found no option to do this... could you please tell me if that is possible? this is a very important feature for our application because it is a backend service that need to deal with hundreds of request at the same time.
Thank you in advance,
Mauricio.

mmagni
 
Posts: 2
Joined: Wed Aug 24, 2016 4:23 pm

Mon Sep 25, 2017 3:00 am

Hello,

Thanks for your inquiry.
Please refer to the following code to convert pdf pages to 1 bpp png files.
Code: Select all
 
 private void test_Click(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"inputfile");
            SaveAs1bitBitmap(document);
        }
 private void SaveAs1bitBitmap(PdfDocument document)
        {
            int index=0;
            for (int i = 0; i < document.Pages.Count; i++)
            {
                var image = document.SaveAsImage(i, 400, 400);
                Bitmap bm = image as Bitmap;
                Bitmap b;
                b = bm.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format1bppIndexed);
                (b as Bitmap).Save(string.Format("11684_{0}.png", index));
                index++;
            }
        }

Looking foreward to your reply.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Sep 27, 2017 7:53 am

Hello Mauricio,

Have you tried the solution I provided? Did it meet your requirement?
Your feedback will be greatly appreciated.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Oct 09, 2017 4:41 pm

Hello Jane
Thank you for your solution. I will implement it (I have a different version, less efficient than yours). Anyway, based on quite specific requirements for this project, we need to reduce de consumption of memory and improve speed as much as we can. With your solution, we keep having the same problem, with the line
Code: Select all
var image = document.SaveAsImage(i, 400, 400);

because it returns a 32 bit depth image. What we need is a method like this:
Code: Select all
var image = document.SaveAs1bppImage(i, 400, 400);

that avoids creating a 32 bit image.
Hope you can help me with that.
Kind regards,
Mauricio

mmagni
 
Posts: 2
Joined: Wed Aug 24, 2016 4:23 pm

Tue Oct 10, 2017 7:10 am

Hello Mauricio,

Thanks for your feedback.
After a discussion, sorry we have no plan to encapsulate the manupulation of image at present. Moreover, even we encapsulate the method innerly, the approach of the images process is the same and this is not helpful for the performance optimization. Thus, you could process the 32 bit images and encapsulate the method by yourself.
I would appreciate your understanding.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF