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 May 11, 2021 4:32 pm

Hello,
In one of our applications, we are generating a pdf document by combining user input collected via DevExpress Rich Editor ( word like Editor)

Steps of Document generation process
1. Collect data from user for each Item as HTML via DevExpress Editor.
2. Store them in SQL Server database
3. Retrieve HTML from Database and generate separate documents for each Item.
4. Combine all the generated documents in to final document ( we are doing this as we have to add attachments in-between PDF pages)

The Problem.

Since user has the freedom to copy and paste content from anywhere, sometimes we come up with scenarios where users paste images that has a higher width compared to the document.
therefore when individual document is generated, sometimes we get pages that are slightly larger than usual width.
once we combine all individual pdf files, the section that contain the document with above mentioned issue becomes shrank ( about 70%)

This is the code we are using to save the HTML to individual PDF
Code: Select all
private void ConvertHtmlToPdf(string content, string outputFileName, string fileOutputPath, bool isCoverPage)
        {
         
            string input = string.Empty;

           
                PdfMargins margin = new PdfMargins();
                margin.Top = 70;
                margin.Bottom = 60;
                margin.Left = Convert.ToInt32(90);
                margin.Right = Convert.ToInt32(70);

             
                input = @"<div  style=""width: " + PageSize + @"px !important;"">" + content + @"</div>";


               
                    Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(input,
                                            outputFileName,
                                            true,
                                            10 * 1000,
                                            PdfPageSize.A4,
                                            margin,
                                            LoadHtmlType.SourceCode
                                            );
           
         
        }




This is the code we are using to merge individual pdf in to one PDF
Code: Select all
foreach (var item in combineFileList)
            {
                try
                {
                    if (item.Type.Equals("AgendaGroupItem"))
                    {
                        PdfDocument pdfDocument = new PdfDocument();
                        pdfDocument.LoadFromFile(outputFilePath + "AgendaGroupItem_" + item.PageName + ".pdf");
                        Doc.AppendPage(pdfDocument);
                    }
                    else if (item.Type.Equals("AttandaceReport"))
                    {
                        PdfDocument pdfDocument = new PdfDocument();
                        pdfDocument.LoadFromFile(outputFilePath + "Attandance.pdf");
                        Doc.AppendPage(pdfDocument);
                    }
                    else if (item.Type.Equals("AgendaGroup"))
                    {
                        PdfDocument pdfDocument = new PdfDocument();
                        pdfDocument.LoadFromFile(outputFilePath + "AgendaGroup_" + item.PageName + ".pdf");
                        Doc.AppendPage(pdfDocument);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Logger.Log(e);
                }
            }

            Doc.SaveToFile(outputPath);




Can you please help me to get this fixed and keep all pages with equal width

infra
 
Posts: 18
Joined: Tue Apr 03, 2018 12:05 pm

Wed May 12, 2021 7:42 am

Hello,

Thanks for your inquiry.

I tried to merge some PDF files with different page widths, but I did not encounter the page shrinking issue you mentioned. Could you please provide some PDF files to help us investigate further?

Besides, you can refer to the code below about keeping all pages of the same width.
Code: Select all
            PdfDocument Doc = new PdfDocument("Original.pdf");
            float width = Doc.Pages[0].Size.Width;
            float height = Doc.Pages[0].Size.Height;
            PdfMargins margins = Doc.PageSettings.Margins;

            PdfDocument pdfDocument = new PdfDocument();
            pdfDocument.LoadFromFile("append.pdf");
            PdfDocument newDoc = new PdfDocument();

            for (int i = 0; i < pdfDocument.Pages.Count; i++)
            {
                PdfPageBase page = pdfDocument.Pages[i];
                PdfPageBase newPage = newDoc.Pages.Add(new SizeF(width, height), margins);
                newPage.Canvas.DrawTemplate(page.CreateTemplate(), PointF.Empty);
            }
            Doc.AppendPage(newDoc);
            Doc.SaveToFile("final.pdf");


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed May 19, 2021 10:14 am

Hello,

Greetings from E-iceblue!
Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Jul 06, 2021 2:53 am

Hi
I was able to fix my problem using another approach

infra
 
Posts: 18
Joined: Tue Apr 03, 2018 12:05 pm

Tue Jul 06, 2021 3:58 am

Okay, I am glad to hear that you have found a solution.
If you encounter any issues related to our products in the future, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF