Hello !
I am trying to create a PDF file in my Blazor Webassembly app using Syncfusion.PDF.Net.Core.
I am using the documentation from the following links:
https://help.syncfusion.com/file-formats/pdf/create-pdf-document-in-blazor
https://help.syncfusion.com/file-formats/pdf/working-with-text
|
We can able to set the custom size to PDF page using the below code example,
|
|
|
We do support only for creating PDF document and we are not aware of label printers. So currently we do not have support to set the height of the PDF page to be continuous for label printers. Note: We can able to manually set the height of the PDF page by using below code example,
|
|
|
To obtain the position of the last text, you can utilize the PdfLayoutResult class.
API link: Class PdfLayoutResult (syncfusion.com) UG documentation link: https://help.syncfusion.com/file-formats/pdf/working-with-text#creating-a-multicolumn-pdf-document
Please refer the below code example for your reference,
KB documentation for Paginate text in PDF document: https://support.syncfusion.com/kb/article/8190/how-to-paginate-the-text-in-a-pdf-using-c-and-vb-net |
|
|
Please refer the below code example to insert base64 image to PDF document.
|
Please let us know if you need any further assistance.
Thank you for your answer !
I wand to use Syncfusion.PDF.Net.Core to generate a continuous receipt or a continuous label, that's why a setting to define a
continuous page is required...
I have at least two more questions for you :
| I wand to use Syncfusion.PDF.Net.Core to generate a continuous receipt or a continuous label, that's why a setting to define a continuous page is required... | As we have already said, We do support only for creating PDF document and we are not aware of label printers. So currently we do not have support to set the height of the PDF page to be continuous for label printers. | |
| How can I resize the loaded base64 image to a smaller size ? I need to draw a smaller image into PDF file | We suggest defining bounds while drawing the image to the PDF document. Please refer to the modified code snippet below:
| |
| Please tell me how can I send directly to a specified printer the new downloaded PDF file, when I click the export PDF file button ? I want to automatically print the new generated PDF file to a specified printer. | As of now, we do not have support for printing the PDF document by using the Syncfusion PDF Library. But we can achieve this by using a system library. Kindly try the following code snippet to print an existing PDF via Microsoft Print to PDF and let us know the result:
|
Thank you very much for all your help !
Best Regards !
Hello again !
Please be kind and tell me how to center the title horizontally on the page !
PdfTextElement title = new PdfTextElement("THIS IS MY TITLE", pdfFont, PdfBrushes.Black);
PdfLayoutResult result = title.Draw(page, new Syncfusion.Drawing.PointF(0, 0));
Thank you very much and
Best Regards !
The TextAlignment API is used to set the alignment for the text to be drawn in the PDF document. This API will help to align the text to the center and we need to change the pointer to the middle of the page while drawing the text. we have attached the modified code for your reference. Please check this on your end and let us know the result.
Modified code :
PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; PdfTextElement title = new PdfTextElement("THIS IS MY TITLE", pdfFont,null, PdfBrushes.Black, format); PdfLayoutResult result = title.Draw(page, new Syncfusion.Drawing.PointF(page.GetClientSize().Width/2,0)); |
Follow the below links for more information,
https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Graphics.PdfTextAlignment.html
Hello again !
With your help I managed to create a simple PDF file.
Please tell me how to resize the page height after rendering it !
I am using a thermal printer to make some kind of a continuous ticket (like a cash register long ticket) and I want to print my PDF generated file to that printer.
//Create a PDF document.
PdfDocument pdfDocument = new PdfDocument();
//Set the page height.
pdfDocument.PageSettings.Width = 215;
pdfDocument.PageSettings.Height = 5000;
//Set page margins
pdfDocument.PageSettings.Margins.All = 5;
//Add Page to the PDF document.
PdfPage page = pdfDocument.Pages.Add();
Here I fill my PDF page and after the last line is written, I can find out the Height of the entire page based on Syncfusion PdfLayoutResult class
//Draws the last paragraph.
layoutResult = new PdfTextElement(
var_last_text_paragraph, pdfFont).Draw(page, new Syncfusion.Drawing.RectangleF(0, layoutResult.Bounds.Bottom + 10, page.Size.Width, page.Size.Height));
Now I know the Height of yhe page is layoutResult.Bounds.Bottom and I want to resize the page Height to that value and I don't know how !
I tried to set the page Height again before saving it, but no success.
//Set the page height.
pdfDocument.PageSettings.Width = 215;
pdfDocument.PageSettings.Height = 2200;
Can you tell me how can I resize the page Height before saving it ?
I think I must add a new page with the NEW-HEIGHT into the PDF document, to copy all data from the first page into the second one and to remove the first page...
Can you help me, please ?
It is the default behavior, Page orientation, and size should be set before adding a page to the PDF document we cannot alter the size and orientation of the page after that.
We suggest you create a PDF document that sizes lesser than that of the input document the draw the template of the existing pdf document into a new document. We have followed the same on our end and it worked well. We will share here the code snippet and sample for your reference. Please try this on your end and let us know the result.
FileStream filestream = new FileStream("Input.pdf",FileMode.Open,FileAccess.ReadWrite); PdfLoadedDocument ldoc = new PdfLoadedDocument(filestream); PdfDocument doc = new PdfDocument(); PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage; doc.PageSettings.Size = new SizeF(300, 400); doc.PageSettings.Margins.All=0; PdfPage page = doc.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfTemplate template = lpage.CreateTemplate(); graphics.DrawPdfTemplate(template, new PointF(0,0), new SizeF(page.GetClientSize().Width,page.GetClientSize().Height)); MemoryStream input = new MemoryStream(); doc.Save(input); System.IO.File.WriteAllBytes("Output.pdf",input.ToArray()); |
It is working fine now !
I managed to change the page height !
THANK YOU VERY MUCH FOR ALL YOUR HELP
and Best Regards !