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.

Tue Feb 04, 2020 8:56 pm

Hi,

When I want make a new doc and Insert HTML Styled Text to PDF in C#, I have evrytime a blank page in the document.
I see, in your exemple, you have 2 page too.

Why there are 1 page more in the doc ? I can not remove this page and I can not write it.

vilau_claudiu
 
Posts: 5
Joined: Tue Feb 04, 2020 6:10 pm

Wed Feb 05, 2020 2:33 am

Hello,

Thanks for your inquiry.
After investigation, we found that this is because the automatic pagination is set in the page layout, and the Rectangle set in the code is too large and exceeds one page. Thus, it caused a blank page. You could reduce the height of the Rectangle to remove the blank page, like the below code. Any question, just feel free to contact us.
Code: Select all
    //......
    //Draw htmlString
    //Change "page.GetClientSize().Height" to "page.GetClientSize().Height/2"
    richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height/2), format);
    //......


Sincerely,
Rachel
E-iceblue support team
User avatar

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

Tue Feb 11, 2020 8:43 am

Hello,

Greetings from E-iceblue!
Has your issue been resolved? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Sat Feb 22, 2020 10:39 pm

Hi,
Thank you for your answer but it's not woking.
If a make this I have 1 page more and the text justify no more woking...

vilau_claudiu
 
Posts: 5
Joined: Tue Feb 04, 2020 6:10 pm

Mon Feb 24, 2020 1:36 am

Hello,

Thanks for your feedback and sorry for the late reply as weekends.
To help us investigate your issue more accurately, please provide your full code, your output file as well as your desired output for reference. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Mon Mar 02, 2020 9:53 am

Hello,

Hope you are doing well.
How is your issue now? Could you please provide further information to help us investigate it?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Tue Mar 10, 2020 2:19 pm

Hi,
Please find here my code:

