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 Jun 30, 2020 3:30 am

Hi Team
I am using below code for convert html pdf.
I have attached my sample html and output PDF getting blank pages, page_break and format not expected, Can you please check my attached file and help.
Here is my code.

myModel = myModel.Replace("cdk-global-scrollblock ratna", "#");
MemoryStream pdfstream = new MemoryStream();
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(myModel,
pdfstream,
//enable javascript`
true,
//load timeout
100 * 1000,
//page size
PdfPageSize.A4,
//new SizeF(1920, 1080),

//page margins
new Spire.Pdf.Graphics.PdfMargins(0,20),
//load from content type
LoadHtmlType.SourceCode
);

pdfstream.Position = 0;
FileStreamResult filestreamResult = new FileStreamResult(pdfstream, "application/pdf");
filestreamResult.FileDownloadName = "Madhutest.pdf";
return filestreamResult;
}


Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Tue Jun 30, 2020 8:15 am

Hello,

Thanks for your inquiry.
Regarding the blank page issue, I used the latest x64 plugin to convert your file, but the generated PDF has no extra blank pages. Attached is my output file, please check. If you are not using the latest plugin, please download it and try again.
Direct download link for the latest x64 plugin: http://www.e-iceblue.com/downloads/plug ... ws-x64.zip

As for the page break and format issues you mentioned, in fact, our plugin conversion method is based on the Qt plugin of the Chrome kernel. And I used Chrome to directly convert the your HTML file to PDF and also got a similar result, as shown below. Hope you can understand.
Save_as_PDF.png

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Tue Jun 30, 2020 2:05 pm

Hi Rachel,
Thanks for ur update.
After replace with new plugin still getting blank-pages.
Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Wed Jul 01, 2020 2:18 am

Hello,

Thanks for your feedback.
The following is my test project, please run it directly on your side. If the issue still occurs, please provide your OS information (E.g. Windows 7, 64 bit) and region setting (E.g. China, Chinese) for further investigation.
http://www.e-iceblue.com/downloads/demo/22044Demo.zip

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Wed Jul 08, 2020 4:42 am

Hi Rachel.
Hope you are doing great.
Thanks for r support.
I need to add time stamp and page number every page top and my test html show up 3 records a row in browser but pdf conversion got one record per one row.
Can you please check attached sample files and help me on this issue.
Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Wed Jul 08, 2020 9:58 am

Hello,

Thanks for your post.
Regarding adding time stamp and page number to PDF, the following is the code for your reference. If this is not what you want, please provide your desired output for our reference.
Code: Select all
        public static void AddTimeStamp(PdfDocument doc)
        {
            //Get the first page
            foreach(PdfPageBase page in doc.Pages){
                PdfTemplate template = new PdfTemplate(125, 20);
                PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Elephant", 10f, FontStyle.Italic), true);
                PdfSolidBrush brush = new PdfSolidBrush(Color.DarkRed);
                PdfPen pen = new PdfPen(brush);
                RectangleF rectangle = new RectangleF(new PointF(500, 5), template.Size);

                //Draw stamp text
                String timeString = DateTime.Now.ToString("MM/dd/yy hh:mm:ss tt ");
                PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Lucida Sans Unicode", 9f, FontStyle.Bold), true);
                template.Graphics.DrawString(timeString, font2, brush, new PointF(2, 5));

                //Create a rubber stamp
                PdfRubberStampAnnotation stamp = new PdfRubberStampAnnotation(rectangle);
                PdfAppearance apprearance = new PdfAppearance(stamp);
                apprearance.Normal = template;
                stamp.Appearance = apprearance;

                //Draw stamp into page
                page.AnnotationsWidget.Add(stamp);
            }
        }

        public static void AddPageNumber(PdfDocument doc)
        {
            PdfMargins margin = doc.PageSettings.Margins;
            foreach (PdfPageBase page in doc.Pages)
            {
                page.Canvas.SetTransparency(0.5f);
                PdfBrush brush = PdfBrushes.Black;
                PdfPen pen = new PdfPen(brush, 0.75f);
                PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Italic), true);
                PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
                format.MeasureTrailingSpaces = true;
                float space = font.Height * 0.75f;
                float x = margin.Left;
                float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
                float y = margin.Top - space;
                page.Canvas.DrawLine(pen, x, y, x + width, y);
                y = y - font.Height;
                //Draw page number
                String numberLabel = String.Format("{0} of {1}", 1, doc.Pages.Count);
                page.Canvas.DrawString(numberLabel, font, brush, x + width, y, format);
                page.Canvas.SetTransparency(1);
            }
        }


As for your another question, yes, your html file shows up 3 records in a row in the browser, but when using Chrome to directly convert the your HTML file to PDF, you can see there is only one record in a row, as shown below. Our plugin conversion method is based on the Qt plugin of the Chrome kernel, thus, using our product you will get a similar result. Hope you can understand.
screenshot.png

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Wed Jul 08, 2020 1:28 pm

Hi Rachel,
Thanks for ur replay,
Where can I integrate addtimestamo and pagenumber functions with in my code? Please help on this.


public FileStreamResult Htmltopdf(string myModel)
{
try
{

myModel = myModel.Replace("cdk-global-scrollblock ratna", "#");
MemoryStream pdfstream = new MemoryStream();
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(myModel,
pdfstream,
//enable javascript`
true,
//load timeout
100 * 1000,
//page size
PdfPageSize.A4,
//page margins
new Spire.Pdf.Graphics.PdfMargins(20,40),
//load from content type
LoadHtmlType.SourceCode
);

pdfstream.Position = 0;
FileStreamResult filestreamResult = new FileStreamResult(pdfstream, "application/octet-stream");
return filestreamResult;

}
catch (Exception ex)
{
throw;
}

}


Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Wed Jul 08, 2020 10:49 pm

Hi Rachel,
Please check attached files some overlapping with page break, Please advise how to fix overlapping issue?
I am using latest pluging what you provided.
Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Thu Jul 09, 2020 8:09 am

Hello,

Thanks for your inquiry.
Regarding your first issue, please refer to the following code snippet to invoke the two functions.
Code: Select all
            //...
            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(myModel,
            pdfstream,
                //enable javascript`
            true,
                //load timeout
            100 * 1000,
                //page size
            PdfPageSize.A4,
                //page margins
            new Spire.Pdf.Graphics.PdfMargins(20, 40),
                //load from content type
            LoadHtmlType.SourceCode
            );

            PdfDocument doc = new PdfDocument();
            doc.LoadFromStream(pdfstream);
            AddTimeStamp(doc);
            AddPageNumber(doc);
            doc.SaveToStream(pdfstream);

            pdfstream.Position = 0;
            //...

As for the overlapping issue, I did notice that the some text overlapped. But I found that if you set the page margins to 0, the effect will be much better. Anyway, I will pass this issue to our Dev team for further investigation. If there is any update, we will let you know. Sorry for the inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Mon Jul 13, 2020 4:52 pm

Hi Rachel,
Hope are doing great.
Some of the car images are showing blank within the print functionality on edge, do we know why and how to correct?

Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Mon Jul 13, 2020 8:41 pm

Hi Rachel,
I am trying to convert html to pdf and preview with "ngx-extended-pdf-viewer" working expected chrome and IE but some images missing with edge browser.
Please check attached image and let me know need any plugin to solve this issue.

Thanks
Madhu

myarra1228
 
Posts: 8
Joined: Mon Jun 29, 2020 2:59 am

Tue Jul 14, 2020 5:47 am

Hi Madhu,

Thanks for your post.
You mean you used edge browser to convert your html file to PDF, but some car images weren't displayed correctly, right? Sorry this is not within the scope of our product features. This issue may be caused by your html file not fully loaded.
Besides, I have verified that using our plugin method to convert your html file to PDF, all the car images can be displayed correctly. If you have any other questions related to our product, please feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Return to Spire.PDF