When writing to a FileStream with PdfStreamWriter.WritePage, either implicitly or after the PdfStreamWriter loses scope... A PDF document gets created correctly specifically with the ending portion of the PDF document that handles the %EOF and the portions just prior to that.
When this same process is done with a MemoryStream (not a file) for the purposes of taking that "PDF DOCUMENT" and saving the byte() to a database, that ending part of the PDF document doesn't get created... and thus it becomes a corrupt (unreadable) PDF file. This ending portion of the PDF document that I'm referring to looks like this: (example):
xref
0 26
0000000000 65535 f
0000350400 00000 n
0000350089 00000 n
0000000017 00000 n
0000000204 00000 n
0000000440 00000 n
0000000699 00000 n
0000150134 00000 n
0000150319 00000 n
0000150473 00000 n
0000150732 00000 n
0000232360 00000 n
0000232502 00000 n
0000232814 00000 n
0000232842 00000 n
0000233014 00000 n
0000233544 00000 n
0000233799 00000 n
0000346061 00000 n
0000346138 00000 n
0000346322 00000 n
0000346637 00000 n
0000346892 00000 n
0000350305 00000 n
0000350459 00000 n
0000350528 00000 n
trailer
<</Size 26 /Root 24 0 R /ID [<b3a969414ce82cc43f271ef24e965a21> <b3a969414ce82cc43f271ef24e965a21>] >>
startxref
350975
%%EOF
What do I have to do after .WritePage with a backing MemoryStream... to eventually grab that byte() with a complete PDF document that includes the %%EOF piece... like for example:
Dim
contentLength
As
Int64 = msOutputStream.Length
Dim
aryBuffer(contentLength - 1)
As
Byte
aryBuffer = msOutputStream.ToArray
After the WritePage, the above will NOT include that ending segment of the PDF document/file.
I can't really .Close the MemoryStream, because then it isn't accessible at all... Does it need to be a part of a USING statement in some way? I have the PdfStreamWriter in a USING... and I do NOT need to have the FileStream as part of a USING and it works correctly.
Some full sample code:
Dim
documentsToMerge
As
String
() = {
"d:\SignaturePageToAppend.pdf"
}
Dim
msOutputStream
As
MemoryStream =
New
MemoryStream()
Using memoryWriter
As
Pdf.Streaming.PdfStreamWriter =
New
Pdf.Streaming.PdfStreamWriter(msOutputStream)
Dim
pdfOutputProv
As
Pdf.PdfFormatProvider =
New
Pdf.PdfFormatProvider(msOutputStream)
For
Each
documentName
As
String
In
documentsToMerge
'This is initializing the MemoryStream with a good Byte() PDF from a DB
Dim
msAddedPagePDF
As
MemoryStream =
New
MemoryStream(docAddedPage.FSDocument)
Using fileToMerge
As
Pdf.Streaming.PdfFileSource =
New
Pdf.Streaming.PdfFileSource(msAddedPagePDF)
Dim
pdfAddedPage1
As
Pdf.Streaming.PdfPageSource = fileToMerge.Pages.FirstOrDefault
memoryWriter.WritePage(pdfAddedPage1)
End
Using
'TBD
Dim
contentLength
As
Int64 = msOutputStream.Length
Dim
aryBuffer(contentLength - 1)
As
Byte
aryBuffer = msOutputStream.ToArray
'aryBuffer will NOT include the ending PDF segment to complete the PDF document
'Saving Byte() to DB
'docSource.FSDocument = aryBuffer
'trDocumentRepository.Update(docSource)
'trDocumentRepository.FlushAndSaveChanges()
Next
End
Using
Hi Admin,
With using RadFixedDocument, I tried to import a PDF AcroForm that have signature
then fill data then export to byte array.
But It's always throw exception when use function export
Can you support?
Thank you
Hi admin,
With Telerik reporting (RadPdfProcessing), could we able to do bellow?
1. Load existed an AcroForm as template
2. Auto fill data to this template with data in the database
3. Generate to new non editable PDF file
If can do, please post the guideline
Thank you for supporting
Best regards,
How do you add symbols, specifically "registered" and "copyright" to the pdf export? Id displays in Visual Studio when creating the text, but it doesn't display after the PDF is generated.
Thanks!
Hi all,
Does Telerik RadFlowDocument or RadFlowDocumentEditor support Track Changes & Lock Tracking of Microsoft Office files(.DOCX)?
Is there any alternative for the same?
Dear Concerned,
I am successfully able to merge multiple documents (.DOCX) in to a single document using RadFlowDocument.Merge function.
Now I want to split this document back into multiple documents. please suggest how to proceed?
Hi Team,
I was able to convert a word document to PDF using telerik wordsprocessing (https://demos.telerik.com/aspnet-ajax/wordsprocessing/exporttopdf/defaultvb.aspx?show-source=true),this works excellent for simple word documents and not for documents like certificates or a background image with text on it.
Does Telerik WordsProcessing support conversion of word document such as certificates or any documents with background image and text on top of it?
If not , will this be fixed in next update?
Is there any other control or way to convert word( like certificates) to pdf ?
SAMPLE CERTIFICATE: https://omextemplates.content.office.net/support/templates/en-us/tf03982379.dotx (convert this to docx)
I work for a company that heavily leverages Telerik controls in our core applications. I’ve been tasked with exploring the PDF options available in hopes of replacing our current PDF exports with Telerik equivalents to help move away from an unwanted software license.
In exploring the demos and product features it appears to me that rendering HTML content is limited to the RadClientExportManager and therefore is client side only, while server document creation requires the more elemental building of documents by plotting text, and graphics manually via .NET code.
Is this an accurate assessment? What would you recommend to someone wanting to render HTML content on the server where there is no actual browser or user involvement?
We currently convert data populated WebForm pages into PDF files all on the server that are never delivered to a user via browser interaction, or even requested by a browser (automated generation.)
Aside from an HTML source being easier to use and maintain, it would plug right into our existing situation and not require use to reconstruct our forms in C#. That is obviously a more attractive option for us.
I am very impressed with the functionality of the client side rendering, it just doesn’t appear to cover a lot of common use cases that we happen to fall under.
Hi,
i want to convert HTML to Pdf in c# api in .net Core 2, an you please suggest best way
I want to report bug with this code:
byte[] file = File.ReadAllBytes("Test.pdf");
RadFixedDocument document = null;
var prov = new PdfFormatProvider();
using (var input = new MemoryStream())
{
input.Write(file, 0, file.Length);
document = prov.Import(input);
}
When I tried to import my document to RadFixedDocument it says:
Ex: {"Stack empty."}
Stack trace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Stack`1.Peek()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.PushToken(PdfPrimitive primitive)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PrimitiveParsers.ArrayParser.End()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.<BuildStateMachine>b__8(PostScriptReaderArgs b)
at Telerik.Windows.Documents.Data.StateMachine.State`1.ExecuteActionIfNotNull(Action`1 action, TArgs arguments)
at Telerik.Windows.Documents.Data.StateMachine.State`1.Enter(TArgs arguments)
at Telerik.Windows.Documents.Data.StateMachine.StateMachine`1.GoToState(State`1 state, TArgs arguments)
at Telerik.Windows.Documents.Data.StateMachine.StateMachine`1.GoToNextState(TArgs arguments)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.Read(IPdfImportContext context, Int64 endPosition)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.Read(IPdfImportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.ContentStreamInterpreter.ReadContentPrimitives()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.ContentStreamInterpreter.Execute()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.ContentStream.ParseContentData(Byte[] data, IRadFixedDocumentImportContext context, IResourceHolder resourceHolder, IContentRootElement contentRoot)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.Page.CopyPropertiesTo(PostScriptReader reader, IRadFixedDocumentImportContext context, RadFixedPage fixedPage)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPagePropertiesTo(PostScriptReader reader, IRadFixedDocumentImportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPropertiesTo(PostScriptReader reader, IRadFixedDocumentImportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.RadFixedDocumentImportContext.BeginImportOverride()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.BaseImportContext.BeginImport(Stream pdfFileStream)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.PdfImporter.Import(Stream input, IPdfImportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ImportOverride(Stream input)
at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Import(Stream input
Please fix this issue.