logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
carrot  
#1 Posted : Monday, January 21, 2019 4:27:20 AM(UTC)
carrot

Rank: Newbie

Groups: Registered
Joined: 12/4/2017(UTC)
Posts: 9
Slovakia
Location: Bratislava

Hello,

how can I specify filter for image: DCTDecode, JBIG2Decode, JPXDecode, FlateDecode...
I need to optimize size of pdf which contains only one image per page and trying to use jpeg format, but I do not know how.
I'm using following code to create PdfBitmap:

Code:
PdfBitmap result = null;

BitmapFormats pdfFormat;
int[] palette;
GetPdfFormat(bitmap, out pdfFormat, out palette);

var lockInfo = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
result = new PdfBitmap(bitmap.Width, bitmap.Height, pdfFormat, lockInfo.Scan0, lockInfo.Stride);
bitmap.UnlockBits(lockInfo);

if (palette != null)
{
	result.Palette = palette;
}


Thank you.
Paul Rayman  
#2 Posted : Monday, January 21, 2019 5:40:13 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 724

Thanks: 1 times
Was thanked: 87 time(s) in 86 post(s)
PdfBitmap is by definition an uncompressed image.
Compression mode should be applied to the PdfImageObject, that is placed in the content stream on a page.

When the PdfBitmap inserted into PdfImageObject the FlateDecode is used to compress this image. This is by default behavior.

You may try PdfImageObject.LoadJpegFile(). In this case JPXDecode will be applied.

Also you may try to create monochrome bitmap instead of argb format.
carrot  
#3 Posted : Wednesday, January 23, 2019 2:12:44 PM(UTC)
carrot

Rank: Newbie

Groups: Registered
Joined: 12/4/2017(UTC)
Posts: 9
Slovakia
Location: Bratislava

Thanks, loading jpeg works.

It decodes Jpeg image by DCTDecode. Jpeg has sense only for images in color.
8bpp (grayscale) and 1bpp (black white) can't be used in jpeg.
Is there any other way to optimize the size of PDF?
Paul Rayman  
#4 Posted : Tuesday, February 12, 2019 7:12:35 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 724

Thanks: 1 times
Was thanked: 87 time(s) in 86 post(s)
You can try encode such images yourself and write raw bytes into the image object stream.

Also you may try to create PdfBitmap with appropriate pixel format.
Users browsing this topic
Forum Jump  
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.