protected void crea_pdf(object sender, EventArgs e)
{
// Initiate an object of Spire.PdfDocument
PdfDocument newDoc = new PdfDocument();

PdfNewPage page1 = newDoc.Pages.Add() as PdfNewPage;
PdfNewPage page2 = newDoc.Pages.Add() as PdfNewPage;
PdfNewPage page3 = newDoc.Pages.Add() as PdfNewPage;
PdfNewPage page4 = newDoc.Pages.Add() as PdfNewPage;

//newDoc.Pages.RemoveAt(0);
// Add a new page in this newly created pdf file



PdfImage image = PdfImage.FromFile(this.Server.MapPath("/images_hh/logo.jpg"));
/*float width = image.Width * 0.4f;
float height = image.Height * 0.4f;
float x = (page.Canvas.ClientSize.Width - width) / 2;
page.Canvas.DrawImage(image, x, 60, width, height);*/
page1.Canvas.DrawImage(image, 0, 0, 55, 70);

PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Layout = PdfLayoutType.Paginate;
format.Break = PdfLayoutBreakType.FitPage;
PdfFont font_titre = new PdfFont(PdfFontFamily.TimesRoman, 16f);
PdfFont font_pdf = new PdfFont(PdfFontFamily.TimesRoman, 12f);
PdfBrush brush = PdfBrushes.Black;

string html_text = "<b>" + p1.InnerText + "</b>";
PdfHTMLTextElement htmltext = new PdfHTMLTextElement(html_text, font_titre, brush);
htmltext.TextAlign = Spire.Pdf.Graphics.TextAlign.Left;
htmltext.Draw(page1, new RectangleF(100, 20, page1.GetClientSize().Width, page1.GetClientSize().Height), format);

string html_text1 = p2.InnerText + "<br/><br/>" + p3.InnerText + "<br/>" + p4.InnerText + "<br/>" + p5.InnerText +
"<br/>" + p6.InnerText + "<br/>" + p8.InnerText + "<br/>" + p9.InnerText +
"<br/><br/>" + p10.InnerText + "<br/><br/>" + p11.InnerText + "<br/><br/>" + p12.InnerText + "<br/><br/>" +
"<b>" + p_prenom_nom.InnerText + "</b><br/>" + p_adresse.InnerText + "<br/>" + p_adresse_endroit.InnerText + "<br/>" + p_email_tel.InnerText +
"<br/><br/>" + p13.InnerText +
"<br/><br/>" + p14.InnerText + "<br/><br/>" + p15.InnerText + "<br/><br/>" + p16.InnerText + "<br/><br/>" + p17.InnerText +
"<br/>" + p18.InnerText + "<br/>" + p19.InnerText + "<br/><br/>" + p20.InnerText + "<br/><br/>" + p21.InnerText +
"<br/>" + p22.InnerText + "<br/>" + p23.InnerText;

PdfHTMLTextElement htmltext1 = new PdfHTMLTextElement(html_text1, font_pdf, brush);
htmltext1.TextAlign = Spire.Pdf.Graphics.TextAlign.Justify;
htmltext1.Draw(page1, new RectangleF(0, 80, page1.GetClientSize().Width, page1.GetClientSize().Height), format);

string html_text2 = p24.InnerText + "<br/><br/>" + "Le Bailleur loue au Preneur le logement du " +
"<b>" + Label_date_du.Text + "</b>" + Label_au.Text + "<b>" + Label_date_au.Text + "</b>" + Label_text_contrat1.Text +
"<b>" + Label_nb_nuits.Text + "</b>" + Label_text_contrat2.Text + "<b>" + Label_date_fin.Text + "</b>" + Label4.Text +
p26.InnerText + "<br/><br/>" + p27.InnerText + "<br/><br/>" + "Les Parties ont convenu de fixer le montant (taxe de séjour incluse) de la location à " +
"<b>" + Label_text_prix.Text + "</b>" + Label_text_contrat3.Text + "<br/>" + p29.InnerText + "<br/>" + p30.InnerText +
"<br/>" + p31.InnerText + "<br/>" + p32.InnerText + "<br/>" + p33.InnerText + "<br/>" + p34.InnerText +
"<br/>" + p35.InnerText + "<br/>" + p36.InnerText + "<br/>" + p37.InnerText + "<br/><br/>" + p38.InnerText +
"<br/><br/>" + "Afin de procéder à la réservation du logement, le Preneur retourne le présent contrat paraphé à chaque page et signé, et le règlement de l'acompte d'un montant de " +
"<b>" + (decimal.Parse(Label_text_acompte.Text)) + Label_text_contrat3_9.Text + "</b>" + Label_text_contrat4.Text +
"<br/>" + p42.InnerText + "<br/><br/>" + p43.InnerText +
"<br/><br/>" + "Le montant de la location indiqué au paragraphe 4, soit " + "<b>" + Label_text_prix2.Text + "</b>" + Label_text_contrat5.Text +
"<br/><br/>" + p45.InnerText + "<br/><br/>" + p46.InnerText;

PdfHTMLTextElement htmltext2 = new PdfHTMLTextElement(html_text2, font_pdf, brush);
htmltext2.TextAlign = Spire.Pdf.Graphics.TextAlign.Justify;
htmltext2.Draw(page2, new RectangleF(0, 20, page2.GetClientSize().Width, page2.GetClientSize().Height), format);


string html_text3 = p47.InnerText + "<br/>" + p48.InnerText +
"<br/><br/>" + p49.InnerText + "<br/><br/>" + p50.InnerText + "<br/>" + p51.InnerText + "<br/><br/>" + p52.InnerText +
"<br/><br/>" + p53.InnerText + "<br/>" + p54.InnerText + "<br/>" + p55.InnerText + "<br/>" + p56.InnerText +
"<br/><br/>" + p57.InnerText + "<br/><br/>" + p58.InnerText + "<br/><br/>" + p59.InnerText + "<br/><br/>" + p60.InnerText +
"<br/>" + p61.InnerText + "<br/>" + p62.InnerText;

PdfHTMLTextElement htmltext3 = new PdfHTMLTextElement(html_text3, font_pdf, brush);
htmltext3.TextAlign = Spire.Pdf.Graphics.TextAlign.Justify;
htmltext3.Draw(page3, new RectangleF(0, 20, page3.GetClientSize().Width, page3.GetClientSize().Height), format);


string html_text4 = p63.InnerText + "<br/>" + p64.InnerText +
"<br/>" + p65.InnerText + "<br/>" + p66.InnerText + "<br/><br/>" + p67.InnerText + "<br/><br/>" + p68.InnerText +
"<br/><br/>" + p69.InnerText + "<br/><br/>" + p70.InnerText + "<br/><br/><br/>" + p71.InnerText + "<br/>" + p72.InnerText +
"<br/><br/>" + p73.InnerText + "<br/><br/><br/><br/>" + p74.InnerText + "<br/>" + p75.InnerText + "<br/><br/>" + p76.InnerText;

PdfHTMLTextElement htmltext4 = new PdfHTMLTextElement(html_text4, font_pdf, brush);
htmltext4.TextAlign = Spire.Pdf.Graphics.TextAlign.Justify;
htmltext4.Draw(page4, new RectangleF(0, 20, page4.GetClientSize().Width, page4.GetClientSize().Height), format);

//To open this pdf document in client browser.
newDoc.SaveToHttpResponse("contrat Home Holiday " + p_prenom_nom.InnerText + ".pdf", HttpContext.Current.Response, HttpReadType.Open);
}

