MBS Xojo Conference
6/7th September 2018, Munich

« Training day for MBS … | Home | Hotel for MBS Xojo Co… »

Tip of the day: Joining images to one PDF file

Below a code example on how to quickly join a list of image files into a PDF. You provide the page size, here in milli meter. All images are placed as pages with the given page size. So this is best if you have images in a given paper format (e.g. DIN A4) and you want to merge them to a PDF file. Duplicate images are referenced within the PDF and not added twice to the file, which reduces the file size:

Function CreatePrintPDF(jpgFiles() as folderitem, pdfFile as FolderItem, PageWidth as integer, PageHeight as integer) As Boolean // have files? If pdfFile = Nil Then Return False If jpgFiles = Nil Then Return False If jpgFiles.Ubound < 0 Then Return False // new DynaPDF Dim pdf As New MyDynapdfMBS // page width/height in MilliMeter Dim pdfWidth As Integer = PageWidth * 72 / 25.4 Dim pdfHeight As Integer = PageHeight * 72 / 25.4 // put your license here Call pdf.SetLicenseKey "Starter" // create pdf Call pdf.CreateNewPDF pdfFile // set a couple of options Call pdf.SetPageCoords(MyDynaPDFMBS.kpcTopDown) Call pdf.SetResolution(300) Call pdf.SetUseTransparency(False) Call pdf.SetSaveNewImageFormat(False) Call pdf.SetGStateFlags(MyDynaPDFMBS.kgfUseImageColorSpace, False) Call pdf.SetJPEGQuality(100) // set page size Call pdf.SetBBox(MyDynaPDFMBS.kpbMediaBox, 0, 0, pdfWidth, pdfHeight) Call pdf.SetPageWidth(pdfWidth) Call pdf.SetPageHeight(pdfHeight) // append pages with one image per page For i As Integer = 0 To jpgFiles.Ubound Call pdf.Append Call pdf.InsertImageEx(0, 0, pdfWidth, pdfHeight, jpgFiles(i), 1) Call pdf.EndPage Next // close Call pdf.CloseFile Return True End Function
01 11 15 - 10:58
two comments

Nice! That is exactly what I need just now… Only for FM-plugin :D
MrWatson (Email) - 01 11 15 - 21:46

Just check the DynaPDF examples coming with MBS Plugins. There is a merge/combine PDF example.
Christian Schmitz (URL) - 01 11 15 - 22:23

Remember personal info?

Emoticons / Textile

Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.