ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 SaveToPDF, File Size

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Ken Posted - Aug 09 2011 : 11:22:14
SaveToPDF, File Size

ImageEn 3.1.2, D XE

I have TIFFs that I convert to PDFs. The resulting PDFs are normally about 30KB to 60 KB. However, sometimes I need to add text to the image before converting it to a PDF. Those PDFs are enormous - about 20 MB to 60 MB. I need to be able to produce smaller PDFs when I have to add text. Here's my relevant code:


if StampText <> '' then
StampImageWithSpecialText(MyImage, StampText);

MyImage.IO.Params.PDF_Compression:= ioPDF_G4FAX; // G4Fax compression
MyImage.IO.SaveToPDF;

procedure StampImageWithSpecialText(MyImage : TImageENVect; StampText : string);
procedure IETextOut(Canvas: TCanvas; x,y:integer; angle:integer; const Text: String);
var
LogFont : TLogFont;
begin
with Canvas do
begin
GetObject(Font.Handle, SizeOf(TLogFont), @LogFont);
LogFont.lfEscapement := angle*10;
LogFont.lfQuality:=3;
Font.Handle := CreateFontIndirect(LogFont);
TextOut(x, y, Text);
end;
end;
begin
MyImage.LayersAdd; // add a new layer
MyImage.Proc.Fill(CreateRGB(255,255,255));
MyImage.Bitmap.Canvas.Font.Name := 'Arial';
MyImage.Bitmap.Canvas.Font.Size := 24;
MyImage.Bitmap.Canvas.Font.Size := trunc(24 * (MyImage.Bitmap.width/2544));
MyImage.Bitmap.Canvas.Font.Color := clBlack;
IETextOut(MyImage.Bitmap.Canvas, trunc(300 * (MyImage.Bitmap.width/2544)), 0, 0, StampText); // draw text on second layer
MyImage.Proc.Rotate(180);
IETextOut(MyImage.Bitmap.Canvas, trunc(300 * (MyImage.Bitmap.width/2544)), 0, 0, StampText);
MyImage.Proc.SetTransparentColors(CreateRGB(255, 255, 255), CreateRGB(255,255, 255), 0); // remove the white, making it as transparent
MyImage.LayersMergeAll;
end;


--------------------------------------------------------------------------------------------------------------------------------------------------------------





I figured out a workaround. I just save to a TIF and load from the TIF, right before SaveToPDF.

if (StampText <> '') then
begin
StampImageWithSpecialText(MyImage, StampText);
MyImage.IO.SaveToFile(FileName + '.tif');
MyImage.IO.LoadFromFile(FileName + '.tif');
end;

MyImage.IO.Params.PDF_Compression:= ioPDF_G4FAX; // G4Fax compression
MyImage.IO.SaveToPDF;

Still, there has to be a better solution. Or, SaveToPDF has a bug, or needs more documentation.

--------------------------------------------------------------------------------------------------------------------------------------------------------------



After further testing, I have determined that adding SaveToFile and LoadFromFile just slows the processing down too much when the pdf has too many pages. So I'd still appreciate some other ideas.

Thanks,
George





3   L A T E S T    R E P L I E S    (Newest First)
fab Posted - Aug 11 2011 : 14:50:51
>Is there anything else I can do?

You could write directly over the main bitmap, instead of using layers.
George Posted - Aug 11 2011 : 10:54:47
I am taking over from Ken here.

I added MyImage.Proc.ConvertToBWThreshold() after LayersMergeAll, and I removed the SaveToFile/LoadFromFile.

It works, but it isn't any faster. I can generate a 38 page pdf without calling StampImageWithSpecialText in about 5 seconds. It still takes about 22 seconds to generate the same 38 page pdf with calling StampImageWithSpecialText.

Is there anything else I can do?

Thanks,
George
fab Posted - Aug 09 2011 : 14:06:20
The method LayersMergeAll converts implicitly the image to RGB (24 bit), so the compression method ioPDF_G4FAX is no more applicable.
You should re-convert back the image to black/white executing:

...
MyImage.LayersMergeAll;
MyImage.Proc.ConvertToBWThreshold(); // other ways available
...