diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.74k stars 1.17k forks source link

Support text columns #304

Open diegomura opened 6 years ago

diegomura commented 6 years ago

OS: All

React-pdf version: Lastest

Description: Add test column layout support. Textkit already supports this

ghost commented 5 years ago

Hi, just curious if this has been/is being implemented. Finding myself in a situation now where I found myself with a really long list that I don't want to continue onto a second page. Want it to wrap into a second column to keep it all on one page.

Maybe there is another way to do this that someone wouldn't mind sharing how they handled it?

AirborneEagle commented 5 years ago

+1 This would be great!

diegomura commented 5 years ago

I’m currently working on a huge refactor and improvement of the text layout that fixes some issues i had with it. So until that’s finished I cannot add this feature to react-pdf, and unfortunately it’s something you cannot achieve right now

alxhghs commented 5 years ago

What would it take to build this feature? Is this something that people could help with? I am looking to dynamically generate PDFs with columns that span multiple pages

imdevan commented 5 years ago

bump

davidecarpini commented 4 years ago

I've used 'original' pdfkit version: ^0.10.0 to build a MULTICOLUMN work-around component:

so just run: yarn add pdfkit

create the component:

import React, { useRef } from 'react';
import { Canvas } from '@react-pdf/renderer';
import PDFKit from 'pdfkit';

interface Props {
  text: string;
  width: number;
  height: number;
  style?: any;
  options?: any;
}

const MultiColumn: React.FC<Props> = ({
  text,
  width,
  height,
  style = {},
  options = {}
}) => {
  const canvasRef = useRef(null);
  return (
    <Canvas
      debug={true}
      ref={canvasRef}
      style={{ width, height, ...style }}
      paint={() => {
        const document = new PDFKit();
        document.page.content = canvasRef.current.root.instance.page.content;
        document.text(text, 0, 0, {
          width,
          height,
          columns: 2,
          ellipsis: true,
          ...options
        });
        return null;
      }}
    />
  );
};

export default MultiColumn;

and use it like:

<MultiColumn width={300} height={100} text={'here your multi line text'} />
artdias90 commented 3 years ago

any news here?

nissimscialom commented 3 years ago

I've used 'original' pdfkit version: ^0.10.0 to build a MULTICOLUMN work-around component:

so just run: yarn add pdfkit

create the component:

import React, { useRef } from 'react';
import { Canvas } from '@react-pdf/renderer';
import PDFKit from 'pdfkit';

interface Props {
  text: string;
  width: number;
  height: number;
  style?: any;
  options?: any;
}

const MultiColumn: React.FC<Props> = ({
  text,
  width,
  height,
  style = {},
  options = {}
}) => {
  const canvasRef = useRef(null);
  return (
    <Canvas
      debug={true}
      ref={canvasRef}
      style={{ width, height, ...style }}
      paint={() => {
        const document = new PDFKit();
        document.page.content = canvasRef.current.root.instance.page.content;
        document.text(text, 0, 0, {
          width,
          height,
          columns: 2,
          ellipsis: true,
          ...options
        });
        return null;
      }}
    />
  );
};

export default MultiColumn;

and use it like:

<MultiColumn width={300} height={100} text={'here your multi line text'} />

Can it also wrap to several pages?

hkar19 commented 3 years ago

Hi, is there any documentation on using @react-pdf/textkit out there, regarding multicolumns?

trevorallred commented 2 years ago

I need this to create a book with two columns on the page. I'm available next week to start work on this. Has anyone else started designing this?

At a high level I'm considering 3 options: 1 - new primitive type called Column 2 - new prop for View called columns 3 - a custom render method for View

I just need 2 columns but I assume we could support multiple with a little extra effort. I also need wrapping across multiple pages to work as expected.

jimmarshall87 commented 2 years ago

Would also find this very useful!

lenardchristopher commented 1 year ago

Still would be very useful!

zdettwiler commented 1 year ago

Still interested in this feature!

sainathaq4 commented 10 months ago

Still interested in this feature!

DevTGhosh commented 6 months ago

Feature is absolutely needed.

huytranbes commented 2 weeks ago

Still interested in this feature!