Free Support Forum - aspose.com

Absolute Positioned HTML Box And Formatting


#1

Hello Friends,

I am using a floatingbox to insert a fixed size and fixed positioned box. This box is intended to contain HTML with paragraph, bold, and, italic tags. However I am having some difficulties. (1) For some reason the I can not set a font type and size using the Text State. It crashes. (2) Also, how do I make any overflowed text hidden. Currently, the overflow text goes to a second page. (3) Furthermore, what are the limitations on what HTML I can insert?

public void InsertBlurb( Document doc )
{

    Page page = doc.Pages[1];
    FloatingBox box = new Aspose.Pdf.FloatingBox();
    box.ZIndex = 10;
    box.Top    = 71;
    box.Left   = 71;
    box.Height =  400;
    box.Width  = 600;
    box.BackgroundColor = Aspose.Pdf.Color.FromRgb( System.Drawing.Color.Green ); 
    box.Border = new BorderInfo(BorderSide.Box);     
    box.Margin = new MarginInfo(0,0,0,0);             

    blurb = "<p stle='font-size:9'>Hello 1 <i>Italic</i> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, joo asdf feda permu da quom.</p>" +
                "<p stle='font-size:10'>Hello 2 <b>Bold</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, </p>" +
                "<p stle='font-size:10'>Hello 2 <b>Bold</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, " + 
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " +
                "consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum" +
                " dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, " +
                "sunt in culpa qui officia deserunt mollit anim id est laborum.</p>";

         HtmlFragment frag = new HtmlFragment( blurb );  
         frag.TextState.Font = FontRepository.FindFont("Arial"); 
         frag.TextState.FontSize = 9;
         fragt.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb( System.Drawing.Color.White ); 
         
         box.Paragraphs.Add( frag );
         page.Paragraphs.Add(box);
    }

#2

@Toberville

Thank you for contacting support.

We have generated attached PDF document generated with below code snippet. The program does not crash anymore and overflowed text goes off the page thus invisible and not added to second page.

Moreover, we would like to inform you that CSS 2.1 is fully supported except aural properties (azimuth, volume, speech-rate, etc.) because they are not supported by our output formats (XPS, Images, PDF). Regarding to CSS3 support, as you know CSS3 specification is under construction and most chapters are far from at least stable state (https://www.w3.org/Style/CSS/current-work). However, we have implemented a lot of ‘candidate’ properties when they were requested by customers.

public void InsertBlurb(Document doc)
{
    Page page = doc.Pages[1];
    FloatingBox box = new Aspose.Pdf.FloatingBox();
    box.ZIndex = 10;
    box.Top = 71;
    box.Left = 71;
    box.Height = 400;
    box.Width = 600;
    box.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green);
    box.Border = new BorderInfo(BorderSide.Box);
    box.Margin = new MarginInfo(0, 0, 0, 0);

    var blurb = "<p stle='font-size:9'>Hello 1 <i>Italic</i> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, joo asdf feda permu da quom.</p>" +
                "<p stle='font-size:10'>Hello 2 <b>Bold</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, </p>" +
                "<p stle='font-size:10'>Hello 2 <b>Bold</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " +
                "consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum" +
                " dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, " +
                "sunt in culpa qui officia deserunt mollit anim id est laborum.</p>";

    HtmlFragment frag = new HtmlFragment(blurb);
    frag.TextState = new TextState();
    frag.TextState.Font = FontRepository.FindFont("Arial");
    frag.TextState.FontSize = 9;
    frag.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.White);

    box.Paragraphs.Add(frag);
    page.Paragraphs.Add(box);
}

HTMLfragment_19.5.pdf

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


#3

Thank You Farhan… You rock.

I will test out various HTML tags and view the results. This should be fun.


#4

@Toberville

We are honored by your kind feedback.

Please keep using our API and in event of any further query, feel free to ask.


#5

Hello Farhan,

Can you help me solve the Font color? The output is BLACK as in your attachment but the code reads:

frag.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.White);

I ran the same code snippet and can not set the font color with TextState.

Please provide review/feedback.


#6

@Toberville

Thanks for getting back to us.

We were able to notice that the TextState is not honoring Foreground color. We have logged an issue as PDFNET-46412 in our issue tracking system for the sake of correction. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

However, as a workaround, you may specify the color in style tag as under:

    var blurb = "<p style='font-size:9; color:white'>Hello 1 <i>Italic</i> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, joo asdf feda permu da quom.</p>" +
                "<p style='font-size:10; color:white'>Hello 2 <b>Bold</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, </p>" +
                "<p style='font-size:10; color:white'>Hello 2 <b>Bold</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " +
                "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " +
                "consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum" +
                " dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, " +
                "sunt in culpa qui officia deserunt mollit anim id est laborum.</p>";

We have also attached generated PDF file for your kind reference. WhiteBlurb_19.5.pdf


#7

Ok Farhan, I know you are doing your best effort. Thanks for the workaround.

Do you think I can surround my entire HTML fragment (called blurb) with a div statements so all paragraphs are white. For Example…


#8

@Toberville

You may modify it as per your requirements and then check the output displayed by a browser. Aspose.PDF for .NET API renders HTML to PDF exactly the way browser displays it. In case you notice any issue then feel free to contact us. We will be more than happy to assist you further.