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.

Wed Jul 16, 2014 10:14 am

Hello,

When i convert a page with css style for page break inside my page that i want it to be converted not doing page breaking into two pages.

Code: Select all

<html>
<head>
    <title>page with breaks</title>
    <style type="text/css">
        .page-break   { display: block; page-break-before: always; }
    </style>
</head>
<body>
    <div> some content here </div>

    <div class="page-break"></div>

    <div> some content here </div>
</body>
</html>


in C# code
Code: Select all
String url = "http://localhost/mypage.html";
            var doc = new PdfDocument();

            var thread = new Thread(() => doc.LoadFromHTML(url, true, true, true));

            thread.SetApartmentState(ApartmentState.STA);

            thread.Start();

            thread.Join();

            var fileStream = new MemoryStream();

            doc.SaveToStream(fileStream);


how to solve this.

aalsaadi
 
Posts: 1
Joined: Tue Jul 15, 2014 12:41 pm

Thu Jul 17, 2014 6:20 am

Hello,

Sorry that currently our Spire.Pdf product doesn't support the page break in html to pdf conversion. But our Spire.Doc Pro Editioncan support, you can download and test the following C# code and Html code we provide as there is some bugs for your html code, we have posted the bug to our Dev team, once there are any update, we will let you know immediately.
Code: Select all
String url = "http://localhost/mypage.html";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
System.IO.Stream webStream = response.GetResponseStream();
TextReader textReader = new StreamReader(webStream);
Document doc = new Document();
doc.LoadHTML(textReader, Spire.Doc.Documents.XHTMLValidationType.None);
doc.SaveToFile("SpireTest.pdf",FileFormat.PDF);

Code: Select all
<html>
<head>
<title>page with breaks</title>
<style>.break { page-break-before: always; }
</style>
</head>
<body>
content on page 1...
<h1 class='break'>
text of Heading 1 on page 2
</h1>
content on page 2...
<h1 class='break'>
text of Heading 1 on page 3
</h1>
content on page 3...
<p class='break'>
content on top of page 4
</p>
content on page 4...
</body>
</html>

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Aug 28, 2014 2:26 am

Hello,

Now our Spire.Doc can support pagebreak in div, but there is content in the div.
The newest hotfix has been released, you could download the Spire.Doc Pack(hot fix) Version:5.2.29 and try it.
Code: Select all
String url = "http://localhost/mypage.html";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
System.IO.Stream webStream = response.GetResponseStream();
TextReader textReader = new StreamReader(webStream);
Document doc = new Document();
doc.LoadHTML(textReader, Spire.Doc.Documents.XHTMLValidationType.None);
doc.SaveToFile("SpireTest.pdf",FileFormat.PDF);

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Mar 06, 2015 7:50 pm

Gary.zhang wrote:Hello,

Sorry that currently our Spire.Pdf product doesn't support the page break in html to pdf conversion. But our Spire.Doc Pro Editioncan support, you can download and test the following C# code and Html code we provide as there is some bugs for your html code, we have posted the bug to our Dev team, once there are any update, we will let you know immediately.

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team


Is this still the case, or do we still need to purchase spire.doc?

patness
 
Posts: 10
Joined: Tue Jul 08, 2014 12:15 am

Mon Mar 09, 2015 7:42 am

Hello,

The solution supports the feature, you can try it.
http://www.e-iceblue.com/Tutorials/Spir ... lugin.html

Best wishes,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Sat Jul 11, 2015 1:10 am

So Does this new Plugin supports adding page breaks? Please confirm. Is there any sample code to add page breaks as well as a header on each page?

We evaluated Spire.Doc Pro to generate PDF. Although it lets us create page breaks, there are a number of formatting issues when converting to PDF as certain css elements fail to work.

With Spire.PDF there are no such issues and all the css elements are working fine. But now we lost the ability to add page breaks and a custom header on each page.

Please advise if it is possible to do with this new plugin for Spire.PDF.

akhan2003
 
Posts: 11
Joined: Tue Sep 09, 2014 6:47 pm

Mon Jul 13, 2015 7:18 am

Hello,

Thanks for your inquiry. Sorry for late reply as weekend. Sorry that Spire.Pdf doesn't support adding page breaks to existing Pdf document. And you can use the following the method to add the custom header on every page of exiting Pdf.
Code: Select all
  public void AddHeader()
    {
        PdfDocument doc = new PdfDocument();
        doc.PageSettings.Margins.All = 0;
        SetDocumentTemplate(doc, PdfPageSize.A4, 40);
        PdfDocument original = new PdfDocument();
        original.LoadFromFile("existing.pdf");
        PdfPageBase page = null;
        foreach (PdfPageBase origianlPage in original.Pages)
        {
            page = doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height + 40));
            origianlPage.CreateTemplate().Draw(page, 0, 0);
        }
        doc.SaveToFile( "AddHeader.pdf");
        System.Diagnostics.Process.Start( "AddHeader.pdf");

    }
    private void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, float height)
    {
        PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, height);
        topSpace.Foreground = true;
        doc.Template.Top = topSpace;
        PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 20f));
        String label = "This is header for test";
        SizeF size1 = font1.MeasureString(label);
        float x = 0;
        float y = 0;
        topSpace.Graphics.DrawString(label, font1, PdfBrushes.PaleVioletRed, x, y);
    }

Please contact us if you have any queries.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Jul 15, 2015 8:26 am

Hello,

Have you tried the method to add header for every page? Can it achieve your requirement?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.PDF