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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 SaveToPDF, File Size
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Ken

USA
2 Posts

Posted - Aug 09 2011 :  11:22:14  Show Profile  Reply
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





fab

1310 Posts

Posted - Aug 09 2011 :  14:06:20  Show Profile  Reply
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
...
Go to Top of Page

George

USA
1 Posts

Posted - Aug 11 2011 :  10:54:47  Show Profile  Reply
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
Go to Top of Page

fab

1310 Posts

Posted - Aug 11 2011 :  14:50:51  Show Profile  Reply
>Is there anything else I can do?

You could write directly over the main bitmap, instead of using layers.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: