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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
carrot  
#1 Posted : Monday, January 21, 2019 1:27:20 AM(UTC)
Quote
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 2:40:13 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 10 times
Was thanked: 133 time(s) in 130 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 11:12:44 AM(UTC)
Quote
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 4:12:35 PM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 10 times
Was thanked: 133 time(s) in 130 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.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.