#1 2019-02-13 06:13:55

Vladimir K.
Member
Registered: 2019-02-13
Posts: 4

Problem converting multipage TIFF to PDF

Hello!
I have problem converting multipage Tiff to PDF. If all page in pdf have one resolution then everything is converted normally, if pages have different resolution, then i have in

      lPdf.DefaultPageWidth:=TIFF_Im.Width;
      lPdf.DefaultPageHeight:=TIFF_Im.Height;

only resolution from the fist page.

sorry for bad english.

program tiff_test;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  SynGDIPlus,
  SynPDF,
  Classes;
var
  lPdf   : TPdfDocument;
  TIFF_Im:TTIFFImage;
  PDF_Im: TPdfImage;
  i:integer;
  pdfpage: TPdfpage;
  Im_Ox:string;
begin
  lPdf := TPdfDocument.Create;
  TIFF_Im:=TTIFFImage.Create;
  TIFF_Im.LoadFromFile('c:\tiff\1.tif');
  for i:=0 to TIFF_Im.GetPageCount-1 do
    begin
      TIFF_Im.ActivePageIndex:=i;
      lPdf.DefaultPageWidth:=TIFF_Im.Width;
      lPdf.DefaultPageHeight:=TIFF_Im.Height;
      pdfpage:=lPDF.AddPage;
      PDF_Im:= TPdfImage.Create (lPDF, TIFF_Im, true);
      Im_Ox:='Im'+IntToStr(i);
      lPDF.AddXObject(Im_Ox,PDF_Im);
      lpdf.Canvas.DrawXObject (0,0, lPdf.DefaultPageWidth, lPdf.DefaultPageHeight, Im_Ox);
      writeln('converting ', i, ' page');
    end;
  lPDF.SaveToFile('c:\SynPDFTest.pdf');
end.

best regards, Vladimir

Last edited by Vladimir K. (2019-02-13 06:27:56)

Offline

#2 2019-02-13 08:19:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problem converting multipage TIFF to PDF

Did you try to set ForceNoBitmapReuse := true ?

Offline

#3 2019-02-13 11:05:26

Chaa
Member
Registered: 2011-03-26
Posts: 249

Offline

#4 2019-02-13 11:58:02

Vladimir K.
Member
Registered: 2019-02-13
Posts: 4

Re: Problem converting multipage TIFF to PDF

Hello, Chaa
I have one multipage tiff file, 1 - 6 pages 595x842 pix, and 7-9 pages 2380x1684 pix (after converting to 72 dpi).
TiffImage return 595x842 for all pages, not paying attention to either the size or the orientation of the page.
drawings on pages 7-9 are elongated (due to incorrect page orientation)
what you propose is working with a list of files.

Offline

#5 2019-02-13 11:59:04

Vladimir K.
Member
Registered: 2019-02-13
Posts: 4

Re: Problem converting multipage TIFF to PDF

ab wrote:

Did you try to set ForceNoBitmapReuse := true ?

Now I tried to force the installation of ForceNoBitmapReuse in both TRUE and FALSE, there is no result.
As I understand the wrong size of the image gives Tiffimage in TIFF_Im.Width and TIFF_Im.Height.

Offline

#6 2019-02-13 12:21:23

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Problem converting multipage TIFF to PDF

Try to add call to procedure fImageSet in the end of TTiffImage.SelectPage.

Offline

#7 2019-02-13 12:59:09

Vladimir K.
Member
Registered: 2019-02-13
Posts: 4

Re: Problem converting multipage TIFF to PDF

Chaa wrote:

Try to add call to procedure fImageSet in the end of TTiffImage.SelectPage.

Thanks, now everything works out correctly. SynGDIPlus now looks like this.

procedure TTiffImage.SelectPage(index: integer);
var wFrames: integer;
begin
  wFrames := GetPageCount;
  if (wFrames>0) and (cardinal(index)<cardinal(wFrames)) then begin
    Gdip.SelectActiveFrame(fImage, @FrameDimensionPage, index);
    fActivePage := index;
  end else
    raise ERangeError.Create('Invalid Page Index');
//***** Add for correct file resolution *****
  fImageSet;
// **********************************
end;

Now I will think how to make the text semitransparent, to create an analogue of watermarks. As I understand it is better to do through VCLCanvas.

Offline

Board footer

Powered by FluxBB