#1 2016-08-18 07:34:56

pivbul
Member
Registered: 2016-08-18
Posts: 3

jpg to pdf: how to change document resolution?

hello friends.
I created a pdf from jpeg images (300 and 600 dpi), but when printing in acrobat the resolution of the images on each page change. For correct printing in acrobat every time you need to manually select the option to "fit". How can I specify the size of the pdf document such as 300 dpi?

pdfdoc:=TPdfDocument.Create(False, 0, True, Nil);
pdfdoc.DefaultPaperSize:=psA4;
pdfdoc.ForceJPEGCompression:=0;
pdfdoc.CompressionMethod:=cmFlateDecode;
jpg:=tjpegimage.Create;
  try
  jpg.LoadFromFile('c:\1.jpg');
  pdfpage:=pdfdoc.AddPage;
  pdfpage.PageWidth:=jpg.Width;
  pdfpage.PageHeight:=jpg.Height;
  pdfImage:=TPdfImage.Create(pdfDoc,jpg,true);
  pdfdoc.AddXObject('image1', pdfimage);
  pdfdoc.Canvas.DrawXObject(0,0,pdfpage.PageWidth,pdfpage.PageHeight,'image1');
  except end;
//next try...except
jpg.Free;
pdfdoc.SaveToFile('c:\1.pdf');
pdfdoc.Free;

photo sample: https://yadi.sk/i/SH5jpEnduJSPt

Offline

#2 2016-08-18 08:51:59

pivbul
Member
Registered: 2016-08-18
Posts: 3

Re: jpg to pdf: how to change document resolution?

P.S. current page size in Adobe Acrobat: 874,9mm x 1237,5mm

Offline

#3 2016-08-18 09:49:57

pivbul
Member
Registered: 2016-08-18
Posts: 3

Re: jpg to pdf: how to change document resolution?

I manually altered the values of 72 to 300 in the file SynPdf.pas in four places, worked.
...
constructor TPdfCanvas.Create(APdfDoc: TPdfDocument);
begin
  FDoc := APdfDoc;
  FFactor := 300/FDoc.FScreenLogPixels; // PDF expect 72 pixels per inch
  FFactorX := FFactor;
  FFactorY := FFactor;
  FDevScale := 1;
  FMappingMode := MM_TEXT;
  fUseMetaFileTextPositioning := tpSetTextJustification;
  fKerningHScaleBottom := 99.0;
  fKerningHScaleTop := 101.0;
end;
...
procedure TPdfCanvas.SetPage(APage: TPdfPage);
begin
  FPage := APage;
  FPageFontList := FPage.GetResources('Font');
  FContents := TPdfStream(FPage.ValueByName('Contents'));
  FFactor := 300/FDoc.FScreenLogPixels; // PDF expect 72 pixels per inch
end;
...
procedure TPdfPageGDI.SetVCLCurrentMetaFile;
var tmp: RawByteString;
    Stream: TStream;
begin
  assert(fVCLCurrentMetaFile=nil);
  fVCLCurrentMetaFile := TMetaFile.Create;
  fVCLCanvasSize.cx := MulDiv(PageWidth,FDoc.FScreenLogPixels,300);
  fVCLCanvasSize.cy := MulDiv(PageHeight,FDoc.FScreenLogPixels,300);
  fVCLCurrentMetaFile.Width  := fVCLCanvasSize.cx;
  fVCLCurrentMetaFile.Height := fVCLCanvasSize.cy;
  if fVCLMetaFileCompressed<>'' then begin
    tmp := fVCLMetaFileCompressed;
    CompressSynLZ(tmp,false);
    Stream := TRawByteStringStream.Create(tmp);
    try
      fVCLCurrentMetaFile.LoadFromStream(Stream);
    finally
      Stream.Free;
    end;
  end;
end;
...

Offline

#4 2016-08-18 10:17:16

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

Re: jpg to pdf: how to change document resolution?

I'm afraid you are making a confusion.
There is NO such think as resolution in the PDF format, since it uses floating-point coordinates and a 72 DPI unit.

So don't use this code, but try with the ScreenLogPixels property.

Offline

Board footer

Powered by FluxBB