The PDF files can be opened in various viewers and also printed on the corresponding printer.
However, if the file is sent directly from SAP to the print spooler, it cannot be processed.
We have therefore carried out a simple test:
- The data as we process it (attached as files named 'InvoiceFromSihot')
- - this will lead into Screnshot from attached named 'InvoiceFromSihot_Error1' and an additional one 'InvoiceFromSihot_Error2'
--- we convert here a RTF to PDF
- Code: Select all
Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.license_elic));
Spire.License.LicenseProvider.SetLicenseFileStream(stream);
ExportOptions opts = ExportOptions.Parse(exportOptions);
PdfDocument pdf = new PdfDocument(input);
AddMetaData(ref pdf, opts);
if (opts.HasEInvoice)
{
AddDigitalInvoice(ref pdf, opts);
}
MemoryStream pdfStream = new MemoryStream();
pdf.SaveToStream(pdfStream, FileFormat.PDF);
pdf.Dispose();
if (opts.HasEInvoice)
{
var trimmedPdfStream = new MemoryStream(RemoveEOF(pdfStream));
new PdfStandardsConverter(trimmedPdfStream).ToPdfA3A(pdfStream);
return trimmedPdfStream.ToArray();
}
else
{
return RemoveEOF(pdfStream);
}
- Code: Select all
public byte[] RemoveEOF(MemoryStream finalPdfStream)
{
byte[] pdfBytes = finalPdfStream.GetBuffer();
int eofPos = -1;
for (int i = pdfBytes.Length - 1; i >= 0; i--)
{
if (pdfBytes[i] != 0)
{
eofPos = i;
break;
}
}
byte[] adjustedPdf = new byte[eofPos + 1];
Array.Copy(pdfBytes, adjustedPdf, eofPos + 1);
return adjustedPdf;
}
- A very simple PDF with text only created in Spire.PDF (attached as files named 'Spire.PDF')
-- works fine
--- used code for PDF
- Code: Select all
PdfDocument doc = new();
// Meta data
doc.DocumentInformation.Creator = "SIHOT";
doc.DocumentInformation.Title = "SIHOT Test PDF";
// Page settings, reset the default margins to 0
doc.PageSettings.Size = PdfPageSize.A4;
doc.PageSettings.Margins = new(0);
//create a PdfMargins object, the parameters indicate the page margins you want to set
PdfMargins margins = new(60, 0, 0, 60);
// Create a templates with content and apply it to page template
//doc.Template.Top = CreateHeaderTemplate(doc, margins);
//doc.Template.Bottom = CreateFooterTemplate(doc, margins);
// Apply blank templates to other parts of page template
doc.Template.Left = new PdfPageTemplateElement(margins.Left, doc.PageSettings.Size.Height);
doc.Template.Right = new PdfPageTemplateElement(margins.Right, doc.PageSettings.Size.Height);
PdfPageBase page = doc.Pages.Add();
PdfTrueTypeFont fontAssesmentName = new(@"C:\Windows\Fonts\Arial.ttf", 20f);
page.Canvas.DrawString("Test PDF created by Spire.Pdf only", fontAssesmentName, PdfBrushes.Black, 50, page.Size.Height * 0.4f, new PdfStringFormat(PdfTextAlignment.Left));
MemoryStream outstream = new();
doc.SaveToStream(outstream, FileFormat.PDF);
doc.Close();
Does anyone have an idea what we are doing wrong here or what we need to change so that SAP can also process the file directly?