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
 Saving image as PDF
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

933 Posts

Posted - Oct 27 2022 :  17:16:03  Show Profile  Reply
I use a TImageEnIO to create screenshots with IEIO.CaptureFromScreen.

Then I save it as a PDF with IEIO.SaveToFile(Filename.pdf).

Currently, the image is placed on top of an A4 page, with the lower part of the page remaining empty.

Is it possible to have the PDF page the same size as the image without empty space outside of the image?

UPDATE: If I use: IEIO.Params.PDF_PaperSize := iepAuto; then the created PDF pages have a lot of empty space around the image. But I need the PDF to have no empty space around the image - a kind of "PDF-AutoSize" (maybe with a configurable margin). How to achieve this?

When using iepAuto then this is how the PDF from a Windows Notepad window screenshot looks in Windows File Explorer Preview:



Please note the empty space around the image.

xequte

38610 Posts

Posted - Oct 27 2022 :  23:15:03  Show Profile  Reply
Hi Peter

Does this happen even if IEIO.Params.PDF_PaperLayout is ielLandscape?



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

933 Posts

Posted - Oct 28 2022 :  00:16:54  Show Profile  Reply
Hi Nigel

I now use this logic:

IEIO.Params.PDF_PaperSize := iepAuto;
if IEIO.IEBitmap.Height > IEIO.IEBitmap.Width then
  IEIO.Params.PDF_PaperLayout := ielPortrait
else
  IEIO.Params.PDF_PaperLayout := ielLandscape;


Now in the Windows Preview Handler (which is a custom one from PDF-XChange) I have set the Preview Size to FITWIDTH:



The Windows Thumbnail Handler from PDF-XChange (in DOpus) shows this:



That's perfect.
Go to Top of Page

PeterPanino

933 Posts

Posted - Oct 28 2022 :  04:03:36  Show Profile  Reply
I have now created a ComboBox to let the user decide the PDF PaperSize:

var a: TIOPDFPaperSize;
  // Fill combobox with available PDF paper sizes:
  ComboBoxPdfPaperSizes.Clear;
  for a := Low(TIOPDFPaperSize) to High(TIOPDFPaperSize) do
  begin
    var ThisPaperSizeStr := iepdf.IEPaperSizeToStr(a);
    if ThisPaperSizeStr <> '' then // exclude the 'Unknown' PaperSize
      ComboBoxPdfPaperSizes.Items.Add(ThisPaperSizeStr);
  end;


This is how it looks in my App:



Then, at run-time I select "A4" PaperSize in the Combobox;

Then I save the screenshot as PDF:

IEIO.Params.PDF_PaperSize := IEStrToPaperSize(ComboBoxPdfPaperSizes.Text); 
if IEIO.IEBitmap.Height > IEIO.IEBitmap.Width then
  IEIO.Params.PDF_PaperLayout := ielPortrait
else
  IEIO.Params.PDF_PaperLayout := ielLandscape;
IEIO.SaveToFile(FileName.pdf);


The created PDF file is 297 x 209,9 mm. And this is how it looks in the PDF Viewer:



If I comment out the PDF Layout part:

{if IEIO.IEBitmap.Height > IEIO.IEBitmap.Width then
  IEIO.Params.PDF_PaperLayout := ielPortrait
else
  IEIO.Params.PDF_PaperLayout := ielLandscape;}


...then the created PDF file is still 209,9 x 297 mm, but it looks totally different in the PDF Viewer (because the default Layout is ielPortrait):



This seems almost correct because A4 is 210 x 297 mm or 297 x 210 mm, respectively.

So setting the PDF Layout with the above method gives correct results.

Also, when printed out on an A4 paper sheet, setting the Layout with this method results in a more efficient paper usage.

BTW, when using the "Auto" (iepAuto) item in the Combobox, the PDF size of the Notepad screenshot results in 155,6 x 105,1 mm - which is smaller than A4.
Go to Top of Page

xequte

38610 Posts

Posted - Oct 30 2022 :  20:18:23  Show Profile  Reply
Hi

Just to clarify a few points:
- PDF_PaperLayout has no effect if PDF_PaperSize=iepAuto
- iepAuto only matches the size to the image, it is not any best-fit standard size (e.g. landscape A4)
- From the next beta the string value of iepAuto will be a localized version of "Automatic"


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: