Export/Print as PDF merging the same page

Firstly, I do this all automatically with macros (BASIC)
Simplifying as much as I can… I have a page form for printing (with images and some drawing and stuff) where it shows fields from tables. Let’s say a person have can have many of these pages. So the data from fields vary, but not the page. Think of the mail merge but all pages together.

The problem is that I can only print that single page at once. This means : load row → print → next row → print → next… And I end with too many files, and I need them in a SINGLE PDF, and then send it by email to that person (but I already know how to do that)

My first thought was using an external program that can use the command line, first printing them and the using the third party program for merging them, I haven’t found any free program that can do it, but I would rather avoid that. I would hear any solution that use them anyway.

Then I found another alternative in this forum with calc, that I don’t know how to apply to base forms. They copied the page to some other place on the file, like a buffer, and printing altogether when finished. Would be this possible? Like duplicating the entire page to the end of the form?

Hi, @dvd251996, I understand that there is several data, in different locations, about the person, and I would like to bring them together on a single page in PDF

Without seeing the file, my guess would be to create a print form in a spreadsheet, where the data key would be the person, and the data is obtained using the VLOKUP function.

Post an example file, and what you want as an output, it will be easier to help.



Entendi que há varios dados, em locais diferentes, da pessoa, e gostaria de reunir em unica página em PDF

Sem ver o arquivo, meu palpite, seria em uma planilha montar um formulario de impressão, onde a chave dos dados seria a pessoa, e os dados são conseguidos com uso da função VLOKUP.

Poste um arquivo exemplo, e o que deseja de saida, ficará mais fácil ajudar.

Why don’t you use Report Builder, which is part of Base?

pdfSAM for pdf split and merge
.
Pdftk

1 Like

… or PdfBox https://pdfbox.apache.org/
see PDFMerger on Apache PDFBox | Command-Line Tools

1 Like

I use under Win10: Free PDF Tools FREE PDF Tools to Merge, Split, Encrypt, Rotate, Crop, Header, Watermark, Image to PDF, PDF to Image...

1 Like

Have created the following solution with Base Report Builder some times ago:

REM  *****  BASIC  *****

SUB ReportStart
	oReport = ThisDatabaseDocument.ReportDocuments.getByName("MyReport").open
	GroupNewPage(oReport)
END SUB

SUB GroupNewPage(oReport AS OBJECT)
	DIM oTables AS OBJECT
	DIM oTable AS OBJECT
	DIM inT AS INTEGER
	oTables = oReport.getTextTables()
	FOR inT = 0 TO oTables.count() - 1
		oTable = oTables.getByIndex(inT)
		IF Left$(oTable.name, 7) = "MyGroup" THEN
			oTable.PageNumberOffset = 1
		ENDIF
	NEXT inT
END SUB

SUB Print_to_PDF
	DIM oDoc AS OBJECT
	DIM oDatasource AS OBJECT
	DIM oConnection AS OBJECT
	DIM oSQL_Statement AS OBJECT
	DIM oSQL_Statement_1 AS OBJECT
	DIM oResult AS OBJECT
	DIM oReport AS OBJECT
	DIM oReportView AS OBJECT
	DIM stDir AS STRING
	DIM stSql AS STRING
	DIM stFilter AS STRING
	DIM stUrl AS STRING
	DIM arg(0) AS NEW com.sun.star.beans.PropertyValue
	oDoc = ThisDatabaseDocument
	stDir = Left(oDoc.Location,Len(oDoc.Location)-Len(oDoc.Title))
	oDatasource = oDoc.CurrentController
	IF NOT (oDatasource.isConnected()) THEN oDatasource.connect()
	oConnection = oDatasource.ActiveConnection()
	oSQL_Statement = oConnection.createStatement()
	stSql = "SELECT DISTINCT ""SCH"" FROM ""MyTable"""
	oResult = oSQL_Statement.executeQuery(stSql)
	arg(0).name = "FilterName"
	arg(0).value = "writer_pdf_Export"
	oQueries = oDatasource.DataSource.getQueryDefinitions()
	oQuery = oQueries.getByName("Query1")
	WHILE oResult.Next		
		oSQL_Statement_1 = oConnection.createStatement()
		stFilter = oResult.getString(1)
		oQuery.Command = "SELECT * FROM ""MyTable"" WHERE ""SCH"" = '"+stFilter+"'"
		oReport = oDoc.ReportDocuments.getByName("MyReport").open
		oReportView = oReport.CurrentController.Frame.ContainerWindow
		oReportView.Visible = False
		stUrl = stDir + "pdfs/" + stFilter + ".pdf"
		oReport.storeToURL(stUrl, arg())
		oReport.close(true)
	WEND
	oQuery.Command = "SELECT * FROM ""MyTable"""
END SUB

Creates for every new group a new PDF in a subfolder.

Hi! thanks for your help!.
I tried with reports but honestly I dont quite understand how they work, They are not as much customizable as forms, and act in a weird way,
If I understood correctly this would create a pdf for each group, but what I would need is to reapeat the same page with different data and the reports get the different data on the same page(?)

Thanks @Wanderer @ms777 and @KamilLanda for the help.
I checked these and PDFbox seems simple enought, it just requires a single file. If I cant find a way to do it natively I’ll end using it.

I put the command I used in case is usefull for someone in the future

shell(“java -jar ““C:\PDF\pdfbox-app-3.0.1.jar”” merge -i=”“C:\PDF\1.pdf”" -i="“C:\PDF\2.pdf”" -o="“C:\PDF\output.pdf”"")

@dvd251996 : A report could be grouped, for example, by the name of a person. If there are many rows of data for this person all this rows will appear in the group.

I have created such a report in Base Guide for a library: All reminders for a person will be printed by the report. Looks like a letter for all this persons.