Extract in PDF format

0
Hi all! I would like to extract one page in PDF. How can I do it? Thanks a lot!!! Jennifer
asked
3 answers
1

Hi Jennifer,

I’m not sure exactly what you want to do, but in Mendix, you can create PDF documents.  You can find a step by step guide here: https://docs.mendix.com/refguide7/how-to-create-your-own-documents#3-the-business-case

Hope that helps,

Mike

**EDIT**

As Wout said in his answer, you can print from your browser.  There is also a widget in the appstore that creates a button to let you print your Mendix page to PDF.  It hasn’t been updated in a while, but could be worth a try:  https://appstore.home.mendix.com/link/app/27069/

 

answered
1

The fastest way to extract one page is to choose Print in your browser (or ctrl+P)

As printer you can choose: Save as PDF.
 

answered
1

If you mean split PDF and get that one page, this is very simple sample java code.

This is using Apache PDFBox it included in CommunityCommons module.

 

// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package myfirstmodule.actions;

import communitycommons.Logging;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import org.apache.pdfbox.multipdf.Splitter;
import org.apache.pdfbox.pdmodel.PDDocument;

public class splitPDF extends CustomJavaAction<java.util.List<IMendixObject>>
{
	private IMendixObject __Parameter;
	private myfirstmodule.proxies.Pdf Parameter;

	public splitPDF(IContext context, IMendixObject Parameter)
	{
		super(context);
		this.__Parameter = Parameter;
	}

	@java.lang.Override
	public java.util.List<IMendixObject> executeAction() throws Exception
	{
		this.Parameter = __Parameter == null ? null : myfirstmodule.proxies.Pdf.initialize(getContext(), __Parameter);

		// BEGIN USER CODE
		String LOGNODE = "PdfSplit";
		Logging.createLogNode(LOGNODE);

		List<IMendixObject> out = new java.util.ArrayList<IMendixObject>();
		ByteArrayInputStream bis = null;
		ByteArrayOutputStream bos = null;
		try {
			Logging.debug(LOGNODE, "start");
			PDDocument document = PDDocument.load(Core.getFileDocumentContent(getContext(), __Parameter));
			Splitter splitter = new Splitter();
			List<PDDocument> pages = splitter.split(document);
			Iterator<PDDocument> iterator = pages.listIterator();
			int i = 0;
			while(iterator.hasNext()) {
				Logging.debug(LOGNODE, "loop: " + i);
				i++;
				PDDocument pd = iterator.next();
				bos = new ByteArrayOutputStream();
				pd.save(bos);
				bis = new ByteArrayInputStream(bos.toByteArray());
				IMendixObject obj = Core.instantiate(getContext(), "MyFirstModule.Pdf");
				Core.storeFileDocumentContent(getContext(), obj, String.valueOf(i), bis);
				out.add(obj);
			}
			document.close();
		} catch (Exception e) {
			Logging.error(LOGNODE, e.toString());
			throw e;
		} finally {
			if (bis != null) {
				bis.close();
			}
			if (bos != null) {
				bos.close();
			}
		}
		Logging.debug(LOGNODE, "end");
		return out;
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "splitPDF";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

 

answered