Forum > General

[Solved] How to unpack a stream from a pdf object?


i would like to unpack a stream in a pdf object (a part of a pdf file).
Please find attached a sample project and a sample invoice. (This sample project only compiles with trunk!)

This object (Doc.Objects[27]) should contain some xml data.

This xml data is used for Zugferd (Germany) and faktur-x (France) invoices.


With no error checking and assuming your stream is object 27 AND /FlateDecode ...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ZStream; procedure Decompress(ASrcStream, ADestStream: TStream);var  decompressor: TDecompressionStream;begin  decompressor := TDecompressionStream.Create(ASrcStream, false);  try    ADestStream.CopyFrom(decompressor, 0);  // 0 --> entire src stream  finally    decompressor.Free;  end;end; var  S: ansistring;  instream: TMemoryStream;  outstream: TStringStream; //...   instream := TMemoryStream.Create;  outstream := TStringStream.Create;  try    instream.WriteBuffer(TPdfIndirect(Doc.Objects[27]).Stream.Data,Length(TPdfIndirect(Doc.Objects[27]).Stream.Data));    instream.Position := 0;    Decompress(instream, outstream);    S := outstream.DataString;  finally;;  end;   Memo1.Append(S);
This will give you:

--- Quote ---<?xml version='1.0' encoding='UTF-8' ?>
<!-- English disclaimer below.-->
ZUGFeRD Datenformat Version 2.2.0, 14.02.2022
Beispiel Version 14.02.2022
Zweck des Forums elektronisch Rechnung Deutschland, welches am 31. März 2010 unter der Arbeitsgemeinschaft für
<snip> rest of XML
--- End quote ---

This is exactly what I was looking for.
Thank you.


[0] Message Index

Go to full version