vilau_claudiu
 
Posts: 5
Joined: Tue Feb 04, 2020 6:10 pm

Wed Mar 11, 2020 2:56 am

Hello,

Thanks for your sharing.
Do you want to draw html text to only one page? If so, you could set the layout property to "PdfLayoutType.OnePage" so that elements will only be drawn on one page, as shown in the following code.
Code: Select all
    //......
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Change "Paginate" to "OnePage"
    //format.Layout = PdfLayoutType.Paginate;
    format.Layout = PdfLayoutType.OnePage;
    format.Break = PdfLayoutBreakType.FitPage;
    //......

If this is not what you want, please provide your output file, your desired output, your complete HTML text (including html_text, html_text1, html_text2, html_text3 and html_text4) or a runnable sample project to help us further investigate it. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Fri Mar 13, 2020 11:58 am

Hi,
No, I want make this on 4 pages but I have 5 pages.
I said on the first message, in your example in your picture PDF is 1/2. You make an example why we make 1 page to pdf and it is noted 1/2. I think 1 page blank more.

Thank you

vilau_claudiu
 
Posts: 5
Joined: Tue Feb 04, 2020 6:10 pm

Mon Mar 16, 2020 7:08 am

Hello,

Thanks for your response.
When the layout property is set to "PdfLayoutType.Paginate", it will automatically paginate according to the height of the drawn element.
For example, in the following code, the height of richTextElement is equal to the height of the PDF page plus its starting height position (0, 20). This exceeds the height of one page, thus, the extra part will be drawn on the next page.
Code: Select all
 richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format);

For your case, I suggest you set the layout property to "PdfLayoutType.OnePage" , so that the element will be drawn only on one page. Here I uploaded my testing project for your reference, please directly run it on your side.
http://www.e-iceblue.com/downloads/demo/Demo20434.zip

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Fri Mar 20, 2020 7:38 pm

Hi,
Thank you very much
It's working.
I changed Paginate with OnePage

Thank you

vilau_claudiu
 
Posts: 5
Joined: Tue Feb 04, 2020 6:10 pm

Mon Mar 23, 2020 1:39 am

Hello,

Glad to hear that!
If you encounter any question related to our product, please 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

Return to Spire.PDF

cron