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 Dec 07, 2022 5:53 am

Hi,
I have a word document with margins setup as needed.
On creation of PDF the left margin increases.
The entire content moves right by few points.
As in the image, evaluation warning is the start of left margin, the content is not aligned at center along with page number.
Here is the code,
Code: Select all
{
            //Create a pdf document.
            PdfPageBase page1 = docToPdf.Pages[0];

            PdfDocument pdfDoc = new PdfDocument();

            PdfMargins defaultMargins = new PdfMargins(0, 0, 0, 40);

            PdfPageBase firstPage = pdfDoc.Pages.Add(PdfPageSize.A4, defaultMargins);

            firstPage.Canvas.DrawTemplate(page1.CreateTemplate(), new PointF(0, 0));
           
            return pdfDoc;
        }


The docToPdf is a PdfDocument, it has same margins as the word doc.
On creation of "firstPage" using Canvas, the result is as shown in the image.
Please let me know where the issue is.

suryaks2002
 
Posts: 17
Joined: Wed Nov 09, 2022 7:57 am

Wed Dec 07, 2022 9:57 am

Hello,

Thanks for your inquiry.
I simulated a word file and create console project with .Net frameword 4.8 and the latest version of Spire.Office (Spire.Office 7.12.0) to test your scenario, but I didn’t reproduce your issue. I put my test code below and attached the input Word file and output Pdf file for your reference. If you don’t use the latest version of Spire.Office, please update to it and have a test. If the issue still exists, please offer the following message. Thanks for your assistance in advance.

1) Your input file (if any), if you want that other people can’t view your file, you can send it to us via email ([email protected]).
2) Your key code that can reproduce your issue.
3) Application type, such as Console App, .NET Framework 4.8.
4) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Code: Select all
  Document doc = new Document();
            doc.LoadFromFile(@"../../data/TableSample.docx");

            doc.SaveToFile(@"../../output/TableSample.pdf", Spire.Doc.FileFormat.PDF);

            PdfDocument docToPdf = new PdfDocument();
            docToPdf.LoadFromFile(@"../../output/TableSample.pdf");

            //Create a pdf document.
            PdfPageBase page1 = docToPdf.Pages[0];

            PdfDocument pdfDoc = new PdfDocument();

            PdfMargins defaultMargins = new PdfMargins(0, 0, 0, 40);

            PdfPageBase firstPage = pdfDoc.Pages.Add(PdfPageSize.A4, defaultMargins);

            firstPage.Canvas.DrawTemplate(page1.CreateTemplate(), new PointF(0, 0));

            pdfDoc.SaveToFile(@"../../output/result.pdf", Spire.Pdf.FileFormat.PDF);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Wed Dec 28, 2022 3:59 am

Hello,

Greeting from E-iceblue.
Has your issue been solved? Could you give some feedback at your convenience.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF