#1 PDF Engine » How to reduce pdf file size » 2020-10-27 14:47:44

fantoni
Replies: 1

Hi everyone, i need help to create small pdf files with synpdf.
I use this Delphi code to transform scanned .jpg images into a single pdf :

pdfDoc := TPdfDocument.Create(false,0,false,TPdfEncryption.New(elRC4_128,LabeledEditPdfPw.text,LabeledEditPdfPw.text,PDF_PERMISSION_NOCOPYNORPRINT))
else
pdfDoc :=TPdfDocument.Create;
pdfDoc.Info.Author:='';
pdfDoc.Info.Creator:='';
pdfDoc.DefaultPaperSize:=psA4;
pdfDoc.DefaultPageLandscape:=PdfLandscape;
pdfDoc.CompressionMethod:=cmFlateDecode;
pdfDoc.ForceJPEGCompression:=Qualitapdf;
Sb.Panels[0].Text:='Create pdf wait...';

for i := 0 to ListBox1.Count - 1 do
begin

JpegImage:=TJpegImage.create;
Nomefile:=dir+ListBox1.Items.Strings[i];
JpegImage.LoadFromFile(nomefile);
pdfpage := pdfDoc.AddPage;
pdfImage := TPdfImage.Create(pdfDoc,jpegimage,true);
JpegImage.Free;
pdfDoc.AddXObject('image'+inttostr(i), pdfimage);
pdfDoc.Canvas.DrawXObject(0,0,pdfpage.PageWidth,pdfpage.PageHeight,'image'+inttostr(i));

 ListBox1.Selected[i] := true;
Sb.Panels[0].Text:='Process page '+inttostr(i)+' of '+inttostr(ListBox1.Count)+' wait...';
 Application.ProcessMessages;
// pdfImage.CleanupInstance;
 end;

The pdf file I get is still too big... how can I minimize the outupt file size?

Thanks for the attention.

#2 PDF Engine » How to create a protected PDF ? » 2015-04-22 17:01:45

fantoni
Replies: 0

Hi,
I use this code on Delphi XE7 to create a pdf document on multiple pages .

The procedure works well if you do not protect the pdf .

If I protect the file returns error " Access Violation.."

Where is the error ?

and eventually...i can create a pdf file protected from a pdf file unprotected ?

Thanks......

Fantoni

procedure TForm1.Button2Click(Sender: TObject);
var
pdfDoc:TPdfDocument;
pdfDocProtect:TPdfDocument;
pdfpage:TPdfpage;
JpegImage:TJPEGImage;
pdfImage:TPdfImage;
fs: TFileStream;
i:integer;
begin
Qualitapdf:=SpinEdit1.value;

//Make protect document
if length (LabeledEditPdfPw.text)>0 then
pdfDoc := TPdfDocument.Create(false,0,false,TPdfEncryption.New(elRC4_128,LabeledEditPdfPw.text,LabeledEditPdfPw.text,PDF_PERMISSION_NOCOPYNORPRINT))
else
pdfDoc :=TPdfDocument.Create;
JpegImage:= TJPEGImage.Create;
Nomefilepdf := percorso+'PdfFile\' + FormatDateTime( 'dd_mm_yy_hhnnss' , Now() ) +'_.pdf';
fs:= TFileStream.Create(nomefilepdf,fmCreate);

try
pdfDoc.NewDoc;
pdfDoc.Info.Author:='';
pdfDoc.Info.Creator:='';
pdfDoc.DefaultPaperSize:= psA4;
pdfDoc.DefaultPageLandscape:=PdfLandscape;
pdfDoc.CompressionMethod:=cmFlateDecode;
pdfDoc.ForceJPEGCompression:=Qualitapdf;
pdfDoc.SaveToStreamDirectBegin(fs);
Sb.Panels[0].Text:='Create pdf wait...';

for i := 0 to FileListBox1.Count - 1 do
begin
FileListBox1.Selected[i] := true;
JpegImage.LoadFromFile(FileListBox1.Items.Strings[i]);
pdfpage:= pdfDoc.AddPage;
pdfImage := TPdfImage.Create(pdfDoc, JpegImage, true);
pdfDoc.AddXObject('image' + IntToStr(i), pdfImage);
pdfDoc.Canvas.DrawXObject(0, 0, pdfpage.PageWidth, pdfpage.PageHeight, 'image' + IntToStr(i));
pdfDoc.SaveToStreamDirectPageFlush(True);
end;
pdfDoc.SaveToStreamDirectEnd;
//pdfDoc.SaveToFile(nomefilepdf);
finally
fs.Free;
pdfDoc.Free;
JpegImage.Free;
ShowMessage('Pdf Create!!');
ShellExecute(Application.MainForm.Handle,'open',Pchar(nomefilepdf),nil,nil,SW_NORMAL);
  end;

end;

#3 PDF Engine » Delphi XE7 SynPDF could not compile » 2015-03-06 10:13:14

fantoni
Replies: 1

Hi there,

    I'm trying to compile SynPDF in my Delphi XE7, but I retrive an error in the SynCommons unit :

   [dcc32 Error] SynCommons.pas(34059): E2029 Expression expected but 'END' found

I have disable my Avg antivirus but Delphi XE7 replace the same error message on compile SynCommons unit.

I use this version:  http://synopse.info/files/pdf/synpdf.zip;


Is there a way to solve this to use SynPDF with Delphi XE7.

Thanks !

#5 Re: PDF Engine » Problem creating pdf document from multiple jpeg file » 2011-03-23 10:19:09

Well then I can say that before was not working because I did not put the unit SynGdiPlus in the project ... right?


Thank you for your kind help

#6 Re: PDF Engine » Problem creating pdf document from multiple jpeg file » 2011-03-22 16:42:15

After several unsuccessful attempts I put the unit in my project SynGdiPlus and ...... now the compression of pdf files working properly.

Can anyone tell me why?

Thanks ...

#7 Re: PDF Engine » Problem creating pdf document from multiple jpeg file » 2011-03-22 10:44:30

Sorry but there is only pdfDoc.ForceJPEGCompression  one correct code and still does not work......the pdf file size is always the same

procedure TForm1.CreazionePdf;
var
pdfDoc:TPdfDocument;
pdfpage:TPdfpage;
JpegImage:TJpegImage;
pdfImage:TPdfImage;
i:integer;
begin

pdfDoc := TPdfDocument.Create;
pdfDoc.Info.Author:='';
pdfDoc.Info.Creator:='';
pdfDoc.DefaultPaperSize:=psA4;
pdfDoc.CompressionMethod:=cmFlateDecode;
//pdfDoc.ForceJPEGCompression:=Qualitapdf;

pdfDoc.ForceJPEGCompression:=20 ;
JpegImage := TJpegImage.Create;


   for i := 0 to FileListBoxEx1.Count - 1 do
     begin
  JpegImage.Compress;
JpegImage.LoadFromFile( FileListBoxEx1.Items.Strings[i]);
pdfpage := pdfDoc.AddPage;
pdfpage.PageWidth:=Round(jpegimage.Width *0.73);
pdfpage.PageHeight:=Round(jpegimage.Height * 0.73);

pdfImage := TPdfImage.Create(pdfDoc,jpegimage,true);

pdfDoc.AddXObject('image'+inttostr(i), pdfimage);
pdfDoc.Canvas.DrawXObject(0,0,pdfpage.PageWidth,pdfpage.PageHeight,'image'+inttostr(i));

 FileListBoxEx1.Selected[i] := true;
StatusBar1.Panels[0].Text:='Process page '+inttostr(i)+' of '+inttostr(FileListBoxEx1.Count)+' wait...';
 Application.ProcessMessages;
end;


pdfDoc.SaveToFile(nomefilepdf);
   StatusBar1.Panels[0].Text:='Create pdf wait...';

pdfDoc.Free;
 end;

#8 Re: PDF Engine » Problem creating pdf document from multiple jpeg file » 2011-03-22 09:45:24

Hi
to solve the problem I had to rewrite the code.
Now it seems to successfully create the pdf document but I can not diminish the quality ... where am I wrong?

procedure TForm1.CreazionePdf;
var
pdfDoc:TPdfDocument;
pdfpage:TPdfpage;
JpegImage:TJpegImage;
pdfImage:TPdfImage;
i:integer;
begin

pdfDoc := TPdfDocument.Create;
pdfDoc.Info.Author:='';
pdfDoc.Info.Creator:='';
pdfDoc.DefaultPaperSize:=psA4;
pdfDoc.ForceJPEGCompression:=20;
pdfDoc.CompressionMethod:=cmFlateDecode;

JpegImage := TJpegImage.Create;

   for i := 0 to FileListBoxEx1.Count - 1 do
     begin

JpegImage.LoadFromFile( FileListBoxEx1.Items.Strings[i]);
pdfpage := pdfDoc.AddPage;
pdfpage.PageWidth:=Round(jpegimage.Width *0.73);
pdfpage.PageHeight:=Round(jpegimage.Height * 0.73);
 pdfDoc.ForceJPEGCompression:=70;
pdfImage := TPdfImage.Create(pdfDoc,jpegimage,true);

pdfDoc.AddXObject('image'+inttostr(i), pdfimage);
pdfDoc.Canvas.DrawXObject(0,0,pdfpage.PageWidth,pdfpage.PageHeight,'image'+inttostr(i));
pdfDoc.ForceJPEGCompression:=70;
 FileListBoxEx1.Selected[i] := true;
StatusBar1.Panels[0].Text:='Process page '+inttostr(i)+' of '+inttostr(FileListBoxEx1.Count)+' wait...';
 Application.ProcessMessages;
end;


pdfDoc.SaveToFile(nomefilepdf);
   StatusBar1.Panels[0].Text:='Create pdf wait...';

pdfDoc.Free;


end;

#9 Re: PDF Engine » Problem creating pdf document from multiple jpeg file » 2011-03-21 13:53:51

Thanks for your help ...
any image has a unique name for example: 1.jpg, 2.jpeg, 3.jpg, 4.jpg. etc....

Did not understand how to use the recommended code to the breakpoint.

Should I use result: boolean with a timer1?
Could you kindly make an explicit example of how to use pdf.GetXObjectImageName ..

many thanks.

#10 PDF Engine » Problem creating pdf document from multiple jpeg file » 2011-03-21 10:47:51

fantoni
Replies: 11

Hello everyone,
I wrote this simple code in Delphi to create form more jpg files contenent in to a directory on a single pdf file:


procedure TForm1.MakePdf;
var
 pdf: TPdfDocumentGDI;
  i: Integer;
  pict: TPicture;
   FileImmagine:string;
   terminato:boolean;

 begin

   pdf:=TPdfDocumentGDI.Create;

     pdf.Info.Author:='';
      pdf.Info.Creator:='';
      pdf.DefaultPaperSize:=psA4;

    pdf.ForceJPEGCompression:=80;
   pdf.CompressionMethod:=cmFlateDecode;
   pict:= TPicture.Create;
   for i := 0 to FileListBoxEx1.Count - 1 do
     begin
     FileImmagine:= FileListBoxEx1.Items.Strings[i];
     pict.LoadFromFile(FileImmagine);
        with pdf.AddPage do
         begin
           PageWidth:=Round(pict.Width *0.73);
             PageHeight:=Round(pict.Height * 0.73);
         end;
       pdf.VCLCanvas.Draw(0,0,pict.Graphic);
        FileListBoxEx1.Selected[i] := true;
 StatusBar1.Panels[0].Text:='Process page '+inttostr(i)+' of '+inttostr(FileListBoxEx1.Count)+' wait...';
 Application.ProcessMessages;
           end;

     try

   pdf.SaveToFile('C:\Test.pdf');

   StatusBar1.Panels[0].Text:='Create pdf wait...';
   finally
    pict.Free;
   pdf.Free;
   StatusBar1.Panels[0].Text:='Pdf document is created...';
   end;
      ShellExecute(Application.MainForm.Handle,'open',Pchar(nomefilepdf),
        nil,nil,SW_NORMAL);
     end;

