Problem with Mailing Label sizes when saving as pdf

I have this very simplistic code that takes a word document template and merges it with a data table to produce Avery labels. it works fine as a word document but when I save it as PDF which is required for my solution and print out, the columns are off, the differences are mostly in the horizontal regions. I have tried various fixes gathered from here but they had no effect(commented in my code below). All the fonts are Times New Roman except I do have a couple of fields that are barcode font “Libre Barcode 39 Font”. We are using Aspose.Words 23.4 and don’t have the kind of license that lets up update. Any thoughts on this? Here’s my code:

DataTable dataTable = GetDataTable(connectionString, query);
Document doc = new Document(@"c:\DocumentTemplates\LabelTemplate.dotx");

doc.MailMerge.Execute(dataTable);

//remove blank fields
doc.MailMerge.DeleteFields();

//got this from support forum had no effect
//foreach (Section sec in doc.Sections)
//{
//    PageSetup ps = sec.PageSetup;
// 1 inch equals 72 points
//    ps.TopMargin = .5 * 72;
//    ps.RightMargin = .19 * 72;
//    ps.BottomMargin = 0 * 72;
//    ps.LeftMargin = .19 * 72;
//}

// Execute the mail merge operation.
doc.Save(@"c:\temp\mailmergedoc.docx");
//these 2 suggestions didn't change anything
//PdfSaveOptions saveOptions = new PdfSaveOptions { AdditionalTextPositioning = true };
//doc.FirstSection.Body.Tables[0].AutoFit(AutoFitBehavior.AutoFitToWindow);
doc.Save(@"c:\temp\MailMerge.pdf");

@davidszona Could you please attach your output DOCX and PDF documents here for our reference? We will check the issue and provide you more information.

sure here you go…
MailMerge.docx (16.1 KB)

MailMerge.pdf (29.7 KB)

@davidszona The following fonts used in your document are not available on my side:

  • ‘Libre Barcode 39 Text’
  • ‘Aptos’

Could you please attach these fonts here for testing. Font substitution performed by Aspose.Words when fonts are not available might affect the document rendering. You can implement IWarningCallback to get notifications when font substitution is performed.

Desktop.zip (109.9 KB)

Here are the two fonts, I will look into the FontSubstitution and callback information thanks.

@davidszona Thank you for additional information. Unfortunately, I cannot see the differences between PDF produced by MS Word and Aspose.Words from your DOCX document:
Aspose.Words: out.pdf (29.8 KB)
MS Word: ms.pdf (83.6 KB)

Could you please highlight the problem in the PDF document?

The problem was very apparent when trying to print out onto the actual labels but after really zooming in on this I tracked down the real issue. Microsoft Edge was defaulting to “Fit to Printable Area” see screen shot. I learned this when I clicked on “More Settings” and then changed the option to print “Actual Size”. Since the document was already page size, Edge must by default include some margins that it was tacking on which was throwing everything off. Sorry about this false alarm but the matter is solved and it was never anything to do with Aspose. Thanks for your help.

@davidszona It is perfect that you managed to resolve the problem. Please feel free to ask in case of any issues we are always glad to help you.