Git Product home page Git Product logo

Comments (6)

euZebe avatar euZebe commented on July 4, 2024 4

It seems like just switching width and height do the trick:

  const options: Options = {
    html: MyHTMLContent,
    fileName: myDocName,
    directory: myDirectory,
    base64: true,
    width: 792,
    height: 612,
  }

from react-native-html-to-pdf.

esutton avatar esutton commented on July 4, 2024

@waltershub I wish I had time to clean this up and offer a PR.

You are welcome to use or fork. It works on both Android and iOS and supports various page sizes and landscape and portrait.

I added options for page: { size, orientation ) to react-native-html-to-pdf index.js

This may have been a bad place to add them. Not sure.
My goal was to maintain page options in a single place in JS rather than have to maintain in both Android and iOS native code.

See page:
https://github.com/esutton/react-native-html-to-pdf/blob/master/index.js

  onWriteFile = async (fileAttachment, sendCallback) => {
    try {
      if (fileAttachment.mimeType === MimeType.Pdf) {
        const optionsRNHTMLtoPDF = {
          directory: 'docs',
          fileName: fileAttachment.fileBaseName,
          html: fileAttachment.fileData.html,
          page: {
            size: RNHTMLtoPDF.page.size.UsLetter,
            orientation: RNHTMLtoPDF.page.orientation.Landscape,
          },
        };

        await RNHTMLtoPDF.convert(optionsRNHTMLtoPDF);
        // Email the resulting PDF file
        this.onWriteFileComplete(fileAttachment, sendCallback);
        return;
      }

      await RNFS.writeFile(
        fileAttachment.path,
        fileAttachment.fileData,
        fileAttachment.encoding,
      );
      this.onWriteFileComplete(fileAttachment, sendCallback);
    } catch (err) {
      Analytics.logException(`${TAG} onWriteFile`, `Failed to write file: ${fileAttachment.path}`, err);
      Alert.alert(
        `${I18n.t('error')} ${I18n.t('unexpected')}`,
        `${I18n.t('save')}: ${fileAttachment.name}\n${err.message}`,
      );
    }
  };

from react-native-html-to-pdf.

MarisTM avatar MarisTM commented on July 4, 2024

Any news on this issue? I tried to landscape but nothing

from react-native-html-to-pdf.

rabbanirizwan avatar rabbanirizwan commented on July 4, 2024

any solution for this

from react-native-html-to-pdf.

stale avatar stale commented on July 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from react-native-html-to-pdf.

J0ANGARFLO avatar J0ANGARFLO commented on July 4, 2024

It seems like just switching width and height do the trick:

  const options: Options = {
    html: MyHTMLContent,
    fileName: myDocName,
    directory: myDirectory,
    base64: true,
    width: 792,
    height: 612,
  }

Thanks this is the solution

from react-native-html-to-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.