I tried inserting a seven jpg image file in to directory.
When I go to run the procedure, the result is that you create a pdf with seven pages of which only the first two are correct.
The remaining five pages contain the second image instead of the subsequent images.

Does anybody know kindly tell me where am I wrong .......

Thanks

#12 PDF Engine » Lunch default pdf reader program » 2011-02-28 14:24:03

fantoni
Replies: 2

Hello,
how to execute  default PDF reader program after create a pdf file with pdf engine?

thanks to all ..

#13 Re: PDF Engine » Join muliple Jpg image to Pdf file » 2011-02-25 17:33:58

Ok I tried this way and now seems to be fine even if I am not convinced that the 'final image is not deformed ...


procedure TForm1.SpeedButton5Click(Sender: TObject);
var
pdfDoc:TPdfDocument;
pdfpage:TPdfpage;
JpegImage:TJpegImage;
pdfImage:TPdfImage;

begin
pdfDoc := TPdfDocument.Create;
pdfpage := pdfDoc.AddPage;
JpegImage := TJpegImage.Create;
JpegImage.LoadFromFile('C:\SorgentiDelphi\Twain2\immagini\pag_1.jpg');
//JpegImage.ForceJPEGCompression:=90;
pdfImage := TPdfImage.Create(pdfDoc, jpegimage,true);
//pdfImage:= TPdfImage.CreateJpegDirect(pdfDoc,'C:\SorgentiDelphi\Twain2\immagini\pag_1.jpg');
//pdfImage := TPdfImage.Create(pdfDoc, jpegimage);
pdfDoc.AddXObject('image1', pdfimage);
//pdfDoc.Canvas.DrawXObject(0,0,120,230, 'image1');


  pdfDoc.Canvas.DrawXObject(0, pdfpage.PageHeight-900,600, 900, 'image1');

//pdfDoc.Canvas.DrawXObject(0, pdfpage.PageHeight-JpegImage.Height,JpegImage.Width, JpegImage.Height, 'image1');

pdfDoc.SaveToFile('test2.pdf');
pdfDoc.Free;

#14 Re: PDF Engine » Join muliple Jpg image to Pdf file » 2011-02-25 17:24:04

Thanks but ....
My image of width 1653 and length 2338 pixels, but I can not let her in on a sheet of A4 paper 210 x295 mm ....

#15 Re: PDF Engine » Join muliple Jpg image to Pdf file » 2011-02-25 14:49:17

Thanks for your help.
I tried this code but the images are larger than the PDF page and do not maintain the proportions ... where am I wrong ....

procedure TForm1.SpeedButton5Click(Sender: TObject);
var
pdfDoc:TPdfDocument;
pdfpage:TPdfpage;
JpegImage:TJpegImage;
pdfImage:TPdfImage;

begin
pdfDoc := TPdfDocument.Create;
pdfpage := pdfDoc.AddPage;
JpegImage := TJpegImage.Create;
JpegImage.LoadFromFile('C:\SorgentiDelphi\Twain2\immagini\pag_1.jpg');
//JpegImage.ForceJPEGCompression:=90;
pdfImage := TPdfImage.Create(pdfDoc, jpegimage,true);
pdfDoc.AddXObject('image1', pdfimage);
pdfDoc.Canvas.DrawXObject(0, pdfpage.PageHeight-JpegImage.Height,
JpegImage.Width, JpegImage.Height, 'image1');
pdfDoc.SaveToFile('test2.pdf');
pdfDoc.Free;


Fantoni

#16 PDF Engine » Join muliple Jpg image to Pdf file » 2011-02-25 12:13:45

fantoni
Replies: 5

Hi,
How i can  Join all Jpg images files contained in a directory into a single PDF file while maintaining the proportions?

Thanks to all.....

Fantoni

Board footer

Powered by FluxBB