looking for some solutions? You are welcome.

SOLVED: Blank Pdf is genrating

Amigo:

Pdf is genrating but its is coming blank ,I want to get a html content data in pdf without losing formatting, so i tried this code in this only blank pdf is genrating

    package config;
import com.lowagie.text.DocumentException;
import org.apache.commons.io.FileUtils;
import org.docx4j.org.xhtmlrenderer.pdf.ITextRenderer;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
public class removeHtmlTag {
          public static void main(String [] args) throws DocumentException, IOException {
            FileUtils.writeByteArrayToFile(new File("removeHtmlTag.pdf"), toPdf("<b>YouAAA gotta walk and don't look back</b>"));
          }

          /**
           * Generate a PDF document
           * @param html HTML as a string
           * @return bytes of PDF document
           */
          private static byte[] toPdf(String html) throws DocumentException, IOException {
            final ITextRenderer renderer = new ITextRenderer();
            renderer.setDocumentFromString(html);
            renderer.layout();
            try (ByteArrayOutputStream fos = new ByteArrayOutputStream(html.length())) {
              renderer.createPDF(fos);
              return fos.toByteArray();
            }
          }

    }



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent