I’m trying to convert a label WORD-template (single label) to a PDF-document which has a multiple pages layout (3 columns x 7 rows). The size of the WORD-template matches one cell in this grid.
After looking up the support documentation, I do find some info on how to print multiple pages to one sheet, but not how to do this while exporting to PDF.
https://docs.aspose.com/words/net/print-a-document-programmatically-or-using-dialogs/
Can anyone help me? Many thanks in advance.
I have a license for Aspose.Words, Aspose.Barcode & Aspose.Cells.
Development is in ASP.NET MVC
Hi Jan,
Thanks for your inquiry. Could you please attach your input Word document and expected PDF document here for testing? You can generate your expected PDF file using Microsoft Word. We will investigate the scenario further on our end and provide you more information.
Moreover, there is a similar example you can use to first render multiple pages to a single image file and then save that image file to Pdf:
Document doc = new Document(@"C:\Temp\TestFile.doc");
const int thumbColumns = 3;
// Calculate the required number of rows for thumbnails.
// We can now get the number of pages in the document.
int remainder;
int thumbRows = Math.DivRem(doc.PageCount, thumbColumns, out remainder);
if (remainder> 0)
thumbRows++;
// Lets say I want thumbnails to be of this zoom.
const float scale = 1.0 f;
// For simplicity lets pretend all pages in the document are of the same size,
// so we can use the size of the first page to calculate the size of the thumbnail.
Size thumbSize = doc.GetPageInfo(0).GetSizeInPixels(scale, 96);
// Calculate the size of the image that will contain all the thumbnails.
int imgWidth = thumbSize.Width * thumbColumns;
int imgHeight = thumbSize.Height * thumbRows;
using(Bitmap img = new Bitmap(imgWidth, imgHeight))
{
// The user has to provides a Graphics object to draw on.
// The Graphics object can be created from a bitmap, from a metafile, printer or window.
using(Graphics gr = Graphics.FromImage(img))
{
gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
// Fill the "paper" with white, otherwise it will be transparent.
gr.FillRectangle(new SolidBrush(Color.White), 0, 0, imgWidth, imgHeight);
for (int pageIndex = 0; pageIndex <doc.PageCount; pageIndex++)
{
int columnIdx;
int rowIdx = Math.DivRem(pageIndex, thumbColumns, out columnIdx);
// Specify where we want the thumbnail to appear.
float thumbLeft = columnIdx * thumbSize.Width;
float thumbTop = rowIdx * thumbSize.Height;
SizeF size = doc.RenderToScale(pageIndex, gr, thumbLeft, thumbTop, scale);
// Draw the page rectangle.
gr.DrawRectangle(Pens.Black, thumbLeft, thumbTop, size.Width, size.Height);
}
img.Save(@"C:\Temp\Rendering.Thumbnails Out.png");
}
}
// Create a new document
Document temp = new Document();
DocumentBuilder builder = new DocumentBuilder(temp);
// Insert image into it and save to Pdf
builder.InsertImage(@"C:\Temp\Rendering.Thumbnails Out.png");
temp.Save(@"C:\Temp\out.pdf");
I hope, this helps.
Best regards,