You are viewing limited content. For full access, please sign in.

Question

Question

ExportPDF Multiple Files to One PDF?

asked on September 18, 2014

How can you export multiple files to a single PDF?

(Using SDK (LF) 8.3)

Any Code, Samples, Tutorials, Links???

Thank you!

Below is some of my working code that creates a single PDF from the most recent file in a list of found files; but now I need to a combine all the found files into one PDF for export.

********************

...
SearchResultListing Results = lfSearch.GetResultListing(searchSettings);
instFileID = Results.GetDatumAsString(1, SystemColumn.Id);
...
DocumentInfo docInfo = Document.GetDocumentInfo(Int32.Parse(instFileID, System.Globalization.NumberStyles.AllowThousands), session);
DocumentExporter exporter = new DocumentExporter();
exporter.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, strLocalPath + strDocumentFILE);
...

0 0

Answer

SELECTED ANSWER
replied on September 18, 2014 Show version history

There are no tools in the LF SDK to export multiple LF documents into a single PDF.

 

You could work around the issue by creating a temp Doc in LF and copying all the documents into it, export it, then delete it.  Otherwise, you would need to use other SDK/Toolkits to merge the PDFs after they were exported from the Repository.

0 0

Replies

replied on September 18, 2014

While there's no built-in support for this, you can achieve what you want without the need for any external libraries or creating temporary documents. The first argument to DocumentExporter.ExportPdf is actually an IDocumentContents, not a DocumentInfo. You can write your own class which implements the IDocumentContents interface that composes multiple documents together. The methods you really need to override are GetStatistics, GetPageInfo, GetPageInfos, and GetThumbnails. The rest of the methods you can more or less forward directly forward over to a DocumentInfo instance. It's a bit tricky to implement GetPageInfos since it returns a PageInfoReader instance. You'll need a class that derives from PageInfoReader to return.

1 0
replied on September 19, 2014

Thanks Michael.

I'd really like to try IDocumentContents; however it is beyond my knowledge to do it from scratch. (I learn from examples.)

I imagine I'd loop through my SearchResultListing and use IDocumentContents to stuff some 'Thing'; then go ExportPdf(Thing..).
Do you know of a code sample to show the 'stuff thing' with IDocumentContents part? ​Please forgive the "Noob" speak.

Currently I'm digging in the SDK83_Documentation.chm to find a clue.
 

0 0
replied on September 19, 2014

It would be fairly challenging to develop an implementation of IDocumentContents that splices together multiple documents and is more involved than what you describe. It would involve writing multiple classes. An easier solution is to export the PDFs and then splice them together outside of LF, which Bert suggested. I'll see about making this easier in a future version of the SDK.

0 0
replied on September 19, 2014

I'll see about making this easier in a future version of the SDK.

 

Thanks Michael.

 

It would be great if this was a built in feature of the SDK.  To try to create the solution you alluded to, I would think that one would have to have an intimate knowledge of the RA objects in order to create robust reliable overrides.  Also, as there is no documentation on how to combine multiple DocumentInfo objects into a single IDocumentContents or how to create a PageSet from multiple documents, one could spend a lot of time without much progress.

0 0
replied on September 18, 2014

Thank you for your reply Bert. (Not the answer I was hoping for, but..)

For safety and simplicity I only want to pull from LF. So I'll probably go the other route you suggested and use something like PDFsharp.

I'll check this thread again in case anyone else has a cool idea.

 

 

0 0
replied on September 22, 2014

Thank you to both Bert and Michael for the guidance.

With your input I went with the 3rd tool route and everything is working as I need.

Basically I'm looping through the Results to generate the individual PDF files; then using PDFsharp to merge them together.

Here's my rough/working code...

// START: NEW CreateAllDocs TRICK
int docCount = Results.RowsCount;
for (int i = 1; i < docCount+1; i++)
{
	fileID = Results.GetDatumAsString(i, SystemColumn.Id);
	docInfo = Document.GetDocumentInfo(Int32.Parse(fileID, System.Globalization.NumberStyles.AllowThousands), session);
	exporter.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, strLocalPath + strDocumentNAME + "-" + i + ".pdf");
}
// END: NEW CreateAllDocs TRICK

// START: NEW MergeAllDocs TRICK
PdfDocument tempPDF;
PdfDocument outPdf = new PdfDocument();

for (int i = 1; i < docCount + 1; i++)
{
	tempPDF = PdfReader.Open(strLocalPath + strDocumentNAME + "-" + i + ".pdf", PdfDocumentOpenMode.Import);
	for (int p = 0; p < tempPDF.PageCount; p++)
	{
		outPdf.AddPage(tempPDF.Pages[p]);
	}
}
outPdf.Save(strLocalPath + strDocumentFILE);
// END: NEW MergeAllDocs TRICK

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.