Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ page 6111 "Inbound E-Doc. Picture"
PdfStream, ImageStream : InStream;
EDocDataStorageImageDescriptionLbl: Label 'Pdf Preview';
begin
Clear(TempMediaRepository);
if Rec."Entry No." <> xRec."Entry No." then
PdfLoaded := false;

Expand All @@ -55,8 +56,8 @@ page 6111 "Inbound E-Doc. Picture"
Rec."Data Storage".CreateInStream(PdfStream, TextEncoding::UTF8);
if PdfDocument.Load(PdfStream) then begin
TempBlob.CreateInStream(ImageStream, TextEncoding::UTF8);
PdfDocument.ConvertToImage(ImageStream, "Image Format"::Png, 1);
TempMediaRepository.Image.ImportStream(ImageStream, EDocDataStorageImageDescriptionLbl, 'image/png');
if PdfDocument.ConvertPdfToImage(ImageStream, "Image Format"::Png, 1) then
TempMediaRepository.Image.ImportStream(ImageStream, EDocDataStorageImageDescriptionLbl, 'image/png');
end;
end;

Expand Down
2 changes: 1 addition & 1 deletion src/System Application/App/Pdf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ procedure Example(ImageStream: InStream)
var
PDFDocument: Codeunit "PDF Document";
begin
PDFDocument.ConvertToImage(ImageStream, Enum::"Image Format"::PNG, 1);
PDFDocument.ConvertPdfToImage(ImageStream, Enum::"Image Format"::PNG, 1);
end;
```

Expand Down
18 changes: 17 additions & 1 deletion src/System Application/App/Pdf/src/PDFDocument.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,27 @@ codeunit 3110 "PDF Document"
/// <param name="ImageStream">Stream of the image file.</param>
/// <param name="ImageFormat">Image format to convert the PDF to.</param>
/// <param name="PageNumber">Page number to convert.</param>
/// <returns>Whether or not the conversion was successful.</returns>
procedure ConvertPdfToImage(var ImageStream: InStream; ImageFormat: Enum "Image Format"; PageNumber: Integer): Boolean
begin
exit(PDFDocumentImpl.ConvertToImage(ImageStream, ImageFormat, PageNumber));
end;

#if not CLEAN27
#pragma warning disable AS0072 // this will be backported: #610559
/// <summary>
/// This procedure is used to convert a PDF file to an image.
/// </summary>
/// <param name="ImageStream">Stream of the image file.</param>
/// <param name="ImageFormat">Image format to convert the PDF to.</param>
/// <param name="PageNumber">Page number to convert.</param>
[Obsolete('Use the ConvertPdfToImage procedure instead.', '27.1')]
procedure ConvertToImage(var ImageStream: InStream; ImageFormat: Enum "Image Format"; PageNumber: Integer)
begin
PDFDocumentImpl.ConvertToImage(ImageStream, ImageFormat, PageNumber);
end;

#pragma warning restore AS0072
#endif
/// <summary>
/// This procedure is used to get the invoice attachment stream from a PDF file.
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions src/System Application/App/Pdf/src/PDFDocumentImpl.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ codeunit 3109 "PDF Document Impl."

procedure ConvertToImage(var ImageStream: InStream; ImageFormat: Enum "Image Format"; PageNumber: Integer): Boolean
var
PdfConverterInstance: DotNet PdfConverter;
PdfTargetDevice: DotNet PdfTargetDevice;
MemoryStream: DotNet MemoryStream;
ImageMemoryStream: DotNet MemoryStream;
Expand All @@ -72,14 +71,24 @@ codeunit 3109 "PDF Document Impl."
CopyStream(MemoryStream, SharedDocumentStream);

ConvertImageFormatToPdfTargetDevice(ImageFormat, PdfTargetDevice);
ImageMemoryStream := PdfConverterInstance.ConvertPage(PdfTargetDevice, MemoryStream, PageNumber, 0, 0, 0); // apply default height, width and resolution
if not TryToConvertPage(PdfTargetDevice, MemoryStream, PageNumber, ImageMemoryStream) then
exit(false);

// Copy data to the outgoing stream and make sure it is reset to the beginning of the stream.
ImageMemoryStream.Seek(0, 0);
ImageMemoryStream.CopyTo(ImageStream);
ImageStream.Position(1);
exit(true)
end;

[TryFunction]
local procedure TryToConvertPage(var PdfTargetDevice: DotNet PdfTargetDevice; var MemoryStream: DotNet MemoryStream; PageNumber: Integer; var ImageMemoryStream: DotNet MemoryStream)
var
PdfConverterInstance: DotNet PdfConverter;
begin
ImageMemoryStream := PdfConverterInstance.ConvertPage(PdfTargetDevice, MemoryStream, PageNumber, 0, 0, 0); // apply default height, width and resolution
end;

local procedure ConvertImageFormatToPdfTargetDevice(ImageFormat: Enum "Image Format"; var PdfTargetDevice: DotNet PdfTargetDevice)
begin
case ImageFormat of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ codeunit 132601 "PDF Document Test"
NavApp.GetResource('test.pdf', PdfInstream, TextEncoding::UTF8);
TempBlob.CreateInStream(ImageStream);
PdfDocument.Load(PdfInstream);
PdfDocument.ConvertToImage(ImageStream, ImageFormat::Png, 1);
PdfDocument.ConvertPdfToImage(ImageStream, ImageFormat::Png, 1);
Assert.AreNotEqual(0, TempBlob.Length(), LengthErr);
end;

Expand Down
Loading