Create a PDF with an area filled with a raster pattern
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Create a PDF with an area filled with a raster pattern
I try created a PDF by copying a vector part from an existing PDF, but the resulting PDF is not valid.
I used your example of reading WMF and changed the contents of the ParseWMF() function.
When there is no raster fill area in the stream, everything is fine.
What features around should I use to achieve a valid PDF?
thank you in advance for your reply and sorry for my english.
I used your example of reading WMF and changed the contents of the ParseWMF() function.
When there is no raster fill area in the stream, everything is fine.
What features around should I use to achieve a valid PDF?
thank you in advance for your reply and sorry for my english.
- Attachments
-
- PDF.ZIP
- source and my pdf
- (4.37 KiB) Downloaded 183 times
Last edited by gabuliatko on Wed Sep 02, 2020 4:42 pm, edited 1 time in total.
Re: Create a PDF with an area filled with a raster pattern
Is this question related to wxWidgets? If yes, how?
Use the source, Luke!
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
this image is correct
this image is wrong
when when I add a record
PDF is correct, but displays nothing
Code: Select all
data += wxS("q 128 0 0 64 2057 5566.67 cm\n");
data += wxS("BI\n");
data += wxS("/IM true\n");
data += wxS("/W 16\n");
data += wxS("/H 8\n");
data += wxS("/BPC 1\n");
data += wxS("ID ");
ID[0]=0xff; ID[1]=0xff; ID[2]=0xcf; ID[3]=0xcf; ID[4]=0xb7; ID[5]=0xb7; ID[6]=0xb7; ID[7]=0xb7; ID[8]=0x7b; ID[9]=0x7b; ID[10]=0x7b; ID[11]=0x7b; ID[12]=0xfc; ID[13]=0xfc; ID[14]=0xff; ID[15]=0xff;
for (unsigned i=0;i<16;i++) { data += ID[i]; }
data += wxS("\n");
data += wxS("EI Q\n");
Code: Select all
data += wxS("q 128 0 0 64 2057 5566.67 cm\n");
data += wxS("BI\n");
data += wxS("/CS/R7\n");
data += wxS("/W 16\n");
data += wxS("/H 8\n");
data += wxS("/BPC 4\n");
data += wxS("/F/Fl\n");
data += wxS("ID ");
ID[0]=0x78; ID[1]=0x9c; ID[2]=0x63; ID[3]=0x60; ID[4]=0x80; ID[5]=0x82; ID[6]=0x55; ID[7]=0x10; ID[8]=0xcc; ID[9]=0xc5; ID[10]=0xb0;
ID[11]=0x00; ID[12]=0x05; ID[13]=0x2f; ID[14]=0x40; ID[15]=0x13; ID[16]=0x41; ID[17]=0xa8; ID[18]=0x84; ID[19]=0x00; ID[20]=0x00; ID[21]=0x04; ID[22]=0x9f; ID[23]=0x07; ID[24]=0xf9;
for (unsigned i=0;i<25;i++) { data += ID[i]; }
data += wxS("\n");
data += wxS("EI Q\n");
Code: Select all
Out("/Group <</Type /Group /S /Transparency /CS /DeviceRGB 15 <000000800000008000808000000080800080008080808080c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff>>>");
Re: Create a PDF with an area filled with a raster pattern
From your attached PDF documents I can see that you used wxPdfDocument. That was not clear from your posting. For future postings you should remember to mention the wxWidgets based components you are using and with which you experience problems.
If possible show the code you use to create your PDF document. And if you intend to present the resulting PDF file here, please use method SetCompression(false) on the wxPdfDocument instance, because that makes it easier for me to analyze the PDF file. Thanks.
Regarding the code snippets in your second posting, I have no idea from which source you got the data, and what you intend to accomplish with it. Again, please describe what you want to acchieve. Thanks.
If you try to inject content into a PDF document without using the methods provided by wxPdfDocument you really need to know what you are doing. Otherwise you are asking for trouble.gabuliatko wrote: ↑Wed Sep 02, 2020 4:18 pm I try created a PDF by copying a vector part from an existing PDF, but the resulting PDF is not valid.
WMF support of wxPdfDocument is limited. Not all features of WMF files are supported, especially raster operations are not supported, only vector operations.gabuliatko wrote: ↑Wed Sep 02, 2020 4:18 pm I used your example of reading WMF and changed the contents of the ParseWMF() function.
When there is no raster fill area in the stream, everything is fine.
First of all, you should describe what you are trying to accomplish. Then I might be able to give advice.gabuliatko wrote: ↑Wed Sep 02, 2020 4:18 pm What features around should I use to achieve a valid PDF?
thank you in advance for your reply and sorry for my english.
If possible show the code you use to create your PDF document. And if you intend to present the resulting PDF file here, please use method SetCompression(false) on the wxPdfDocument instance, because that makes it easier for me to analyze the PDF file. Thanks.
Regarding the code snippets in your second posting, I have no idea from which source you got the data, and what you intend to accomplish with it. Again, please describe what you want to acchieve. Thanks.
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
The goal is to save the EMF to PDF. I used your WMF example and replaced META_ with EMR_. Everything works until I came across areas filled with a raster pattern in EMF.
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
Yes, and raster operations are what I have a problem with. Is there any help from you?
Specifically it is EMR_STRETCHDIBITS from EMF. Result is inline image in PDF.
Re: Create a PDF with an area filled with a raster pattern
As said WMF/EMF raster operations are currently not supported by the WMF parser included in wxPdfDocument.gabuliatko wrote: ↑Thu Sep 03, 2020 6:25 am The goal is to save the EMF to PDF. I used your WMF example and replaced META_ with EMR_. Everything works until I came across areas filled with a raster pattern in EMF.
Well, you are the first one asking for extended WMF/EMF support in almost 15 years. The WMF/EMF specification includes several raster operations, for which it will be difficult if not impossible to support them. However, transferring bitmap images from WMF/EMF to PDF should be doable. This will require to extend the WMF parser in wxPdfDocument accordingly.gabuliatko wrote: ↑Thu Sep 03, 2020 6:25 amYes, and raster operations are what I have a problem with. Is there any help from you?
In principle, I could look into this issue. However, it doesn't have high priority on my to-do list, I have to admit. That is, you may be better off, to convert your EMF file to a format that is directly supported by wxPdfDocument like PNG or JPEG.
Could you provide a sample EMF file for testing purposes?gabuliatko wrote: ↑Thu Sep 03, 2020 6:25 am Specifically it is EMR_STRETCHDIBITS from EMF. Result is inline image in PDF.
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
Thank you.
I have two type areas with raster. EMF atached.
First P2108_200901 have raster type EMR_CREATEDIBPATTERNBRUSHPT, not priority.
Second P0948_200901 have raster type EMR_STRETCHDIBITS
Function 81 Size 160 ipos 20200 4ee8
STRETCHDIBITS.xDest -1216 EMRSTRETCHDIBITS.yDest -5889
EMRSTRETCHDIBITS.xSrc 0 EMRSTRETCHDIBITS.ySrc 0 EMRSTRETCHDIBITS.cxSrc 16 EMRSTRETCHDIBITS.cySrc 8
EMRSTRETCHDIBITS.offBmiSrc 80 EMRSTRETCHDIBITS.cbBmiSrc 48 EMRSTRETCHDIBITS.offBitsSrc 128 EMRSTRETCHDIBITS.cbBitsSrc 32
EMRSTRETCHDIBITS.iUsageSrc 0
EMRSTRETCHDIBITS.dwRop 8913094 8800c6
EMRSTRETCHDIBITS.cxDest 214 EMRSTRETCHDIBITS.cyDest 107
BmiSrc 0x28 0x0 0x0 0x0 0x10 0x0 0x0 0x0 0x8 0x0 0x0 0x0 0x1 0x0 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x2 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xff 0xff 0xff 0x0
BitsSrc 0xff 0xff 0x0 0x0 0xfc 0xfc 0x0 0x0 0x7b 0x7b 0x0 0x0 0x7b 0x7b 0x0 0x0 0xb7 0xb7 0x0 0x0 0xb7 0xb7 0x0 0x0 0xcf 0xcf 0x0 0x0 0xff 0xff 0x0 0x0
Function 81 Size 248 ipos 20360 4f88
EMRSTRETCHDIBITS.xDest -1216 EMRSTRETCHDIBITS.yDest -5889
EMRSTRETCHDIBITS.xSrc 0 EMRSTRETCHDIBITS.ySrc 0 EMRSTRETCHDIBITS.cxSrc 16 EMRSTRETCHDIBITS.cySrc 8
EMRSTRETCHDIBITS.offBmiSrc 80 EMRSTRETCHDIBITS.cbBmiSrc 104 EMRSTRETCHDIBITS.offBitsSrc 184 EMRSTRETCHDIBITS.cbBitsSrc 64
EMRSTRETCHDIBITS.iUsageSrc 0
EMRSTRETCHDIBITS.dwRop 15597702 ee0086
EMRSTRETCHDIBITS.cxDest 214 EMRSTRETCHDIBITS.cyDest 107
BmiScr 0x28 0x0 0x0 0x0 0x10 0x0 0x0 0x0 0x8 0x0 0x0 0x0 0x1 0x0 0x4 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x10 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x80 0x0 0x0 0x80 0x0 0x0 0x0 0x80 0x80 0x0 0x80 0x0 0x0 0x0 0x80 0x0 0x80 0x0 0x80 0x80 0x0 0x0 0x80 0x80 0x80 0x0 0xc0 0xc0 0xc0 0x0 0x0 0x0 0xff 0x0 0x0 0xff 0x0 0x0 0x0 0xff 0xff 0x0 0xff 0x0 0x0 0x0 0xff 0x0 0xff 0x0 0xff 0xff 0x0 0x0 0xff 0xff 0xff 0x0
BitSrc 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xaa 0x0 0x0 0x0 0xaa 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0x0 0xaa 0x0 0x0 0x0 0xaa 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
If you have any advice on where to find instructions on what dwRop, BmiSrc and BitSrc mean and how to convert it to an inline image, I would be grateful.
I have two type areas with raster. EMF atached.
First P2108_200901 have raster type EMR_CREATEDIBPATTERNBRUSHPT, not priority.
Second P0948_200901 have raster type EMR_STRETCHDIBITS
Function 81 Size 160 ipos 20200 4ee8
STRETCHDIBITS.xDest -1216 EMRSTRETCHDIBITS.yDest -5889
EMRSTRETCHDIBITS.xSrc 0 EMRSTRETCHDIBITS.ySrc 0 EMRSTRETCHDIBITS.cxSrc 16 EMRSTRETCHDIBITS.cySrc 8
EMRSTRETCHDIBITS.offBmiSrc 80 EMRSTRETCHDIBITS.cbBmiSrc 48 EMRSTRETCHDIBITS.offBitsSrc 128 EMRSTRETCHDIBITS.cbBitsSrc 32
EMRSTRETCHDIBITS.iUsageSrc 0
EMRSTRETCHDIBITS.dwRop 8913094 8800c6
EMRSTRETCHDIBITS.cxDest 214 EMRSTRETCHDIBITS.cyDest 107
BmiSrc 0x28 0x0 0x0 0x0 0x10 0x0 0x0 0x0 0x8 0x0 0x0 0x0 0x1 0x0 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x2 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xff 0xff 0xff 0x0
BitsSrc 0xff 0xff 0x0 0x0 0xfc 0xfc 0x0 0x0 0x7b 0x7b 0x0 0x0 0x7b 0x7b 0x0 0x0 0xb7 0xb7 0x0 0x0 0xb7 0xb7 0x0 0x0 0xcf 0xcf 0x0 0x0 0xff 0xff 0x0 0x0
Function 81 Size 248 ipos 20360 4f88
EMRSTRETCHDIBITS.xDest -1216 EMRSTRETCHDIBITS.yDest -5889
EMRSTRETCHDIBITS.xSrc 0 EMRSTRETCHDIBITS.ySrc 0 EMRSTRETCHDIBITS.cxSrc 16 EMRSTRETCHDIBITS.cySrc 8
EMRSTRETCHDIBITS.offBmiSrc 80 EMRSTRETCHDIBITS.cbBmiSrc 104 EMRSTRETCHDIBITS.offBitsSrc 184 EMRSTRETCHDIBITS.cbBitsSrc 64
EMRSTRETCHDIBITS.iUsageSrc 0
EMRSTRETCHDIBITS.dwRop 15597702 ee0086
EMRSTRETCHDIBITS.cxDest 214 EMRSTRETCHDIBITS.cyDest 107
BmiScr 0x28 0x0 0x0 0x0 0x10 0x0 0x0 0x0 0x8 0x0 0x0 0x0 0x1 0x0 0x4 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x10 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x80 0x0 0x0 0x80 0x0 0x0 0x0 0x80 0x80 0x0 0x80 0x0 0x0 0x0 0x80 0x0 0x80 0x0 0x80 0x80 0x0 0x0 0x80 0x80 0x80 0x0 0xc0 0xc0 0xc0 0x0 0x0 0x0 0xff 0x0 0x0 0xff 0x0 0x0 0x0 0xff 0xff 0x0 0xff 0x0 0x0 0x0 0xff 0x0 0xff 0x0 0xff 0xff 0x0 0x0 0xff 0xff 0xff 0x0
BitSrc 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xaa 0x0 0x0 0x0 0xaa 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0xa 0x0 0xa0 0x0 0x0 0xaa 0x0 0x0 0x0 0xaa 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
If you have any advice on where to find instructions on what dwRop, BmiSrc and BitSrc mean and how to convert it to an inline image, I would be grateful.
- Attachments
-
- 200628.zip
- (44.91 KiB) Downloaded 178 times
Re: Create a PDF with an area filled with a raster pattern
If your EMF files contain bitmap images anyway, the easiest approach is to convert them to a bitmap format like PNG beforehand. I've done that for your attached files - see attached zip file.
I have to admit that it is long ago that I have read the WMF/EMF specs for implementing the parser included in wxPdfDocument. That is, I will have to recall the details. This may take some time.gabuliatko wrote: ↑Thu Sep 03, 2020 9:31 am First P2108_200901 have raster type EMR_CREATEDIBPATTERNBRUSHPT, not priority.
Second P0948_200901 have raster type EMR_STRETCHDIBITS
[...]
If you have any advice on where to find instructions on what dwRop, BmiSrc and BitSrc mean and how to convert it to an inline image, I would be grateful.
- Attachments
-
- emf2png.zip
- (102.9 KiB) Downloaded 199 times
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
Yes, but these are cutouts of individual areas, and replacement by a raster affects the size of the resulting file.
I will be grateful for any advice on how to implement an inline image into a PDF file.
Re: Create a PDF with an area filled with a raster pattern
I'm not sure whether I really understand what you intend to accomplish. Do you want to embed the (complete) graphics from EMF files in a PDF document? Or do you want to extract parts from an EMF file for embedding them in a PDF document? For the former case it may be possible to enhance the parser to handle EMFs with embedded raster graphics. The latter case would be outside the scope of wxPdfDocument in my opinion.gabuliatko wrote: ↑Thu Sep 03, 2020 10:33 amYes, but these are cutouts of individual areas, and replacement by a raster affects the size of the resulting file.
Could you show an example of what you want to accomplish? That is, what are the source files and how should the result look like?gabuliatko wrote: ↑Thu Sep 03, 2020 10:33 amI will be grateful for any advice on how to implement an inline image into a PDF file.
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
My inline image
BI
/CS/R7
/W 16
/H 8
/BPC 4
/F /AHx
ID 00 00 00 00 00 00 00 00 00 00 00 aa 00 00 00 aa a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 00 aa 00 00 00 aa 00 00 00 00 00 00 00 00 00 00 >
EI Q
The whole problem was shortened to an external colorspace. When using an inline image with BPC 4, /DeviceRGB 15 (I think) must be defined in resources.
I must add
at object /Resources (2 0 R)
row
/ColorSpace 8 0 R
and add 2 objects
7 0 obj
[ /Indexed /DeviceRGB 15 <000000800000008000808000000080800080008080808080c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff> ]
endobj
8 0 obj
<<
/R7 7 0 R
>>
endobj
Is there this option (add two objects) using wxpdfdocument without having to count the number of objects and add them manually?
BI
/CS/R7
/W 16
/H 8
/BPC 4
/F /AHx
ID 00 00 00 00 00 00 00 00 00 00 00 aa 00 00 00 aa a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 00 aa 00 00 00 aa 00 00 00 00 00 00 00 00 00 00 >
EI Q
The whole problem was shortened to an external colorspace. When using an inline image with BPC 4, /DeviceRGB 15 (I think) must be defined in resources.
I must add
at object /Resources (2 0 R)
row
/ColorSpace 8 0 R
and add 2 objects
7 0 obj
[ /Indexed /DeviceRGB 15 <000000800000008000808000000080800080008080808080c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff> ]
endobj
8 0 obj
<<
/R7 7 0 R
>>
endobj
Is there this option (add two objects) using wxpdfdocument without having to count the number of objects and add them manually?
Re: Create a PDF with an area filled with a raster pattern
Instead of describing the goal you want to accomplish on a higher level, you are quoting low level PDF content bytes. The public interface of wxPdfDocument does not offer low level methods which would allow to easily inject arbitrary content bytes and to add arbitrary resource objects.gabuliatko wrote: ↑Sun Sep 06, 2020 4:19 pm My inline image
BI
/CS/R7
/W 16
/H 8
/BPC 4
/F /AHx
ID 00 00 00 00 00 00 00 00 00 00 00 aa 00 00 00 aa a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 0a 00 a0 00 00 aa 00 00 00 aa 00 00 00 00 00 00 00 00 00 00 >
EI Q
Simple answer: no, unless you implement them yourself.gabuliatko wrote: ↑Sun Sep 06, 2020 4:19 pm The whole problem was shortened to an external colorspace. When using an inline image with BPC 4, /DeviceRGB 15 (I think) must be defined in resources.
[...]
Is there this option (add two objects) using wxpdfdocument without having to count the number of objects and add them manually?
If the solution to your problem can't be described in terms of higher level methods of wxPdfDocument, you are of course free to adjust the internal methods of wxPdfDocument to your liking. However, you are then on your own. Low level PDF manipulations as described by you are not in the focus of the wxPdfDocument library. Sorry.
-
- In need of some credit
- Posts: 9
- Joined: Wed Sep 02, 2020 3:57 pm
Re: Create a PDF with an area filled with a raster pattern
I'm sorry, I followed the example of WMF, where the PDF code is written directly. That's why I'm at a low-level level.utelle wrote: ↑Sun Sep 06, 2020 7:40 pm Instead of describing the goal you want to accomplish on a higher level, you are quoting low level PDF content bytes. The public interface of wxPdfDocument does not offer low level methods which would allow to easily inject arbitrary content bytes and to add arbitrary resource objects.
I understand and thank you for the answer.utelle wrote: ↑Sun Sep 06, 2020 7:40 pm If the solution to your problem can't be described in terms of higher level methods of wxPdfDocument, you are of course free to adjust the internal methods of wxPdfDocument to your liking. However, you are then on your own. Low level PDF manipulations as described by you are not in the focus of the wxPdfDocument library. Sorry.
Re: Create a PDF with an area filled with a raster pattern
Well, wxPdfDocument supports to add WMF graphics as image objects to a PDF document. This is the high level goal. The PDF specification does not include direct support for WMF graphics. Therefore, wxPdfDocument parses internally the WMF file and transforms its GDI commands into PDF drawing operations, to accomplish the goal of supporting the WMF graphics format (at least to a certain degree).gabuliatko wrote: ↑Sun Sep 06, 2020 7:58 pm I'm sorry, I followed the example of WMF, where the PDF code is written directly. That's why I'm at a low-level level.
To be able to support not only WMF, but also EMF graphics files, it would be probably necessary to apply certain modifications to the WMF parser code. If your question would be to enhance wxPdfDocument in this sense that using EMF files as sources for images in a PDF document would be possible, that could be discussed.
However, you only talked about adding partial extracts from EMF files to a PDF document. This goal seems to be very specific to your current application and does not seem to impose a generic use case beneficial to a wider audience.