Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #26582

    Hello,
    Iam a paid user. We have been using your product for quite a while. We are very much happy with this. Recently we have got one requirement ,where we have one big HTML Report needs to converted as PDF.

    We tried to make use of yours. But here when try to output as ledger type (11/17), pdf width is coming as 79.1% only. We need it 120% (atleaset 100%), since the font of 79.1% is non readable.

    Below is the code snippet using to generate

    pd4ml.fitPageVertically();
    pd4ml.adjustHtmlWidth();
    pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.LEDGER));

    Please help us as quickly as possible.

    Tom
      #28586

      Adding to the below issue, i would like to add my output pdf file for better understanding on the problem. Please let me know if you require input html file

      We want whole pdf content to expand to its right.

      #28587

      [language=java:3d8jgyrb]pd4ml.fitPageVertically();
      pd4ml.adjustHtmlWidth();[/language:3d8jgyrb]

      Both API calls are intended to automatically compute htmlWidth value, which fulfills specific requirements. The first call increases htmlWidth (in other words scales down the document layout) until the document content fits a single page.

      The second call cares, that top right content edge of the page is not cut.

      If you call both methods the results are not predictable.

      If I understand you correctly you would like to fill a single page horizontally and vertically with the document content. Please correct if I am wrong. PD4ML does not support the mode. However there is a relatively simple (but resource consuming) method to achieve that.

      You need to increase htmlWidth in small amounts and render the document into a ByteArrayOutputStream. After each iteration control a relation between resulting document width and height (until the aspect ratio is the same as of PD4Constants.LEDGER). You may request the document height and width (in pixels) with the calls:

      [language=java:3d8jgyrb]pd4ml.render(url, byteArrayOutputStream);
      System.out.println(“height: ” + (Long)pd4ml.getLastRenderInfo(PD4Constants.PD4ML_DOCUMENT_HEIGHT_PX));
      System.out.println(“right edge: ” + (Long)pd4ml.getLastRenderInfo(PD4Constants.PD4ML_RIGHT_EDGE_PX));[/language:3d8jgyrb]

      Tom
        #28588

        Thanks for you reply..

        Now i removed pd4ml.adjustHtmlWidth() call. Yes you are right. I need to fill a single page horizontally and vertically with the document content. In the attached output pdf in my previous thread you can see content is not expanding to the right.

        Also i couldnot understand this ByteArrayOutputStream . I could only get output pdf if i use fileoutputstream object.

        I hope you understood the problem iam facing. Vertically it is coming fine. When it comes to horizontally content is not expanding 100%.

        Could you please suggest me code to use ByteArrayoutputstream .

        As of now this is my current code..

        java.io.FileOutputStream fos = new java.io.FileOutputStream(“C:/ouputPdf.pdf”);

        PD4ML pd4ml = new PD4ML();

        pd4ml.fitPageVertically();

        pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.LEDGER));

        pd4ml.render(“file:” + inputHTMLFileName, fos );

        #28589

        Schematically it looks like that:
        [language=java:2bwk47xo]double desiredRatio = (double)PD4Constants.LEDGER.width / PD4Constants.LEDGER.height;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for ( int i = 0; i < 40; i++ ) { int width = 900 + (i * 20); pd4ml.setHtmlWidth( width ); pd4ml.render(urls, baos); int height = ((Long)pd4ml.getLastRenderInfo(PD4Constants.PD4ML_DOCUMENT_HEIGHT_PX)).intValue(); // width = ((Long)pd4ml.getLastRenderInfo(PD4Constants.PD4ML_RIGHT_EDGE_PX)).intValue(); // for special cases double actualRatio = (double)width / height; if ( actualRatio < desiredRatio * 1.1 && actualRatio > desiredRatio * 0.9 ) {
        break;
        }

        baos.reset();
        }

        fos.write( baos.toByteArray() );
        fos.close();[/language:2bwk47xo]

        The numeric constant values (width step, number of steps, matching aspect ratio scope) have no special meaning, so they needs to be adjusted for your particular case.

        And please take into account, each render() call is a resource consuming task, so it makes sense to reduce a number of calls to the possible minimum.

        Tom
          #28590

          I just replaced with your code . Firstly document is getting generated with a size of 0kb by taking 10 sec to 12 secs time. When i try to open it obviously it is showing file is damaged.

          if you want i can provide you my input html .

          Please suggest the solution for this problem or give a conclusion on this regard. We need to tell the same to our client as soon as possible.

          The following is the code i used

          java.io.FileOutputStream fos = new java.io.FileOutputStream(outputPDFFile); PD4ML pd4ml = new PD4ML();
          pd4ml.fitPageVertically();
          pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.LEDGER)); // ledger page orientation
          double desiredRatio = (double)PD4Constants.LEDGER.width / PD4Constants.LEDGER.height;
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          for ( int i = 0; i < 40; i++ ) { int width = 900 + (i * 20); pd4ml.setHtmlWidth( width ); pd4ml.render("file:" + inputHTMLFileName, baos); int height = ((Long)pd4ml.getLastRenderInfo(PD4Constants.PD4ML_DOCUMENT_HEIGHT_PX)).intValue(); //width = ((Long)pd4ml.getLastRenderInfo(PD4Constants.PD4ML_RIGHT_EDGE_PX)).intValue(); // for special cases double actualRatio = (double)width / height; if ( actualRatio < desiredRatio * 1.1 && actualRatio > desiredRatio * 0.9 ) {
          break;
          }

          baos.reset();
          }

          fos.write( baos.toByteArray() );
          fos.close();

          #28591

          As I wrote it was only schematic code. Put there some debug output and check if the condition is true at some point.

          if ( actualRatio < desiredRatio * 1.1 && actualRatio > desiredRatio * 0.9 ) {
          break;
          }

          The resulting document is 0 bytes, as it is reset by the line:

          baos.reset();

          Probably it makes sense to place the line just after

          for ( int i = 0; i < 40; i++ ) {

          Tom
            #28592

            Well, i had to do lot of trail and error kind of things before i write new comment with my observations on your code.
            Still we are not comfortable with the solution you provided:

            Reason :
            I had kept your modified code and i did some modifications to reduce the time taking by pd4ml to generate the document.

            Your code : ………………..
            for ( int i = 0; i < 40; i++ ) { baos.reset(); int width = 900 + (i * 20); ............. Changed code : .................... for ( int i = 0; i < 3; i++ ) { baos.reset(); int width = 900 + (i * 425); ............. I just reduced the number of iterations. With either your code or my changed code , i could just expand the content to right side. So that left margin, right margin are in sync (i attached the output PDF). The problems i observed are : 1) I could just increase the space between columns. But text font still remain unreadable. How text was appearing before having this new code , same way text is appearing now. You can see in the attached pdf. We have to increase text font here. 2) I thought with the fix of text font ,we resolved the issue . But i just changed the input html to another huge html file comparitively. Problem still persists. Here content is not expanding. I see what ever fix we made is for 1st file. again if i change the numbers it starts expanding. Dont know what i should do with this behaviour of code. In one line , we might needed a code which should 1) expand the content to right , i mean left margins should be in sync 2) text font should be little visible 3)code should behave same for any input file irrespective of content.

            #28593

            The document layout looks like a big table with width=100%, whose cells contain smaller content tables with fixed widths.

            In the case increasing of htmlWidth (it is an analog of browser frame width) just increases gaps between the content tables and has almost no impact to the document height.

            If the nested content tables had width given in percents, at some values of htmlWidth currently multiline content cells could have only a single line of text (which would efficiently reduce the document height and would help to achieve the needed aspect ratio at bigger zoom factors).

            You could just play with the document layout in a web browser – just load the doc and resize the browser frame width. With current layout even if you stretch the frame very wide, the document height will reduce insignificantly. For a better visualization I would recommend to temporarily set border=1 for all tables.

            If you want, for the test you may use PD4ML in GUI mode:
            java -Xmx512m -jar pd4ml.jar

            Tom
              #28594

              I could understand your explanation to some extent. But here the problem is input HTML files come from 3rd party. We dont generate them . Our job is to get the pdf out of that HTML file. What should i do now?.

              #28595

              Well, let’s imagine you need to convert the current discussion thread to a single page PDF. The only chance to put the content “as is” to a single page is to scale it down to almost invisible sizes of fonts. (That is what pd4ml.fitPageVertically() would do). And it is normal – the thread has already too much content for a single page.

              An interactive solution for the “problem” – browser scrollbars. But PDF is paper-output-oriented format. Paper has no scrollbars -> there is no generic solution for the issue – there are content amounts simply do not fit a page.

              So I would recommend to consider multi-page PDF output if it is acceptable by your work requirements.

              If not, you could try to impact the third-party document layout with external CSS style (pd4ml.addStyle()). The goal is to let the content flow horizontally. The solution will work only if the expected input documents has similar structure and their volume only slightly differs from one doc to another.

              Tom
                #28596

                K. I dont think client would accept having multi page pdf output. They need it as Ledger (11/17).

                Also you suggested one solution by adding style to documents with a constraint ,they slightly differ. Actually what ever htmls come, those are reports of their clients. So obviously as there will be huge difference between one report and another report. We cant count on that.

                But as you suggested we shall try to add style while building pdf. So is addStyle method takes care of font and all ?. if not please let me how to use that for my reports.

              Viewing 12 posts - 1 through 12 (of 12 total)

              The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.