@M.Heinz
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-26466
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Does this fix also require the August updates for Apsose.PDF and/or Aspose.BarCode? Because just the Aspose.Words update does not seem to fix the issue at all.
P.S.: And the July updates for PDF and BarCode do not seem to suffice to make any changes.
Replacing the Aspose_Words_BarcodeGenerator class is the original code sample (posted on Jan 15th 2024) with the classes CustomBarcodeGenerator and CustomBarcodeGeneratorUtils does not resolve the issue.
As of today, I’m testing with the most recent versions of the Aspose product:
Aspose.Words 24.8
Aspose.PDF 24.8
Aspose.BarCode 24.7
Good behavior:
Reading and then saving the original docx file as a docx file using Aspose does not change the size or position of the generated QR-code; this was previously correct and still looks good to me. (You can compare the attached docx file dated 2024-08-19 with the one dated 2024-01-15 from the post on Jan 15th.)
Misbehavior:
The update you’ve provided does realign/move the QR-code within the resulting PDF file (i.e. the bottom right corner does seem to align with the bottom right corner position in the xlsx file), but the update does not size the QR-code properly; i.e. it still exceeds the bounding box marked in the original docx file. You can see this by comparing the resulting PDF file against the xlsx file and specifically by looking at the top left corner of each QR-code and their alignment with the markers drawn in blue.
The following attachments have been generated using the most current versions of Aspose and the latest version of the CustomBarcodeGenerator class:
Could you please double check on your end using the input file Word_with_DisplayBarcode.docx from the Jan 15th post and make sure, the resulting QR-code is bound by the blue markers?
However, we can’t change anything with the image size, at the moment it is slightly different. We will discuss this situation with the Aspose.BarCode team and get back to you with more information.
@amjad.sahi Could you please help us with the founded issues in BarcodeGenerator?
There are several problems:
If AutoSizeMode is not specified by default, then it’s impossible to specify the exact value of the “get.Parameters.Barcode.X Dimension.Pixels = 3.4f” - 3.4 will always be rounded down at the output to 3, and 3.5 will always be 4. How can I specify more accurate values so that by default the picture is displayed with the dimensions as in the MS Word?
If AutoSizeMode = AutoSizeMode.Nearest, then the generated image will differ in large margins. In the first case, when AutoSizeMode = AutoSizeMode.None you need to additionally specify paddings so that the picture gets into the user’s lines. In the case of AutoSizeMode = AutoSizeMode.Nearest does not need to specify them anymore.
Moreover, problem can also be fixed with IBarcodeGenerator architecture fix (add Resolution to result structure of public Image GetBarcodeImage(Aspose.Words.Fields.BarcodeParameters parameters)).
@amjad.sahi Thanks, the resolution setting helped with the first problem.
And the second case with the difference in indentation between AutoSizeMode.Nearest and AutoSizeMode.None - is this some problem in Aspose.BarCode or is this expected behavior?
@M.Heinz Please check the answers. CustomBarcodeGenerator provides you the basic idea of using Aspose.BarCode when converting .docx to .pdf. Due to some limitations, you can update the provided code and configure the barcode for your desired purpose. To get the same output as the .docx file, you can update the code as follows:
Main problem here is that Aspose.Words ignores the resolution of provided image and counts the resolution as 96 dpi, independently from real resolution.
@vyacheslav.deryushev Thanks for your answer. I’ll definitely try this approach, but I’m still curious, as to why both outputs would render different barcode sizes!
As you can imagine, I’m not simply trying to convert this one document from a docx file into a PDF (-> I could adjust the layout manually to fix any issues for a single document), but we’re using Aspose.Words in our software to provide customers the possibility to convert their documents from docx to PDF. And thus we don’t have any control over the initial docx files, that will be input to the algorithm and we would expect the size and position of the barcodes to always match between the docx and the resulting PDF file, such that the layout of the original docx and the resulting PDF file remains the same.
I can hardly imagine, setting the gen.Parameters.Resolutionto 103 and the top and left offset to 16px each would work for any possible barcode created with a BarCode-MergeField from MS Word.
Thus I’d like to be able to implement a general solution, which does not depend on the specifics of the MergeField and instead works as is for any provided `BarCode-MergeField.
Can you please take a stand on my suspicion, that the provided values (resolution 103 and offset 16,16) will only work in specific cases of QR-BarCode-MergeFields and evaluate a general solution to the issue at hand?
Yeah, as expected, this only works for QR codes version 3. I’ve added an other QR code version (simply by adding more text to the BarCode-MergeField) to the input docx file and - not surprisingly - your presets (especially the gen.Parameters.Resolution of 103) do not work anymore.
@M.Heinz I’m afraid there is no universal solution that covers all sizes of barcode images generated by MS Word fields. Aspose.Words inserts the barcode image provided by Aspose.BarCode as is. You can get acquainted with the described limitations and possible solutions on the next page:
I’ll create a new task to further investigate and improve the solution, but for now I don’t think there is a one-line code to save all barcode sizes as MS Word created them.
@M.Heinz
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-27314
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
You can probably understand, that the previous fix doesn’t cover our use-case, as the BarCode text is a user input and as such may vary in length and thus will the QR code version.
I’m fine with a static offset of 16x16 px from the top left - as long as this offset doesn’t vary depending on the QR code version. Although I don’t see any point in this offset not being applied automatically by Aspose itself, as this clearly aligns the QR code with the positioning used by MS Word.
Thanks again for your dedication and I’m looking forward to any improvements you can provide.