I am trying out the document processing library and the barcode formsource (https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/formsource/barcode).
When I add the barcode, I get a white pdf. If I leave barcode off it, everything else shows up. Any idea what i am doing wrong?
Example file:
internal class DocGenerator
{
public void CreateDocument()
{
var document = new RadFixedDocument();
var page = document.Pages.AddPage();
page.Size = new Size(595, 842); // A4 size
var editor = new FixedContentEditor(page);
//editor.Position.Translate(0, 0);
//FormSource barcode = FormSource.FromBarcode(Symbology1DType.Code128, "1234567890", width: 100, height: 100);
//editor.DrawForm(barcode, 100, 100);
editor.Position.Translate(20, 20);
// Title
editor.DrawText("P 24-07-2024 12:03");
editor.Position.Translate(300, 20);
editor.DrawText("Person X");
// Aisle and Pallet
editor.Position.Translate(20, 60);
editor.DrawText("AISLE");
editor.Position.Translate(100, 60);
editor.TextProperties.FontSize = 36;
editor.DrawText("A101");
editor.Position.Translate(20, 150);
editor.TextProperties.FontSize = 12;
editor.DrawText("P");
editor.Position.Translate(100, 150);
editor.TextProperties.FontSize = 36;
editor.DrawText("0237");
AddBarcode(editor);
editor.TextProperties.FontSize = 10;
var blackColor = new RgbColor(0, 0, 0);
Table table = new Table();
table.Borders = new TableBorders(
new Border(1, blackColor), // Top
new Border(1, blackColor), // Right
new Border(1, blackColor), // Bottom
new Border(1, blackColor) // Left
);
AddTableRows(table);
editor.Position.Translate(20, 240);
editor.DrawTable(table);
using (Stream output = File.OpenWrite(@"c:\temp\Output.pdf"))
{
PdfFormatProvider flowPdfProvider = new();
flowPdfProvider.Export(document, output, new TimeSpan(0,0,10));
}
}
private void AddBarcode(FixedContentEditor editor)
{
editor.Position.Translate(150, 150);
FormSource barcodeWithCenterCenterText = FormSource.FromBarcode(Symbology1DType.Code128, "1234567890", showText: true);
editor.DrawForm(barcodeWithCenterCenterText, 100, 100);
}
private void AddTableRows(Table table)
{
string[][] rows = new[]
{
new[] { "P", "PNo", "Brut", "Net", "Quality", "Pattern", "Pr", "Co", "Ac" },
new[] { "1000", "1001", "119,50", "118,70", "P1", "", "C1", "U1" },
new[] { "1000", "1002", "120,00", "119,40", "P1", "", "C1", "U1" },
new[] { "1000", "1003", "112,80", "112,10", "P1", "", "C1", "U1" },
new[] { "1000", "1004", "120,50", "120,00", "P1", "", "C1", "U1" },
new[] { "1000", "1005", "114,40", "113,50", "P1", "", "C1", "U1" },
new[] { "1000", "1006", "114,40", "113,70", "P1", "", "C1", "U1" },
new[] { "1000", "1007", "104,00", "102,60", "P1", "", "C1", "U1" },
new[] { "1002", "1008", "99,80", "99,40", "P2", "", "C2", "H1" },
new[] { "1002", "1009", "100,40", "100,00", "P2", "", "C2", "H1" },
new[] { "1002", "1010", "100,40", "99,40", "P2", "", "C2", "H1" },
new[] { "1002", "1011", "73,30", "72,50", "P2", "", "C2", "H1" },
new[] { "1002", "1012", "100,00", "99,80", "P2", "", "C2", "H1" },
new[] { "1002", "1013", "74,30", "73,80", "P2", "", "C2", "H1" },
new[] { "1002", "1014", "105,00", "104,30", "P2", "", "C2", "H1" },
};
foreach (var rowValues in rows)
{
var row = table.Rows.AddTableRow();
foreach (var value in rowValues)
{
var cell = row.Cells.AddTableCell();
cell.Blocks.AddBlock().InsertText(value);
}
}
}
}
https://www.telerik.com/document-processing-libraries/pdf-processing
Folks,
For a new project I need to generate a dynamic multi page pdf and one of the mandatory requirements is that some kind of template (html, xml, word) is used for easier maintance purposes.
Is it correct that for the Telerik PDF processing Library the only way to define pdfs is directly in the c# code and not some kind of template?
Thank you
Valentin
PdfProcessing - Developer Focused Examples - Telerik Document Processing
Hi,
we need to generate PDF/UA comform pdfs from scratch. Is that possible with Telerik PdfProcessing? I know that PDF/A works but we need PDF/UA specifically.
Thank you,
Valentin
The contents of an uploaded .docx file is being cut-off when converted to .pdf file.
Code snippet:
var fileFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
using (MemoryStream inputFileStream = new MemoryStream())
{
this.fileSystemService.GetFile(documentInfo, inputFileStream);
if (fileFormatProvider != null)
{
var document = fileFormatProvider.Import(inputFileStream);
using (MemoryStream output = new MemoryStream())
{
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
pdfProvider.Export(document, output);
var newFile = new DocumentInfo()
{
NameWithPath = outputFileName,
DocumentLocation = documentInfo.DocumentLocation
};
this.fileSystemService.SaveFile(newFile, output);
}
}
Can someone confirm if this a Telerik side issue, or am I missing a setting or config?
Thanks!
I am trying to convert HTML to a PDF document with 0.25" margins. The left and right margins are being set correctly, but the top and bottom margins remain 0.5". My code is below, a screenshot of the generated PDF is attached.
StringBuilder sb = new StringBuilder();
foreach (string row in data)
sb.AppendLine(row);
HtmlFormatProvider provider = new HtmlFormatProvider();
RadFlowDocument html = provider.Import(sb.ToString());
foreach (Section section in html.Sections)
{
section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(24, 24, 24, 24);
// Code snippet from function that adds header inserted below
}
PdfFormatProvider pdf = new PdfFormatProvider();
return pdf.Export(html);
Thanks in advance for the help.
Darwin Pinder
Hi,
we have editable PDFs which are stored in a database. We used to be able to pull the PDFs, import them through the Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider to get a RadFixedDocument, iterate through the fields of this document and fill them with data. Afterwards, we exported the PDF through the PdfFormatProvider and wrote them to a file. This gave us the original PDF but filled with the required data.
This does not work anymore, as the resulting exported PDF is visually broken. We have no clue why that happens, maybe you can help us fix this.
I attached a small sample project with our work flow including one of the PDFs we try to fill out and the resulting PDF for you to analyze.
Thanks a lot in advance.