1
votes

I am trying to convert an image file to a PDF document with a defined page size (letter size).

Currenlty I am able to convert an image to a PDF document without defining any page dimensions (default dimensions of the PDF is the image size). I would like to define the page dimensions on the creation of the document, and place the image on that page (possibly with margins).

The following code snippet shows how I am currently converting an image file to a PDF document without setting any dimensions for the page:

async static Task<bool> ConvertImageToPDF(TestFile file)
{
    pdftron.PDF.PDFDoc pdfdoc = new PDFDoc();  //Initialize a new PDF document
    pdftron.PDF.Convert.ToPdf(pdfdoc, file.InputFile);   //Use the Convert.ToPdf to generate the file from the image file   
    await pdfdoc.SaveAsync(file.OutputFile, SDFDocSaveOptions.e_linearized);  //Save the PDF document generated from the conversion
    pdfdoc.Destroy();
    pdfdoc = null;
}

Any help or direction for assigning dimensions (letter size) to a PDF page and inserting the image file in that page would be more than welcome.

1

1 Answers

0
votes

If ToPDF is given an image then PDFNet will query the DPI information of the image metadata and make page dimensions to match the DPI and resolution of the source.

If you like, you can always post-process the PDF generated by ToPDF.

Or, you can follow the AddImage sample code to do everything yourself. https://www.pdftron.com/pdfnet/samplecode.html#AddImage