Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Feb 04, 2021 8:12 am

Hi ,

I used the function html convert to pdf with new plugin. I found an issue that some (words , tables ) contents are broken . I have attached screenshot with broken table contents . Please find and let me know the solution . Thanks in advance .

This is sample example . I faced the above issue for words also .

my tset code:
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(strNewFileLocation, strOutputFileName, true, 10 * 1000, new SizeF(612, 792),new Spire.Pdf.Graphics.PdfMargins(3, 3, 3, 3));

JayanthiJaya
 
Posts: 22
Joined: Thu Jan 21, 2021 6:06 am

Thu Feb 04, 2021 10:09 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more accurately, please provide us with your HTML file/URL. You could send it to us via email([email protected]). Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Feb 04, 2021 11:18 am

hi ,

I sent you an email with attachment . Please find the attachment and do the needful. Thanks in advance.

JayanthiJaya
 
Posts: 22
Joined: Thu Jan 21, 2021 6:06 am

Thu Feb 04, 2021 11:49 am

Hi,

I have attached one more file . please find the attachment and do the needfull.

JayanthiJaya
 
Posts: 22
Joined: Thu Jan 21, 2021 6:06 am

Fri Feb 05, 2021 2:46 am

Hello,

Thanks for providing more information.
To avoid the text in the table being cut off, there are two solutions for you.

1. Set a larger value for the bottom margin, as shown below.
Code: Select all
//Change the bottom margin to 10
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(inputFile, outputFile, true, 10 * 1000, new SizeF(612, 792), new Spire.Pdf.Graphics.PdfMargins(3, 3, 3, 10));


2. In your html file, add the style "page-break-inside: avoid;" to the <tr> tag, which will avoid page-break within the table row. I have sent you the modified HTML file via email.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Feb 17, 2021 6:02 am

hi,

now working fine . Thank you so much .

JayanthiJaya
 
Posts: 22
Joined: Thu Jan 21, 2021 6:06 am

Wed Feb 17, 2021 6:14 am

Hello,

Thanks for your feedback.
If you encounter any questions related to our product in the future, just feel free to contact us!
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Jan 04, 2024 6:07 pm

1. We are still getting broken and splitted table content in generated pdf from html after applying above provided solution. Please find sample input file attached.

2.
Code: Select all
      Path tempFile = Files.createTempFile("output", ".html");

      try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(tempFile.toFile().getPath()),
            StandardCharsets.UTF_8)) {
         writer.append(htmlString);
         writer.newLine();
      } catch (IOException e) {
         throw e;
      }

      logger.info("temp file created: " + tempFile.toFile().getPath());

      File outputFile = File
            .createTempFile("output_pdf_" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()), ".pdf");

      // Set license key
      com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);

      // Set plugin path
      HtmlConverter.setPluginPath(PLUGIN_PATH);

      // Convert HTML string to PDF
      HtmlConverter.convert(tempFile.toFile().getPath().toString(), new FileOutputStream(outputFile), true,
            1000000000, new Size((float) PageSize.A4.getWidth(), (float) PageSize.A4.getHeight()),
            new PdfMargins(40));
      logger.info("outputResource.getFile().length() " + outputFile.length());

      return addPageNumberToPDF(outputFile.getAbsolutePath());

   


Manifest-Version: 1.0
Extension-Name: spire.office
Implementation-Title: spire.office for java
Implementation-Version: 8.12.0
Implementation-Vendor: E-iceblue Co., Ltd.
Implementation-Vendor-Id: com.spire
Implementation-URL: https://www.e-iceblue.com

4. Application Type: Spingboot JDK 1.8

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Fri Jan 05, 2024 4:17 am

Hi,

Thank you for your inquiry.
Due to the specified height and width restrictions on PDF pages in the “HtmlConverter.Convert” method, any parts exceeding the page size during plugin conversion will be displayed on the next page and cannot be displayed on the same page. You can try to convert HTML to Word first, and then convert Word to PDF.
I put the complete code below for your reference:
Code: Select all
        // Create a new Document object
        Document doc = new Document();

        // Load the HTML file "data/sample input 1.html" into the document
        doc.loadFromFile("data/sample input 1.html", FileFormat.Html);

      // Save the document as a Word document with the name "output/HTMLtoWord.docx"
        doc.saveToFile("output/HTMLtoWord.docx", FileFormat.Docx);

        // Create a new Document object for reading the saved Word document
        Document doc1 = new Document();

        // Load the saved Word document "output/HTMLtoWord.docx" into the document
        doc1.loadFromFile("output/HTMLtoWord.docx");

        // Get the first section of the document
        Section section = doc1.getSections().get(0);

        for(int i=7;i<section.getParagraphs().getCount();i++){
            // Get the current paragraph
            Paragraph paragraph = section.getParagraphs().get(i);

            // Get the paragraph format
            ParagraphFormat paragraphFormat = paragraph.getFormat();

            // Set the horizontal alignment of the paragraph to left
            paragraphFormat.setHorizontalAlignment(HorizontalAlignment.Left);
        }

        // Set the page size of the section to A4 and the orientation to portrait
        section.getPageSetup().setPageSize(com.spire.doc.documents.PageSize.A4);
        section.getPageSetup().setOrientation(PageOrientation.Portrait);

        // Save the modified document as a PDF with the name "output/WordToPDF1.pdf"
        doc1.saveToFile("output/WordToPDF1.pdf",FileFormat.PDF);

If you have any issue, just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Mon Jan 08, 2024 9:09 am

Hello,

I tried above table is jot splitting but table's border is not visible.

Thanks and regards,
Umesh Asodekar

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Mon Jan 08, 2024 9:55 am

Hi,

Thank you for your feedback.
Did you use the latest version of Spire. Office for java 8.12.0? if not, please use the latest version of Spire.Office for java 8.12.0 to test again.
I have placed download Link and my results file below for your reference.

Download Link:https://www.e-iceblue.com/Download/office-for-java.html

Sincerely,
Ula
E-iceblue support team

WordToPDF1.rar
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Tue Jan 09, 2024 4:59 pm

Hello,

Yes, I have used 8.12.0 version of spire office.

Manifest-Version: 1.0
Extension-Name: spire.office
Implementation-Title: spire.office for java
Implementation-Version: 8.12.0
Implementation-Vendor: E-iceblue Co., Ltd.
Implementation-Vendor-Id: com.spire
Implementation-URL: https://www.e-iceblue.com

Code: Select all
public static String convertHTMLToDocToPdf(String htmlString) throws IOException {

      Path tempHTMLFile = Files.createTempFile("output", ".html");

      try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(tempHTMLFile.toFile().getPath()),
            StandardCharsets.UTF_8)) {
         writer.append(htmlString);
         writer.newLine();
      } catch (IOException e) {
         throw e;
      }

      // Set license key
      com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);

      // Create a new Document object
      Document doc = new Document();

      // Load the HTML file "data/sample input 1.html" into the document
      doc.loadFromFile(tempHTMLFile.toFile().getPath().toString(), FileFormat.Html);

      Path tempWordFile = Files.createTempFile("HTMLtoWord", ".docx");

      // Save the document as a Word document with the name "output/HTMLtoWord.docx"
      doc.saveToFile(tempWordFile.toFile().getPath().toString(), FileFormat.Docx);

      // Create a new Document object for reading the saved Word document
      Document doc1 = new Document();

      // Load the saved Word document "output/HTMLtoWord.docx" into the document
      doc1.loadFromFile(tempWordFile.toFile().getPath().toString());

      // Get the first section of the document
      Section section = doc1.getSections().get(0);

      for (int i = 7; i < section.getParagraphs().getCount(); i++) {
         // Get the current paragraph
         Paragraph paragraph = section.getParagraphs().get(i);

         // Get the paragraph format
         ParagraphFormat paragraphFormat = paragraph.getFormat();

         // Set the horizontal alignment of the paragraph to left
         paragraphFormat.setHorizontalAlignment(HorizontalAlignment.Left);
      }

      // Set the page size of the section to A4 and the orientation to portrait
      section.getPageSetup().setPageSize(com.spire.doc.documents.PageSize.A4);
      section.getPageSetup().setOrientation(PageOrientation.Portrait);

      File tempPdfFile = File
            .createTempFile("WordToPDF1_" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()), ".pdf");

      // Save the modified document as a PDF with the name "output/WordToPDF1.pdf"
      doc1.saveToFile(tempPdfFile.getAbsolutePath(), FileFormat.PDF);
      logger.info(tempPdfFile.getAbsolutePath());

      return tempPdfFile.getAbsolutePath();
   }


Thanks and regards,
Umesh Asodekar

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Tue Jan 09, 2024 5:04 pm

PFA.

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Wed Jan 10, 2024 3:43 am

Hello,

Thank you for your feedback.
I have tested the HTML file you provided and was able to reproduce the issue where the table borders are not visible. However, upon investigation, I found that this problem occurred because you set "table border='0'" in the HTML file. By changing it to "table border='1'", the resulting output file now displays the table borders correctly.
Attached are the modified HTML file and the converted output file for your reference.
If you have any further questions or need additional assistance, please don't hesitate to let me know.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF